Search in sources :

Example 16 with HugeKeys

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

the class CassandraTable method buildDelete.

protected Delete buildDelete(CassandraBackendEntry.Row entry) {
    List<HugeKeys> idNames = this.idColumnName();
    Delete delete = QueryBuilder.delete().from(this.table());
    if (entry.columns().isEmpty()) {
        // Delete just by id
        List<Long> idValues = this.idColumnValue(entry);
        assert idNames.size() == idValues.size();
        for (int i = 0, n = idNames.size(); i < n; i++) {
            delete.where(formatEQ(idNames.get(i), idValues.get(i)));
        }
    } else {
        // Delete just by column keys(must be id columns)
        for (HugeKeys idName : idNames) {
            // TODO: should support other filters (like containsKey)
            delete.where(formatEQ(idName, entry.column(idName)));
        }
    /*
             * TODO: delete by id + keys(like index element-ids -- it seems
             * has been replaced by eliminate() method)
             */
    }
    return delete;
}
Also used : Delete(com.datastax.driver.core.querybuilder.Delete) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 17 with HugeKeys

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

the class CassandraTable method buildAppend.

protected Update buildAppend(CassandraBackendEntry.Row entry) {
    List<HugeKeys> idNames = this.idColumnName();
    List<HugeKeys> colNames = this.modifiableColumnName();
    Map<HugeKeys, Object> columns = entry.columns();
    Update update = QueryBuilder.update(table());
    for (HugeKeys key : colNames) {
        if (!columns.containsKey(key)) {
            continue;
        }
        String name = formatKey(key);
        Object value = columns.get(key);
        if (value instanceof Map) {
            update.with(QueryBuilder.putAll(name, (Map<?, ?>) value));
        } else if (value instanceof List) {
            update.with(QueryBuilder.appendAll(name, (List<?>) value));
        } else {
            update.with(QueryBuilder.append(name, value));
        }
    }
    for (HugeKeys idName : idNames) {
        assert columns.containsKey(idName);
        update.where(formatEQ(idName, columns.get(idName)));
    }
    return update;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) Update(com.datastax.driver.core.querybuilder.Update) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 18 with HugeKeys

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

the class CassandraTable method createTable.

protected void createTable(CassandraSessionPool.Session session, ImmutableMap<HugeKeys, DataType> partitionKeys, ImmutableMap<HugeKeys, DataType> clusteringKeys, ImmutableMap<HugeKeys, DataType> columns) {
    Create table = SchemaBuilder.createTable(this.table()).ifNotExists();
    for (Map.Entry<HugeKeys, DataType> entry : partitionKeys.entrySet()) {
        table.addPartitionKey(formatKey(entry.getKey()), entry.getValue());
    }
    for (Map.Entry<HugeKeys, DataType> entry : clusteringKeys.entrySet()) {
        table.addClusteringColumn(formatKey(entry.getKey()), entry.getValue());
    }
    for (Map.Entry<HugeKeys, DataType> entry : columns.entrySet()) {
        table.addColumn(formatKey(entry.getKey()), entry.getValue());
    }
    LOG.debug("Create table: {}", table);
    session.execute(table);
}
Also used : Create(com.datastax.driver.core.schemabuilder.Create) DataType(com.datastax.driver.core.DataType) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 19 with HugeKeys

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

the class TextSerializer method writeQueryCondition.

@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;
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Example 20 with HugeKeys

use of com.baidu.hugegraph.type.define.HugeKeys 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

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