public void unsetCondition(Object key) { this.checkFlattened(); for (Iterator<Condition> iter = this.conditions.iterator(); iter.hasNext();) { Condition c = iter.next(); assert c.isRelation(); if (((Condition.Relation) c).key().equals(key)) { iter.remove(); } } }
public List<Condition> syspropConditions(HugeKeys key) { this.checkFlattened(); List<Condition> conditions = new ArrayList<>(); for (Condition condition : this.conditions) { Relation relation = (Relation) condition; if (relation.key().equals(key)) { conditions.add(relation); } } return conditions; }
public List<Condition> userpropConditions(Id key) { this.checkFlattened(); List<Condition> conditions = new ArrayList<>(); for (Condition condition : this.conditions) { Relation relation = (Relation) condition; if (relation.key().equals(key)) { conditions.add(relation); } } return conditions; }
if (relation.key().equals(key)) { rs.add(relation);
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 { "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, * 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); }
@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 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 writeQueryEdgeCondition(Query query) { ConditionQuery result = (ConditionQuery) query; for (Condition.Relation r : result.relations()) { Object value = r.value(); if (value instanceof Id) { if (r.key() == HugeKeys.OWNER_VERTEX || r.key() == HugeKeys.OTHER_VERTEX) { // Serialize vertex id r.serialValue(IdUtil.writeString((Id) value)); } else { // Serialize label id r.serialValue(((Id) value).asObject()); } } else if (value instanceof Directions) { r.serialValue(((Directions) value).code()); } } return null; }
private static Condition convNotin2And(Relation relation) { assert relation.relation() == Condition.RelationType.NOT_IN; Object key = relation.key(); @SuppressWarnings("unchecked") List<Object> values = (List<Object>) relation.value(); Condition cond; Condition conds = null; for (Object value : values) { if (key instanceof HugeKeys) { cond = Condition.neq((HugeKeys) key, value); } else { cond = Condition.neq((Id) key, value); } conds = conds == null ? cond : Condition.and(conds, cond); } return conds; }
public Object condition(Object key) { this.checkFlattened(); List<Object> values = new ArrayList<>(); for (Condition c : this.conditions) { if (c.isRelation()) { Condition.Relation r = (Condition.Relation) c; if (r.key().equals(key) && r.relation() == RelationType.EQ) { values.add(r.value()); } } } if (values.isEmpty()) { return null; } E.checkState(values.size() == 1, "Illegal key '%s' with more than one value", key); return values.get(0); }
private static Condition convIn2Or(Relation relation) { assert relation.relation() == Condition.RelationType.IN; Object key = relation.key(); @SuppressWarnings("unchecked") List<Object> values = (List<Object>) relation.value(); Condition cond, conds = null; for (Object value : values) { if (key instanceof HugeKeys) { cond = Condition.eq((HugeKeys) key, value); } else { cond = Condition.eq((Id) key, value); } conds = conds == null ? cond : Condition.or(conds, cond); } return conds; }
public ConditionQuery query(Condition condition) { // Query by id (HugeGraph-259) if (condition instanceof Relation) { Relation relation = (Relation) condition; if (relation.key().equals(HugeKeys.ID) && relation.relation() == RelationType.EQ) { E.checkArgument(relation.value() instanceof Id, "Invalid id value '%s'", relation.value()); super.query((Id) relation.value()); return this; } } this.conditions.add(condition); return this; }
public Object serialKey() { return this.serialKey != null ? this.serialKey : this.key(); }
public Set<Object> userpropValues(Id field) { Set<Object> values = new HashSet<>(); for (Relation r : this.userpropRelations()) { if (r.key().equals(field)) { values.add(r.serialValue()); } } return values; }
public boolean containsCondition(HugeKeys key, Condition.RelationType type) { for (Relation r : this.relations()) { if (r.key().equals(key) && r.relation().equals(type)) { return true; } } return false; }
@Override public String toString() { return String.format("%s %s %s", this.key(), this.relation.string(), this.value); }
private static Condition convTextContainsAny2Or(Relation relation) { assert relation.relation() == Condition.RelationType.TEXT_CONTAINS_ANY; @SuppressWarnings("unchecked") Collection<String> words = (Collection<String>) relation.value(); Condition cond, conds = null; for (String word : words) { assert relation.key() instanceof Id; cond = Condition.textContains((Id) relation.key(), word); conds = conds == null ? cond : Condition.or(conds, cond); } return conds; }
@Override public int hashCode() { return this.type().hashCode() ^ this.relation().hashCode() ^ this.key().hashCode() ^ this.value().hashCode(); }