use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.
the class MysqlTable method queryId2Select.
protected List<StringBuilder> queryId2Select(Query query, StringBuilder select) {
// Query by id(s)
if (query.idsSize() == 0) {
return ImmutableList.of(select);
}
List<HugeKeys> nameParts = this.idColumnName();
List<List<Object>> ids = new ArrayList<>(query.idsSize());
for (Id id : query.ids()) {
List<Object> idParts = this.idColumnValue(id);
if (nameParts.size() != idParts.size()) {
throw new NotFoundException("Unsupported ID format: '%s' (should contain %s)", id, nameParts);
}
ids.add(idParts);
}
// Query only by partition-key
if (nameParts.size() == 1) {
List<Object> values = new ArrayList<>(ids.size());
for (List<Object> objects : ids) {
assert objects.size() == 1;
values.add(objects.get(0));
}
WhereBuilder where = this.newWhereBuilder();
where.in(formatKey(nameParts.get(0)), values);
select.append(where.build());
return ImmutableList.of(select);
}
/*
* Query by partition-key + clustering-key
* NOTE: Error if multi-column IN clause include partition key:
* error: multi-column relations can only be applied to clustering
* columns when using: select.where(QueryBuilder.in(names, idList));
* So we use multi-query instead of IN
*/
List<StringBuilder> selections = new ArrayList<>(ids.size());
for (List<Object> objects : ids) {
assert nameParts.size() == objects.size();
StringBuilder idSelection = new StringBuilder(select);
/*
* NOTE: concat with AND relation, like:
* "pk = id and ck1 = v1 and ck2 = v2"
*/
WhereBuilder where = this.newWhereBuilder();
where.and(formatKeys(nameParts), objects);
idSelection.append(where.build());
selections.add(idSelection);
}
return selections;
}
use of com.baidu.hugegraph.type.define.HugeKeys in project incubator-hugegraph by apache.
the class MysqlTable method buildInsertTemplateForce.
protected String buildInsertTemplateForce(MysqlBackendEntry.Row entry) {
StringBuilder insert = new StringBuilder();
insert.append("REPLACE INTO ").append(this.table()).append(" (");
int i = 0;
int n = entry.columns().size();
for (HugeKeys key : entry.columns().keySet()) {
insert.append(formatKey(key));
if (++i != n) {
insert.append(", ");
}
}
insert.append(") VALUES (");
// Fill with '?'
for (i = 0; i < n; i++) {
insert.append("?");
if (i != n - 1) {
insert.append(", ");
}
}
insert.append(")");
return insert.toString();
}
Aggregations