use of com.baidu.hugegraph.backend.query.Aggregate in project incubator-hugegraph by apache.
the class MysqlTable method query2Select.
protected List<StringBuilder> query2Select(String table, Query query) {
// Build query
StringBuilder select = new StringBuilder(64);
select.append("SELECT ");
// Set aggregate
Aggregate aggregate = query.aggregate();
if (aggregate != null) {
select.append(aggregate.toString());
} else {
select.append("*");
}
// Set table
select.append(" FROM ").append(table);
// Is query by id?
List<StringBuilder> ids = this.queryId2Select(query, select);
List<StringBuilder> selections;
if (query.conditionsSize() == 0) {
// Query only by id
LOG.debug("Query only by id(s): {}", ids);
selections = ids;
} else {
ConditionQuery condQuery = (ConditionQuery) query;
if (condQuery.containsScanRelation()) {
assert ids.size() == 1;
return ImmutableList.of(queryByRange(condQuery, ids.get(0)));
}
selections = new ArrayList<>(ids.size());
for (StringBuilder selection : ids) {
// Query by condition
selections.addAll(this.queryCondition2Select(query, selection));
}
LOG.debug("Query by conditions: {}", selections);
}
// Set page, order-by and limit
for (StringBuilder selection : selections) {
boolean hasOrder = !query.orders().isEmpty();
if (hasOrder) {
this.wrapOrderBy(selection, query);
}
if (query.paging()) {
this.wrapPage(selection, query, false);
wrapLimit(selection, query);
} else {
if (aggregate == null && !hasOrder) {
select.append(this.orderByKeys());
}
if (!query.noLimit() || query.offset() > 0L) {
this.wrapOffset(selection, query);
}
}
}
return selections;
}
Aggregations