Search in sources :

Example 6 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class ImpalaAstBuilder method visitQuerySpecification.

@Override
public Node visitQuerySpecification(ImpalaSqlParser.QuerySpecificationContext context) {
    Optional<Relation> from = Optional.empty();
    List<SelectItem> selectItems = visit(context.selectItem(), SelectItem.class);
    List<Relation> relations = visit(context.relation(), Relation.class);
    if (!relations.isEmpty()) {
        // synthesize implicit join nodes
        Iterator<Relation> iterator = relations.iterator();
        Relation relation = iterator.next();
        while (iterator.hasNext()) {
            relation = new Join(getLocation(context), Join.Type.IMPLICIT, relation, iterator.next(), Optional.empty());
        }
        from = Optional.of(relation);
    }
    return new QuerySpecification(getLocation(context), new Select(getLocation(context.SELECT()), isDistinct(context.setQuantifier()), selectItems), from, visitIfPresent(context.where, Expression.class), visitIfPresent(context.groupBy(), GroupBy.class), visitIfPresent(context.having, Expression.class), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join)

Example 7 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class RelationPlanner method process.

private SetOperationPlan process(SetOperation node) {
    List<Symbol> outputs = null;
    ImmutableList.Builder<PlanNode> sources = ImmutableList.builder();
    ImmutableListMultimap.Builder<Symbol, Symbol> symbolMapping = ImmutableListMultimap.builder();
    List<RelationPlan> subPlans = node.getRelations().stream().map(relation -> processAndCoerceIfNecessary(relation, null)).collect(toImmutableList());
    for (RelationPlan relationPlan : subPlans) {
        List<Symbol> childOutputSymbols = relationPlan.getFieldMappings();
        if (outputs == null) {
            // Use the first Relation to derive output symbol names
            RelationType descriptor = relationPlan.getDescriptor();
            ImmutableList.Builder<Symbol> outputSymbolBuilder = ImmutableList.builder();
            for (Field field : descriptor.getVisibleFields()) {
                int fieldIndex = descriptor.indexOf(field);
                Symbol symbol = childOutputSymbols.get(fieldIndex);
                outputSymbolBuilder.add(planSymbolAllocator.newSymbol(symbol.getName(), planSymbolAllocator.getTypes().get(symbol)));
            }
            outputs = outputSymbolBuilder.build();
        }
        RelationType descriptor = relationPlan.getDescriptor();
        checkArgument(descriptor.getVisibleFieldCount() == outputs.size(), "Expected relation to have %s symbols but has %s symbols", descriptor.getVisibleFieldCount(), outputs.size());
        int fieldId = 0;
        for (Field field : descriptor.getVisibleFields()) {
            int fieldIndex = descriptor.indexOf(field);
            symbolMapping.put(outputs.get(fieldId), childOutputSymbols.get(fieldIndex));
            fieldId++;
        }
        sources.add(relationPlan.getRoot());
    }
    return new SetOperationPlan(sources.build(), symbolMapping.build());
}
Also used : Table(io.prestosql.sql.tree.Table) SampledRelation(io.prestosql.sql.tree.SampledRelation) ListMultimap(com.google.common.collect.ListMultimap) Relation(io.prestosql.sql.tree.Relation) CTEScanNode(io.prestosql.spi.plan.CTEScanNode) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) AggregationNode(io.prestosql.spi.plan.AggregationNode) Cast(io.prestosql.sql.tree.Cast) SemanticExceptions.notSupportedException(io.prestosql.sql.analyzer.SemanticExceptions.notSupportedException) Join(io.prestosql.sql.tree.Join) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowType(io.prestosql.spi.type.RowType) SystemSessionProperties.getTaskConcurrency(io.prestosql.SystemSessionProperties.getTaskConcurrency) Identifier(io.prestosql.sql.tree.Identifier) Row(io.prestosql.sql.tree.Row) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) SystemSessionProperties.getCteMaxQueueSize(io.prestosql.SystemSessionProperties.getCteMaxQueueSize) NodeRef(io.prestosql.sql.tree.NodeRef) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) ExpressionUtils(io.prestosql.sql.ExpressionUtils) SymbolReference(io.prestosql.sql.tree.SymbolReference) Union(io.prestosql.sql.tree.Union) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Field(io.prestosql.sql.analyzer.Field) Iterables(com.google.common.collect.Iterables) IntersectNode(io.prestosql.spi.plan.IntersectNode) ExpressionTreeRewriter(io.prestosql.sql.tree.ExpressionTreeRewriter) UnnestNode(io.prestosql.sql.planner.plan.UnnestNode) ArrayList(java.util.ArrayList) MapType(io.prestosql.spi.type.MapType) LinkedHashMap(java.util.LinkedHashMap) Session(io.prestosql.Session) AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) SetOperation(io.prestosql.sql.tree.SetOperation) Query(io.prestosql.sql.tree.Query) Assignments(io.prestosql.spi.plan.Assignments) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ValuesNode(io.prestosql.spi.plan.ValuesNode) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) SampleNode(io.prestosql.sql.planner.plan.SampleNode) Lateral(io.prestosql.sql.tree.Lateral) UnmodifiableIterator(com.google.common.collect.UnmodifiableIterator) Expression(io.prestosql.sql.tree.Expression) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) TableSubquery(io.prestosql.sql.tree.TableSubquery) Unnest(io.prestosql.sql.tree.Unnest) SystemSessionProperties.getExecutionPolicy(io.prestosql.SystemSessionProperties.getExecutionPolicy) Intersect(io.prestosql.sql.tree.Intersect) QualifiedName(io.prestosql.sql.tree.QualifiedName) DefaultTraversalVisitor(io.prestosql.sql.tree.DefaultTraversalVisitor) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) FilterNode(io.prestosql.spi.plan.FilterNode) Type(io.prestosql.spi.type.Type) QuerySpecification(io.prestosql.sql.tree.QuerySpecification) TypeCoercion(io.prestosql.type.TypeCoercion) Except(io.prestosql.sql.tree.Except) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) ImmutableMap(com.google.common.collect.ImmutableMap) ArrayType(io.prestosql.spi.type.ArrayType) NaturalJoin(io.prestosql.sql.tree.NaturalJoin) UUID(java.util.UUID) RelationType(io.prestosql.sql.analyzer.RelationType) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Scope(io.prestosql.sql.analyzer.Scope) List(java.util.List) UnionNode(io.prestosql.spi.plan.UnionNode) Optional(java.util.Optional) Analysis(io.prestosql.sql.analyzer.Analysis) ExceptNode(io.prestosql.spi.plan.ExceptNode) MetadataUtil.createQualifiedObjectName(io.prestosql.metadata.MetadataUtil.createQualifiedObjectName) JoinNodeUtils(io.prestosql.sql.planner.plan.JoinNodeUtils) InPredicate(io.prestosql.sql.tree.InPredicate) Logger(io.airlift.log.Logger) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) HashMap(java.util.HashMap) RelationId(io.prestosql.sql.analyzer.RelationId) INNER(io.prestosql.sql.tree.Join.Type.INNER) TableHandle(io.prestosql.spi.metadata.TableHandle) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) HashSet(java.util.HashSet) Values(io.prestosql.sql.tree.Values) SystemSessionProperties.isCTEReuseEnabled(io.prestosql.SystemSessionProperties.isCTEReuseEnabled) ImmutableList(com.google.common.collect.ImmutableList) JoinUsing(io.prestosql.sql.tree.JoinUsing) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) Iterator(java.util.Iterator) LambdaArgumentDeclaration(io.prestosql.sql.tree.LambdaArgumentDeclaration) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) RowExpression(io.prestosql.spi.relation.RowExpression) Symbol(io.prestosql.spi.plan.Symbol) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Field(io.prestosql.sql.analyzer.Field) PlanNode(io.prestosql.spi.plan.PlanNode) RelationType(io.prestosql.sql.analyzer.RelationType) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

Example 8 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class ImpalaAstBuilder method visitAliasedRelation.

@Override
public Node visitAliasedRelation(ImpalaSqlParser.AliasedRelationContext context) {
    Relation child = (Relation) visit(context.relationPrimary());
    if (context.identifier() == null) {
        return child;
    }
    List<Identifier> aliases = null;
    if (context.columnAliases() != null) {
        aliases = visit(context.columnAliases().identifier(), Identifier.class);
    }
    return new AliasedRelation(getLocation(context), child, (Identifier) visit(context.identifier()), aliases);
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) AliasedRelation(io.prestosql.sql.tree.AliasedRelation)

Example 9 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class ImpalaAstBuilder method visitJoinRelation.

@Override
public Node visitJoinRelation(ImpalaSqlParser.JoinRelationContext context) {
    Relation left = (Relation) visit(context.left);
    Relation right;
    if (context.CROSS() != null) {
        right = (Relation) visit(context.right);
        return new Join(getLocation(context), Join.Type.CROSS, left, right, Optional.empty());
    }
    if (context.joinType().SEMI() != null) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().SEMI().getText(), "[SEMI] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "SEMI", context);
    }
    if (context.joinType().ANTI() != null) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().ANTI().getText(), "[ANTI] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "ANTI", context);
    }
    if (context.joinType().INNER() != null && (context.joinType().LEFT() != null || context.joinType().RIGHT() != null)) {
        addDiff(DiffType.UNSUPPORTED, context.joinType().INNER().getText(), "[LEFT INNER || RIGHT INNER] is not supported");
        throw unsupportedError(ErrorType.UNSUPPORTED_KEYWORDS, "LEFT INNER || RIGHT INNER", context);
    }
    JoinCriteria criteria;
    right = (Relation) visit(context.rightRelation);
    if (context.joinCriteria().ON() != null) {
        criteria = new JoinOn((Expression) visit(context.joinCriteria().booleanExpression()));
    } else if (context.joinCriteria().USING() != null) {
        criteria = new JoinUsing(visit(context.joinCriteria().identifier(), Identifier.class));
    } else {
        throw new IllegalArgumentException("Unsupported join criteria");
    }
    Join.Type joinType;
    if (context.joinType().LEFT() != null) {
        joinType = Join.Type.LEFT;
    } else if (context.joinType().RIGHT() != null) {
        joinType = Join.Type.RIGHT;
    } else if (context.joinType().FULL() != null) {
        joinType = Join.Type.FULL;
    } else {
        joinType = Join.Type.INNER;
    }
    return new Join(getLocation(context), joinType, left, right, Optional.of(criteria));
}
Also used : SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) Identifier(io.prestosql.sql.tree.Identifier) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LambdaExpression(io.prestosql.sql.tree.LambdaExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) JoinCriteria(io.prestosql.sql.tree.JoinCriteria) Join(io.prestosql.sql.tree.Join) JoinUsing(io.prestosql.sql.tree.JoinUsing) JoinOn(io.prestosql.sql.tree.JoinOn)

Example 10 with Relation

use of io.prestosql.sql.tree.Relation in project hetu-core by openlookeng.

the class HiveAstBuilder method visitQuerySpecification.

@Override
public Node visitQuerySpecification(HiveSqlParser.QuerySpecificationContext context) {
    if (context.lateralView().size() > 0) {
        addDiff(DiffType.UNSUPPORTED, context.LATERAL(0).getText(), "[LATERAL VIEW] is not supported");
        addDiff(DiffType.UNSUPPORTED, context.VIEW(0).getText(), null);
        throw unsupportedError(ErrorType.UNSUPPORTED_STATEMENT, "Unsupported statement: LATERAL VIEW", context.lateralView(0));
    }
    Optional<Relation> from = Optional.empty();
    List<SelectItem> selectItems = visit(context.selectItem(), SelectItem.class);
    List<Relation> relations = visit(context.relation(), Relation.class);
    if (!relations.isEmpty()) {
        // synthesize implicit join nodes
        Iterator<Relation> iterator = relations.iterator();
        Relation relation = iterator.next();
        while (iterator.hasNext()) {
            relation = new Join(getLocation(context), Join.Type.IMPLICIT, relation, iterator.next(), Optional.empty());
        }
        from = Optional.of(relation);
    }
    return new QuerySpecification(getLocation(context), new Select(getLocation(context.SELECT()), isDistinct(context.setQuantifier()), selectItems), from, visitIfPresent(context.where, Expression.class), visitIfPresent(context.groupBy(), GroupBy.class), visitIfPresent(context.having, Expression.class), Optional.empty(), Optional.empty(), Optional.empty());
}
Also used : QuerySpecification(io.prestosql.sql.tree.QuerySpecification) SampledRelation(io.prestosql.sql.tree.SampledRelation) Relation(io.prestosql.sql.tree.Relation) AliasedRelation(io.prestosql.sql.tree.AliasedRelation) GroupBy(io.prestosql.sql.tree.GroupBy) SimpleGroupBy(io.prestosql.sql.tree.SimpleGroupBy) ArithmeticUnaryExpression(io.prestosql.sql.tree.ArithmeticUnaryExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) SubqueryExpression(io.prestosql.sql.tree.SubqueryExpression) IfExpression(io.prestosql.sql.tree.IfExpression) InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(io.prestosql.sql.tree.SearchedCaseExpression) SubscriptExpression(io.prestosql.sql.tree.SubscriptExpression) DereferenceExpression(io.prestosql.sql.tree.DereferenceExpression) QuantifiedComparisonExpression(io.prestosql.sql.tree.QuantifiedComparisonExpression) NullIfExpression(io.prestosql.sql.tree.NullIfExpression) SelectItem(io.prestosql.sql.tree.SelectItem) CreateTableAsSelect(io.prestosql.sql.tree.CreateTableAsSelect) Select(io.prestosql.sql.tree.Select) Join(io.prestosql.sql.tree.Join)

Aggregations

AliasedRelation (io.prestosql.sql.tree.AliasedRelation)10 Relation (io.prestosql.sql.tree.Relation)10 SampledRelation (io.prestosql.sql.tree.SampledRelation)10 Join (io.prestosql.sql.tree.Join)7 CoalesceExpression (io.prestosql.sql.tree.CoalesceExpression)6 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)6 Expression (io.prestosql.sql.tree.Expression)6 Identifier (io.prestosql.sql.tree.Identifier)6 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)5 ArithmeticUnaryExpression (io.prestosql.sql.tree.ArithmeticUnaryExpression)5 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)5 IfExpression (io.prestosql.sql.tree.IfExpression)5 InListExpression (io.prestosql.sql.tree.InListExpression)5 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)5 NotExpression (io.prestosql.sql.tree.NotExpression)5 NullIfExpression (io.prestosql.sql.tree.NullIfExpression)5 QuantifiedComparisonExpression (io.prestosql.sql.tree.QuantifiedComparisonExpression)5 SearchedCaseExpression (io.prestosql.sql.tree.SearchedCaseExpression)5 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)5 SubqueryExpression (io.prestosql.sql.tree.SubqueryExpression)5