use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser 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.ExpressionParser 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();
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser in project elide by yahoo.
the class SQLColumnProjection method nest.
@Override
default Pair<ColumnProjection, Set<ColumnProjection>> nest(Queryable source, MetaDataStore store, boolean joinInOuter) {
List<Reference> references = new ExpressionParser(store).parse(source, getExpression());
boolean requiresJoin = requiresJoin(references);
String columnId = source.isRoot() ? getName() : getAlias();
boolean inProjection = source.getColumnProjection(columnId, getArguments(), true) != null;
ColumnProjection outerProjection;
Set<ColumnProjection> innerProjections;
if (requiresJoin && joinInOuter) {
String outerProjectionExpression = toPhysicalReferences(source, store);
outerProjection = withExpression(outerProjectionExpression, inProjection);
innerProjections = extractPhysicalReferences(source, references, store);
} else {
outerProjection = withExpression("{{$" + this.getSafeAlias() + "}}", isProjected());
innerProjections = new LinkedHashSet<>(Arrays.asList(this));
}
return Pair.of(outerProjection, innerProjections);
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser in project elide by yahoo.
the class SQLTimeDimensionProjection method nest.
@Override
public Pair<ColumnProjection, Set<ColumnProjection>> nest(Queryable source, MetaDataStore store, boolean joinInOuter) {
List<Reference> references = new ExpressionParser(store).parse(source, getExpression());
boolean requiresJoin = SQLColumnProjection.requiresJoin(references);
String columnId = source.isRoot() ? getName() : getAlias();
boolean inProjection = source.getColumnProjection(columnId, getArguments(), true) != null;
ColumnProjection outerProjection;
Set<ColumnProjection> innerProjections;
if (requiresJoin && joinInOuter) {
String outerProjectionExpression = toPhysicalReferences(source, store);
outerProjection = withExpression(outerProjectionExpression, inProjection);
innerProjections = SQLColumnProjection.extractPhysicalReferences(source, references, store);
} else {
outerProjection = SQLTimeDimensionProjection.builder().name(name).alias(alias).valueType(valueType).columnType(columnType).grain(new TimeDimensionGrain(this.getName(), grain.getGrain())).expression("{{$" + this.getSafeAlias() + "}}").projected(isProjected()).arguments(arguments).timeZone(timeZone).build();
innerProjections = new LinkedHashSet<>(Arrays.asList(this));
}
return Pair.of(outerProjection, innerProjections);
}
Aggregations