use of com.hortonworks.registries.storage.search.OrderBy in project registry by hortonworks.
the class AbstractSelectQuery method buildSqlWithSearchQuery.
protected String buildSqlWithSearchQuery(SearchQuery searchQuery, Schema schema) {
String sql = "SELECT * FROM " + fieldEncloser() + tableName + fieldEncloser();
WhereClause whereClause = searchQuery.getWhereClause();
Map<Schema.Field, Object> fieldsToValues = new HashMap<>();
if (whereClause != null) {
sql += " WHERE ";
StringBuilder clauseString = new StringBuilder();
for (PredicateCombinerPair predicateCombinerPair : whereClause.getPredicateCombinerPairs()) {
WhereClauseCombiner.Operation combinerOperation = predicateCombinerPair.getCombinerOperation();
Predicate predicate = predicateCombinerPair.getPredicate();
clauseString.append(generateClauseString(predicate, fieldsToValues, schema));
if (combinerOperation != null) {
String opStr;
switch(combinerOperation) {
case ENCL_START:
opStr = " ( ";
break;
case ENCL_FINISH:
opStr = " ) ";
break;
default:
opStr = combinerOperation.toString();
}
clauseString.append(opStr);
}
}
sql += clauseString;
}
List<OrderBy> orderByFields = searchQuery.getOrderByFields();
if (orderByFields != null && !orderByFields.isEmpty()) {
sql += " ORDER BY " + join(orderByFields.stream().map(x -> fieldEncloser() + x.getFieldName() + fieldEncloser() + (x.isAsc() ? " ASC " : " DESC ")).collect(Collectors.toList()), ", ");
}
primaryKey = new PrimaryKey(fieldsToValues);
columns = Lists.newArrayList(fieldsToValues.keySet());
return sql;
}
Aggregations