Search in sources :

Example 11 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.

the class TraversalUtil method convIn2Relation.

public static Condition convIn2Relation(HugeGraph graph, HugeType type, HasContainer has) {
    BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
    assert bp instanceof Contains;
    Collection<?> values = (Collection<?>) has.getValue();
    String originKey = has.getKey();
    if (values.size() > 1) {
        E.checkArgument(!originKey.equals(T.key.getAccessor()) && !originKey.equals(T.value.getAccessor()), "Not support hasKey() or hasValue() with " + "multiple values");
    }
    HugeKeys hugeKey = token2HugeKey(originKey);
    List<?> valueList;
    if (hugeKey != null) {
        valueList = convSysListValueIfNeeded(graph, type, hugeKey, values);
        switch((Contains) bp) {
            case within:
                return Condition.in(hugeKey, valueList);
            case without:
                return Condition.nin(hugeKey, valueList);
            default:
                throw newUnsupportedPredicate(has.getPredicate());
        }
    } else {
        valueList = new ArrayList<>(values);
        String key = has.getKey();
        PropertyKey pkey = graph.propertyKey(key);
        switch((Contains) bp) {
            case within:
                return Condition.in(pkey.id(), valueList);
            case without:
                return Condition.nin(pkey.id(), valueList);
            default:
                throw newUnsupportedPredicate(has.getPredicate());
        }
    }
}
Also used : Contains(org.apache.tinkerpop.gremlin.process.traversal.Contains) Collection(java.util.Collection) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 12 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.

the class GraphTransaction method verifyEdgesConditionQuery.

private static void verifyEdgesConditionQuery(ConditionQuery query) {
    assert query.resultType().isEdge();
    int total = query.conditionsSize();
    if (total == 1) {
        /*
             * Supported query:
             *  1.query just by edge label
             *  2.query just by PROPERTIES (like containsKey,containsValue)
             *  3.query with scan
             */
        if (query.containsCondition(HugeKeys.LABEL) || query.containsCondition(HugeKeys.PROPERTIES) || query.containsScanRelation()) {
            return;
        }
    }
    int matched = 0;
    for (HugeKeys key : EdgeId.KEYS) {
        Object value = query.condition(key);
        if (value == null) {
            break;
        }
        matched++;
    }
    int count = matched;
    if (query.containsCondition(HugeKeys.PROPERTIES)) {
        matched++;
        if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
            matched++;
        }
    }
    if (matched != total) {
        throw new HugeException("Not supported querying edges by %s, expect %s", query.conditions(), EdgeId.KEYS[count]);
    }
}
Also used : HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) HugeException(com.baidu.hugegraph.HugeException)

Example 13 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.

the class GraphSONSchemaSerializer method writeIndexLabel.

public Map<HugeKeys, Object> writeIndexLabel(IndexLabel indexLabel) {
    HugeGraph graph = indexLabel.graph();
    assert graph != null;
    Map<HugeKeys, Object> map = new LinkedHashMap<>();
    map.put(HugeKeys.ID, indexLabel.id().asLong());
    map.put(HugeKeys.NAME, indexLabel.name());
    map.put(HugeKeys.BASE_TYPE, indexLabel.baseType());
    if (indexLabel.baseType() == HugeType.VERTEX_LABEL) {
        map.put(HugeKeys.BASE_VALUE, graph.vertexLabel(indexLabel.baseValue()).name());
    } else {
        assert indexLabel.baseType() == HugeType.EDGE_LABEL;
        map.put(HugeKeys.BASE_VALUE, graph.edgeLabel(indexLabel.baseValue()).name());
    }
    map.put(HugeKeys.INDEX_TYPE, indexLabel.indexType());
    map.put(HugeKeys.FIELDS, graph.mapPkId2Name(indexLabel.indexFields()));
    map.put(HugeKeys.STATUS, indexLabel.status());
    map.put(HugeKeys.USER_DATA, indexLabel.userdata());
    return map;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.

the class HugeGryoModule method readEntry.

@SuppressWarnings("unused")
private static Map<HugeKeys, Object> readEntry(Kryo kryo, Input input) {
    int columnSize = input.readInt();
    Map<HugeKeys, Object> map = new LinkedHashMap<>();
    for (int i = 0; i < columnSize; i++) {
        HugeKeys key = kryo.readObject(input, HugeKeys.class);
        Object val = kryo.readClassAndObject(input);
        map.put(key, val);
    }
    return map;
}
Also used : HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.

the class CassandraTable method row2Entry.

protected static CassandraBackendEntry row2Entry(HugeType type, Row row) {
    CassandraBackendEntry entry = new CassandraBackendEntry(type);
    List<Definition> cols = row.getColumnDefinitions().asList();
    for (Definition col : cols) {
        String name = col.getName();
        HugeKeys key = CassandraTable.parseKey(name);
        Object value = row.getObject(name);
        if (value == null) {
            assert key == HugeKeys.EXPIRED_TIME;
            continue;
        }
        entry.column(key, value);
    }
    return entry;
}
Also used : Definition(com.datastax.driver.core.ColumnDefinitions.Definition) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Aggregations

HugeKeys (com.baidu.hugegraph.type.define.HugeKeys)32 ArrayList (java.util.ArrayList)9 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 HugeGraph (com.baidu.hugegraph.HugeGraph)4 Id (com.baidu.hugegraph.backend.id.Id)4 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 BackendException (com.baidu.hugegraph.backend.BackendException)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 SQLException (java.sql.SQLException)3 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)2 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)2 NotFoundException (com.baidu.hugegraph.exception.NotFoundException)2 Select (com.datastax.driver.core.querybuilder.Select)2 Update (com.datastax.driver.core.querybuilder.Update)2 HugeException (com.baidu.hugegraph.HugeException)1 Aggregate (com.baidu.hugegraph.backend.query.Aggregate)1 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)1