Search in sources :

Example 1 with AttributeSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult in project incubator-atlas by apache.

the class QuickStartV2 method search.

private void search() throws Exception {
    System.out.println("\nSample DSL Queries: ");
    for (String dslQuery : getDSLQueries()) {
        AtlasSearchResult results = atlasClientV2.dslSearchWithParams(dslQuery, 10, 0);
        if (results != null) {
            List<AtlasEntityHeader> entitiesResult = results.getEntities();
            List<AtlasFullTextResult> fullTextResults = results.getFullTextResult();
            AttributeSearchResult attribResult = results.getAttributes();
            if (CollectionUtils.isNotEmpty(entitiesResult)) {
                System.out.println("query [" + dslQuery + "] returned [" + entitiesResult.size() + "] rows.");
            } else if (CollectionUtils.isNotEmpty(fullTextResults)) {
                System.out.println("query [" + dslQuery + "] returned [" + fullTextResults.size() + "] rows.");
            } else if (attribResult != null) {
                System.out.println("query [" + dslQuery + "] returned [" + attribResult.getValues().size() + "] rows.");
            }
        } else {
            System.out.println("query [" + dslQuery + "] failed, results:" + results);
        }
    }
}
Also used : AttributeSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) AtlasFullTextResult(org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult) AtlasSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult)

Example 2 with AttributeSearchResult

use of org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult in project incubator-atlas by apache.

the class EntityDiscoveryService method toAttributesResult.

private AttributeSearchResult toAttributesResult(List list, GremlinQuery query) {
    AttributeSearchResult ret = new AttributeSearchResult();
    List<String> names = new ArrayList<>();
    List<List<Object>> values = new ArrayList<>();
    // extract select attributes from gremlin query
    Option<SelectExpression> selectExpr = SelectExpressionHelper.extractSelectExpression(query.expr());
    if (selectExpr.isDefined()) {
        List<AliasExpression> aliases = selectExpr.get().toJavaList();
        if (CollectionUtils.isNotEmpty(aliases)) {
            for (AliasExpression alias : aliases) {
                names.add(alias.alias());
            }
            ret.setName(names);
        }
    }
    for (Object mapObj : list) {
        Map map = (mapObj instanceof Map ? (Map) mapObj : null);
        if (MapUtils.isNotEmpty(map)) {
            for (Object key : map.keySet()) {
                Object vals = map.get(key);
                values.add((List<Object>) vals);
            }
            ret.setValues(values);
        }
    }
    return ret;
}
Also used : AttributeSearchResult(org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult) AliasExpression(org.apache.atlas.query.Expressions.AliasExpression) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) SelectExpression(org.apache.atlas.query.Expressions.SelectExpression) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AttributeSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 AtlasFullTextResult (org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult)1 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)1 AliasExpression (org.apache.atlas.query.Expressions.AliasExpression)1 SelectExpression (org.apache.atlas.query.Expressions.SelectExpression)1