use of com.yahoo.elide.datastores.aggregation.query.Queryable in project elide by yahoo.
the class PhysicalRefColumnContext method getJoinContext.
@Override
protected ColumnContext getJoinContext(String key) {
SQLJoin sqlJoin = this.queryable.getJoin(key);
Queryable joinQueryable = metaDataStore.getTable(sqlJoin.getJoinTableType());
String joinPath = isBlank(this.alias) ? key : this.alias + PERIOD + key;
PhysicalRefColumnContext joinCtx = PhysicalRefColumnContext.physicalRefContextBuilder().queryable(joinQueryable).alias(joinPath).metaDataStore(this.metaDataStore).column(this.column).tableArguments(mergedArgumentMap(joinQueryable.getArguments(), this.getTableArguments())).build();
return joinCtx;
}
use of com.yahoo.elide.datastores.aggregation.query.Queryable in project elide by yahoo.
the class ExpressionParser method buildJoin.
private JoinReference buildJoin(Queryable source, String referenceName, Map<String, Argument> callingColumnArgs, Map<String, Argument> fixedArguments) {
Queryable root = source.getRoot();
Type<?> tableClass = dictionary.getEntityClass(root.getName(), root.getVersion());
JoinPath joinPath = new JoinPath(tableClass, metaDataStore, referenceName);
Path.PathElement lastElement = joinPath.lastElement().get();
Queryable joinSource = metaDataStore.getTable(lastElement.getType());
String fieldName = lastElement.getFieldName();
Reference reference;
if (fieldName.startsWith("$")) {
reference = PhysicalReference.builder().source(joinSource).name(fieldName.substring(1)).build();
} else {
ColumnProjection referencedColumn = joinSource.getColumnProjection(fieldName);
ColumnProjection newColumn = referencedColumn.withArguments(mergedArgumentMap(referencedColumn.getArguments(), callingColumnArgs, fixedArguments));
reference = LogicalReference.builder().source(joinSource).column(newColumn).references(buildReferenceForColumn(joinSource, newColumn)).build();
}
return JoinReference.builder().path(joinPath).source(source).reference(reference).build();
}
use of com.yahoo.elide.datastores.aggregation.query.Queryable 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