Search in sources :

Example 1 with SyntaxVerifier

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.calcite.SyntaxVerifier 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

ColumnContext (com.yahoo.elide.datastores.aggregation.metadata.ColumnContext)1 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)1 PhysicalRefColumnContext (com.yahoo.elide.datastores.aggregation.metadata.PhysicalRefColumnContext)1 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)1 Queryable (com.yahoo.elide.datastores.aggregation.query.Queryable)1 SyntaxVerifier (com.yahoo.elide.datastores.aggregation.queryengines.sql.calcite.SyntaxVerifier)1 SQLDialect (com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.SQLDialect)1 ColumnArgReference (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ColumnArgReference)1 ExpressionParser (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ExpressionParser)1 HasJoinVisitor (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.HasJoinVisitor)1 JoinReference (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.JoinReference)1 PhysicalReference (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.PhysicalReference)1 Reference (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.Reference)1 ReferenceExtractor (com.yahoo.elide.datastores.aggregation.queryengines.sql.expression.ReferenceExtractor)1 Arrays (java.util.Arrays)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Pair (org.apache.commons.lang3.tuple.Pair)1