Search in sources :

Example 1 with SelectExpression

use of org.apache.atlas.query.Expressions.SelectExpression 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

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