Search in sources :

Example 11 with Relation

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;
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) Id(com.baidu.hugegraph.backend.id.Id)

Example 12 with Relation

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);
    }
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) Clause(com.datastax.driver.core.querybuilder.Clause) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 13 with Relation

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;
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) ArrayList(java.util.ArrayList)

Example 14 with Relation

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;
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) ArrayList(java.util.ArrayList)

Example 15 with Relation

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;
}
Also used : Relation(com.baidu.hugegraph.backend.query.Condition.Relation) HashMap(java.util.HashMap) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Aggregations

Relation (com.baidu.hugegraph.backend.query.Condition.Relation)18 SyspropRelation (com.baidu.hugegraph.backend.query.Condition.SyspropRelation)7 Id (com.baidu.hugegraph.backend.id.Id)5 Condition (com.baidu.hugegraph.backend.query.Condition)5 ArrayList (java.util.ArrayList)4 BackendException (com.baidu.hugegraph.backend.BackendException)3 Shard (com.baidu.hugegraph.backend.store.Shard)3 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)3 HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)2 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 Clause (com.datastax.driver.core.querybuilder.Clause)2 Date (java.util.Date)2 Test (org.junit.Test)2 PageState (com.baidu.hugegraph.backend.page.PageState)1 Aggregate (com.baidu.hugegraph.backend.query.Aggregate)1 Query (com.baidu.hugegraph.backend.query.Query)1 Order (com.baidu.hugegraph.backend.query.Query.Order)1 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)1 BackendTable (com.baidu.hugegraph.backend.store.BackendTable)1 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)1