use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.
the class DefaultSchemaRegistry method findSchemaMetadata.
@Override
public Collection<SchemaMetadataInfo> findSchemaMetadata(Map<String, String> props) {
// todo get only few selected columns instead of getting the whole row.
Collection<SchemaMetadataStorable> storables;
if (props == null || props.isEmpty()) {
storables = storageManager.list(SchemaMetadataStorable.NAME_SPACE);
} else {
List<QueryParam> orderByFieldQueryParams = new ArrayList<>();
List<QueryParam> queryParams = new ArrayList<>(props.size());
for (Map.Entry<String, String> entry : props.entrySet()) {
QueryParam queryParam = new QueryParam(entry.getKey(), entry.getValue());
if (ORDER_BY_FIELDS_PARAM_NAME.equals(entry.getKey())) {
orderByFieldQueryParams.add(queryParam);
} else {
queryParams.add(queryParam);
}
}
storables = storageManager.find(SchemaMetadataStorable.NAME_SPACE, queryParams, getOrderByFields(orderByFieldQueryParams));
}
List<SchemaMetadataInfo> result;
if (storables != null && !storables.isEmpty()) {
result = storables.stream().map(SchemaMetadataStorable::toSchemaMetadataInfo).collect(Collectors.toList());
} else {
result = Collections.emptyList();
}
return result;
}
use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.
the class DefaultSchemaRegistry method getOrderByFields.
private List<OrderByField> getOrderByFields(List<QueryParam> queryParams) {
if (queryParams == null || queryParams.isEmpty()) {
return Collections.emptyList();
}
List<OrderByField> orderByFields = new ArrayList<>();
for (QueryParam queryParam : queryParams) {
if (ORDER_BY_FIELDS_PARAM_NAME.equals(queryParam.getName())) {
// _orderByFields=[<field-name>,<a/d>,]*
// example can be : _orderByFields=foo,a,bar,d
// order by foo with ascending then bar with descending
String value = queryParam.getValue();
String[] splitStrings = value.split(",");
for (int i = 0; i < splitStrings.length; i += 2) {
String ascStr = splitStrings[i + 1];
boolean descending;
if ("a".equals(ascStr)) {
descending = false;
} else if ("d".equals(ascStr)) {
descending = true;
} else {
throw new IllegalArgumentException("Ascending or Descending identifier can only be 'a' or 'd' respectively.");
}
orderByFields.add(OrderByField.of(splitStrings[i], descending));
}
}
}
return orderByFields;
}
Aggregations