assert condition instanceof Condition.Relation; Condition.Relation r = (Condition.Relation) condition; Number value = NumericUtil.convertToNumber(r.value()); Condition.Relation sys = new Condition.SyspropRelation( HugeKeys.FIELD_VALUES, r.relation(), value); condition = condition.replace(r, sys); indexQuery.query(condition);
protected Clause relation2Cql(Relation relation) { String key = relation.serialKey().toString(); Object value = relation.serialValue(); switch (relation.relation()) { case EQ: return QueryBuilder.eq(key, value);
/** * This method is only used for secondary index scenario, * its relation must be EQ * @param fields the user property fields * @return the corresponding user property serial values of fields */ public String userpropValuesString(List<Id> fields) { List<Object> values = new ArrayList<>(fields.size()); for (Id field : fields) { boolean got = false; for (Relation r : this.userpropRelations()) { if (r.key().equals(field) && !r.isSysprop()) { E.checkState(r.relation == RelationType.EQ, "Method userpropValues(List<String>) only " + "used for secondary index, " + "relation must be EQ, but got %s", r.relation()); values.add(r.serialValue()); got = true; } } if (!got) { throw new BackendException( "No such userprop named '%s' in the query '%s'", field, this); } } return SplicingIdGenerator.concatValues(values); }
Id indexLabelId = null; for (Condition.Relation r : ((ConditionQuery) query).relations()) { if (r.key().equals(HugeKeys.INDEX_LABEL_ID)) { indexLabelId = (Id) r.value(); continue; E.checkArgument(r.key() == HugeKeys.FIELD_VALUES, "Expect FIELD_VALUES in AND condition"); switch (r.relation()) { case EQ: keyEq = r.value(); break; case GTE: keyMinEq = true; case GT: keyMin = r.value(); break; case LTE: keyMaxEq = true; case LT: keyMax = r.value(); break; default: E.checkArgument(false, "Unsupported relation '%s'", r.relation()); break;
protected Clause relation2Cql(Relation relation) { String key = relation.serialKey().toString(); Object value = relation.serialValue(); switch (relation.relation()) { case EQ: return QueryBuilder.eq(key, value);
Object key = cond.isRelation() ? ((Relation) cond).key() : null; if (key instanceof Id && indexFields.contains(key)) {
protected StringBuilder relation2Sql(Condition.Relation relation) { String key = relation.serialKey().toString(); Object value = relation.serialValue(); switch (relation.relation()) { case EQ: sql.append(" = ").append(value);
Condition cond = conditions.iterator().next(); E.checkState(cond.isRelation() && ((Condition.Relation) cond).key().equals(HugeKeys.LABEL), "Not support querying edge by %s", conditions); Condition.Relation relation = (Condition.Relation) cond; String label = (String) relation.serialValue();
if (relation.key().equals(key)) { rs.add(relation);
private static Condition flattenIn(Condition condition) { switch (condition.type()) { case RELATION: Relation relation = (Relation) condition; switch (relation.relation()) { case IN: // Flatten IN if needed return convIn2Or(relation); case NOT_IN: // Flatten NOT_IN if needed return convNotin2And(relation); case TEXT_CONTAINS_ANY: // Flatten TEXT_CONTAINS_ANY if needed return convTextContainsAny2Or(relation); default: return condition; } case AND: Condition.And and = (Condition.And) condition; return new Condition.And(flattenIn(and.left()), flattenIn(and.right())); case OR: Condition.Or or = (Condition.Or) condition; return new Condition.Or(flattenIn(or.left()), flattenIn(or.right())); default: throw new AssertionError(String.format( "Wrong condition type: '%s'", condition.type())); } }
assert c instanceof Condition.Relation; Condition.Relation r = (Condition.Relation) c; if (r.key() == HugeKeys.FIELD_VALUES) { fieldValue = r.value().toString(); } else if (r.key() == HugeKeys.INDEX_LABEL_ID) { indexLabelId = r.value().toString(); } else { E.checkState(false, "Secondary index query conditions must be" + "FIELD_VALUES or INDEX_LABEL_ID, but got: %s", r.key());
/** * This method is only used for secondary index scenario, * relation must be EQ * @param fields the user property fields * @return the corresponding user property values of fileds */ public List<Object> userpropValues(List<Id> fields) { List<Object> values = new ArrayList<>(fields.size()); for (Id field : fields) { boolean got = false; for (Relation r : this.userpropRelations()) { if (r.key().equals(field) && !r.isSysprop()) { E.checkState(r.relation == RelationType.EQ, "Method userpropValues(List<String>) only " + "used for secondary index, " + "relation must be EQ, but got '%s'", r.relation()); values.add(r.value()); got = true; } } if (!got) { throw new BackendException( "No such userprop named '%s' in the query '%s'", field, this); } } return values; }
private static Set<IndexLabel> matchRangeOrSearchIndexLabels( ConditionQuery query, Set<IndexLabel> indexLabels) { Set<IndexLabel> matchedIndexLabels = InsertionOrderUtil.newSet(); for (Condition.Relation relation : query.userpropRelations()) { if (!relation.relation().isRangeType() && !relation.relation().isSearchType()) { continue; } Id key = (Id) relation.key(); boolean matched = false; for (IndexLabel indexLabel : indexLabels) { if (indexLabel.indexType() == IndexType.RANGE || indexLabel.indexType() == IndexType.SEARCH) { if (indexLabel.indexField().equals(key)) { matched = true; matchedIndexLabels.add(indexLabel); break; } } } if (!matched) { return ImmutableSet.of(); } } return matchedIndexLabels; }
@Override protected Query writeQueryCondition(Query query) { ConditionQuery result = (ConditionQuery) query; // No user-prop when serialize assert result.allSysprop(); for (Condition.Relation r : result.relations()) { // Serialize key if (query.resultType().isSchema()) { r.serialKey(((HugeKeys) r.key()).string()); } else { r.serialKey(formatSyspropName((HugeKeys) r.key())); } if (r.value() instanceof Id) { // Serialize id value r.serialValue(writeId((Id) r.value())); } else { // Serialize other type value r.serialValue(JsonUtil.toJson(r.value())); } if (r.relation() == Condition.RelationType.CONTAINS_KEY) { // Serialize has-key String key = (String) r.serialValue(); r.serialValue(formatPropertyName(key)); } } return result; }
private static boolean matchCondition(BackendEntry item, Condition c) { // TODO: Compatible with BackendEntry TextBackendEntry entry = (TextBackendEntry) item; // Not supported by memory if (!(c instanceof Condition.Relation)) { throw new BackendException("Unsupported condition: " + c); } Condition.Relation r = (Condition.Relation) c; String key = r.serialKey().toString(); // TODO: deal with others Relation like: <, >=, ... if (r.relation() == Condition.RelationType.CONTAINS_KEY) { return entry.contains(r.serialValue().toString()); } else if (r.relation() == Condition.RelationType.CONTAINS) { return entry.containsValue(r.serialValue().toString()); } else if (r.relation() == Condition.RelationType.EQ) { return entry.contains(key, r.serialValue().toString()); } else if (entry.contains(key)) { return r.test(entry.column(key)); } return false; } }