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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations