use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor 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;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor in project elide by yahoo.
the class SQLColumnProjection method canNest.
@Override
default boolean canNest(Queryable source, MetaDataStore metaDataStore) {
SQLDialect dialect = source.getConnectionDetails().getDialect();
String sql = toSQL(source, metaDataStore);
SyntaxVerifier verifier = new SyntaxVerifier(dialect);
boolean canNest = verifier.verify(sql);
if (!canNest) {
LOGGER.debug("Unable to nest {} because {}", this.getName(), verifier.getLastError());
return false;
}
List<Reference> references = new ExpressionParser(metaDataStore).parse(source, this);
// because rewriting the SQL in the outer expression will lose the context of the calling $$column.
return references.stream().map(reference -> reference.accept(new ReferenceExtractor<JoinReference>(JoinReference.class, metaDataStore, ReferenceExtractor.Mode.SAME_QUERY))).flatMap(Set::stream).map(reference -> reference.accept(new ReferenceExtractor<ColumnArgReference>(ColumnArgReference.class, metaDataStore))).flatMap(Set::stream).collect(Collectors.toSet()).isEmpty();
}
Aggregations