Search in sources :

Example 6 with Queryable

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;
}
Also used : Queryable(com.yahoo.elide.datastores.aggregation.query.Queryable) SQLJoin(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLJoin) ToString(lombok.ToString)

Example 7 with Queryable

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();
}
Also used : Path(com.yahoo.elide.core.Path) JoinPath(com.yahoo.elide.datastores.aggregation.core.JoinPath) JoinPath(com.yahoo.elide.datastores.aggregation.core.JoinPath) Queryable(com.yahoo.elide.datastores.aggregation.query.Queryable) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) Argument.getArgumentMapFromString(com.yahoo.elide.core.request.Argument.getArgumentMapFromString)

Example 8 with Queryable

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();
}
Also used : SyntaxVerifier(com.yahoo.elide.datastores.aggregation.queryengines.sql.calcite.SyntaxVerifier) ReferenceExtractor(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) Queryable(com.yahoo.elide.datastores.aggregation.query.Queryable) ColumnContext(com.yahoo.elide.datastores.aggregation.metadata.ColumnContext) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) JoinReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.JoinReference) Collectors(java.util.stream.Collectors) PhysicalRefColumnContext(com.yahoo.elide.datastores.aggregation.metadata.PhysicalRefColumnContext) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) SQLDialect(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect) PhysicalReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.PhysicalReference) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) HasJoinVisitor(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.HasJoinVisitor) ExpressionParser(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser) Reference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference) LinkedHashSet(java.util.LinkedHashSet) ColumnArgReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ColumnArgReference) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) ColumnArgReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ColumnArgReference) JoinReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.JoinReference) PhysicalReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.PhysicalReference) Reference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference) ColumnArgReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ColumnArgReference) JoinReference(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.JoinReference) SQLDialect(com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect) SyntaxVerifier(com.yahoo.elide.datastores.aggregation.queryengines.sql.calcite.SyntaxVerifier) ExpressionParser(com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser)

Aggregations

Queryable (com.yahoo.elide.datastores.aggregation.query.Queryable)8 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)5 Test (org.junit.jupiter.api.Test)3 Argument.getArgumentMapFromString (com.yahoo.elide.core.request.Argument.getArgumentMapFromString)2 JoinPath (com.yahoo.elide.datastores.aggregation.core.JoinPath)2 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)2 SQLDialect (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect)2 SQLJoin (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLJoin)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ToString (lombok.ToString)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Path (com.yahoo.elide.core.Path)1 Argument (com.yahoo.elide.core.request.Argument)1 ColumnContext (com.yahoo.elide.datastores.aggregation.metadata.ColumnContext)1 PhysicalRefColumnContext (com.yahoo.elide.datastores.aggregation.metadata.PhysicalRefColumnContext)1 ColumnType (com.yahoo.elide.datastores.aggregation.metadata.enums.ColumnType)1 ValueType (com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType)1