use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference in project elide by yahoo.
the class SubqueryFilterSplitter method visitPredicate.
@Override
public SplitFilter visitPredicate(FilterPredicate filterPredicate) {
Type<?> tableType = filterPredicate.getEntityType();
String fieldName = filterPredicate.getField();
SQLTable table = metaDataStore.getTable(tableType);
List<Reference> references = parser.parse(table, table.getColumnProjection(fieldName));
boolean hasJoin = references.stream().anyMatch(ref -> ref.accept(new HasJoinVisitor()));
if (hasJoin) {
return SplitFilter.builder().outer(filterPredicate).build();
}
return SplitFilter.builder().inner(filterPredicate).build();
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference in project elide by yahoo.
the class QueryTranslator method extractJoinExpressions.
/**
* Get required join expressions for given column in given Query.
* @param column {@link ColumnProjection}
* @param query Expanded Query.
* @return A set of Join expressions that capture a relationship traversal.
*/
private Set<String> extractJoinExpressions(ColumnProjection column, Query query) {
Set<String> joinExpressions = new LinkedHashSet<>();
ColumnContext context = ColumnContext.builder().queryable(query).alias(query.getSource().getAlias()).metaDataStore(metaDataStore).column(column).tableArguments(query.getArguments()).build();
JoinExpressionExtractor visitor = new JoinExpressionExtractor(context);
List<Reference> references = parser.parse(query.getSource(), column);
references.forEach(ref -> joinExpressions.addAll(ref.accept(visitor)));
return joinExpressions;
}
use of com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference 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.Reference 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.Reference 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