use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class GraphIndexTransaction method matchRangeOrSearchIndexLabels.
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().isRange() || indexLabel.indexType().isSearch()) {
if (indexLabel.indexField().equals(key)) {
matched = true;
matchedIndexLabels.add(indexLabel);
break;
}
}
}
if (!matched) {
return ImmutableSet.of();
}
}
return matchedIndexLabels;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class CassandraTable method condition2Cql.
protected Clause condition2Cql(Condition condition) {
switch(condition.type()) {
case AND:
Condition.And and = (Condition.And) condition;
Clause left = condition2Cql(and.left());
Clause right = condition2Cql(and.right());
return Clauses.and(left, right);
case OR:
throw new BackendException("Not support OR currently");
case RELATION:
Condition.Relation r = (Condition.Relation) condition;
return relation2Cql(r);
default:
final String msg = "Unsupported condition: " + condition;
throw new AssertionError(msg);
}
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method userpropConditions.
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;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method syspropConditions.
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;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQuery method mayHasDupKeys.
public boolean mayHasDupKeys(Set<HugeKeys> keys) {
Map<HugeKeys, Integer> keyCounts = new HashMap<>();
for (Condition condition : this.conditions) {
if (!condition.isRelation()) {
// Assume may exist duplicate keys when has nested conditions
return true;
}
Relation relation = (Relation) condition;
if (keys.contains(relation.key())) {
int keyCount = keyCounts.getOrDefault(relation.key(), 0);
if (++keyCount > 1) {
return true;
}
keyCounts.put((HugeKeys) relation.key(), keyCount);
}
}
return false;
}
Aggregations