use of com.baidu.hugegraph.backend.query.Query.Order in project incubator-hugegraph by apache.
the class CassandraTable method query2Select.
protected List<Select> query2Select(String table, Query query) {
// Build query
Selection selection = QueryBuilder.select();
// Set aggregate
Aggregate aggregate = query.aggregate();
if (aggregate != null) {
if (aggregate.countAll()) {
selection.countAll();
} else {
selection.fcall(aggregate.func().string(), aggregate.column());
}
}
// Set table
Select select = selection.from(table);
// NOTE: Cassandra does not support query.offset()
if (query.offset() != 0) {
LOG.debug("Query offset is not supported on Cassandra store " + "currently, it will be replaced by [0, offset + limit)");
}
// Set order-by
for (Map.Entry<HugeKeys, Order> order : query.orders().entrySet()) {
String name = formatKey(order.getKey());
if (order.getValue() == Order.ASC) {
select.orderBy(QueryBuilder.asc(name));
} else {
assert order.getValue() == Order.DESC;
select.orderBy(QueryBuilder.desc(name));
}
}
// Is query by id?
List<Select> ids = this.queryId2Select(query, select);
if (query.conditionsSize() == 0) {
// Query only by id
this.setPageState(query, ids);
LOG.debug("Query only by id(s): {}", ids);
return ids;
} else {
List<Select> conds = new ArrayList<>(ids.size());
for (Select id : ids) {
// Query by condition
conds.addAll(this.queryCondition2Select(query, id));
}
this.setPageState(query, conds);
LOG.debug("Query by conditions: {}", conds);
return conds;
}
}
Aggregations