Search in sources :

Example 1 with LogicalReference

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.LogicalReference in project elide by yahoo.

the class QueryPlanTranslator method addHiddenProjections.

public static Query.QueryBuilder addHiddenProjections(MetaDataStore metaDataStore, Query.QueryBuilder builder, Query query) {
    Set<ColumnProjection> directReferencedColumns = Streams.concat(query.getColumnProjections().stream(), query.getFilterProjections(query.getWhereFilter(), ColumnProjection.class).stream()).collect(Collectors.toSet());
    ExpressionParser parser = new ExpressionParser(metaDataStore);
    Set<ColumnProjection> indirectReferenceColumns = new HashSet<>();
    directReferencedColumns.forEach(column -> {
        parser.parse(query.getSource(), column).stream().map(reference -> reference.accept(new ReferenceExtractor<LogicalReference>(LogicalReference.class, metaDataStore, ReferenceExtractor.Mode.SAME_QUERY))).flatMap(Set::stream).map(LogicalReference::getColumn).forEach(indirectReferenceColumns::add);
    });
    Streams.concat(directReferencedColumns.stream(), indirectReferenceColumns.stream()).forEach(column -> {
        if (query.getColumnProjection(column.getAlias(), column.getArguments()) == null) {
            builder.column(column.withProjected(false));
        }
    });
    return builder;
}
Also used : ReferenceExtractor(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor) Queryable(com.yahoo.elide.datastores.aggregation.query.Queryable) Set(java.util.Set) QueryPlan(com.yahoo.elide.datastores.aggregation.query.QueryPlan) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Query(com.yahoo.elide.datastores.aggregation.query.Query) LogicalReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.LogicalReference) AndFilterExpression(com.yahoo.elide.core.filter.expression.AndFilterExpression) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) DefaultQueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) QueryPlanMerger(com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger) ExpressionParser(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser) QueryVisitor(com.yahoo.elide.datastores.aggregation.query.QueryVisitor) Set(java.util.Set) HashSet(java.util.HashSet) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) ExpressionParser(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser) LogicalReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.LogicalReference) HashSet(java.util.HashSet)

Aggregations

Streams (com.google.common.collect.Streams)1 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)1 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)1 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)1 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)1 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)1 Query (com.yahoo.elide.datastores.aggregation.query.Query)1 QueryPlan (com.yahoo.elide.datastores.aggregation.query.QueryPlan)1 QueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.QueryPlanMerger)1 QueryVisitor (com.yahoo.elide.datastores.aggregation.query.QueryVisitor)1 Queryable (com.yahoo.elide.datastores.aggregation.query.Queryable)1 ExpressionParser (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser)1 LogicalReference (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.LogicalReference)1 ReferenceExtractor (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1