Search in sources :

Example 71 with QueryParam

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;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 72 with QueryParam

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;
}
Also used : OrderByField(com.hortonworks.registries.storage.OrderByField) QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)72 ArrayList (java.util.ArrayList)42 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)22 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)22 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)22 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)22 IOException (java.io.IOException)8 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)7 StorableKey (com.hortonworks.registries.storage.StorableKey)7 OrderByField (com.hortonworks.registries.storage.OrderByField)6 HashSet (java.util.HashSet)6 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)5 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)5 Timed (com.codahale.metrics.annotation.Timed)4 Preconditions (com.google.common.base.Preconditions)4 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)4 StorageException (com.hortonworks.registries.storage.exception.StorageException)4 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4