use of com.hortonworks.registries.storage.search.WhereClause in project registry by hortonworks.
the class SchemaRegistryResource method findSchemaMetadataInfos.
private Collection<SchemaMetadataInfo> findSchemaMetadataInfos(MultivaluedMap<String, String> queryParameters) {
Collection<SchemaMetadataInfo> schemaMetadataInfos;
// query for those complex queries.
if (queryParameters.containsKey(SchemaMetadataStorable.NAME) || queryParameters.containsKey(SchemaMetadataStorable.DESCRIPTION)) {
String name = queryParameters.getFirst(SchemaMetadataStorable.NAME);
String description = queryParameters.getFirst(SchemaMetadataStorable.DESCRIPTION);
WhereClause whereClause = WhereClause.begin().contains(SchemaMetadataStorable.NAME, name).or().contains(SchemaMetadataStorable.DESCRIPTION, description).combine();
// todo refactor orderby field in DefaultSchemaRegistry#search APIs merge with these APIs
String orderByFieldStr = queryParameters.getFirst(ORDER_BY_FIELDS_PARAM_NAME);
schemaMetadataInfos = schemaRegistry.searchSchemas(whereClause, getOrderByFields(orderByFieldStr));
} else {
schemaMetadataInfos = Collections.emptyList();
}
return schemaMetadataInfos;
}
use of com.hortonworks.registries.storage.search.WhereClause 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