Search in sources :

Example 1 with GREATER_THAN_OR_EQUAL

use of io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL in project hetu-core by openlookeng.

the class SetOperationNodeTranslator method makeSetContainmentPlan.

public TranslationResult makeSetContainmentPlan(SetOperationNode node) {
    checkArgument(!(node instanceof UnionNode), "Cannot simplify a UnionNode");
    List<Symbol> markers = allocateSymbols(node.getSources().size(), MARKER, BOOLEAN);
    // identity projection for all the fields in each of the sources plus marker columns
    List<PlanNode> withMarkers = appendMarkers(markers, node.getSources(), node);
    // add a union over all the rewritten sources. The outputs of the union have the same name as the
    // original intersect node
    List<Symbol> outputs = node.getOutputSymbols();
    UnionNode union = union(withMarkers, ImmutableList.copyOf(concat(outputs, markers)));
    // add count aggregations and filter rows where any of the counts is >= 1
    List<Symbol> aggregationOutputs = allocateSymbols(markers.size(), "count", BIGINT);
    AggregationNode aggregation = computeCounts(union, outputs, markers, aggregationOutputs);
    List<Expression> presentExpression = aggregationOutputs.stream().map(symbol -> new ComparisonExpression(GREATER_THAN_OR_EQUAL, toSymbolReference(symbol), GENERIC_LITERAL)).collect(toImmutableList());
    return new TranslationResult(aggregation, presentExpression);
}
Also used : GREATER_THAN_OR_EQUAL(io.prestosql.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) StandardTypes(io.prestosql.spi.type.StandardTypes) Literal(io.prestosql.sql.tree.Literal) DEFAULT_NAMESPACE(io.prestosql.spi.connector.CatalogSchemaName.DEFAULT_NAMESPACE) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Cast(io.prestosql.sql.tree.Cast) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) Iterables.concat(com.google.common.collect.Iterables.concat) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) Symbol(io.prestosql.spi.plan.Symbol) SetOperationNodeUtils.sourceSymbolMap(io.prestosql.sql.planner.optimizations.SetOperationNodeUtils.sourceSymbolMap) TypeSignatureProvider.fromTypes(io.prestosql.sql.analyzer.TypeSignatureProvider.fromTypes) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) SetOperationNode(io.prestosql.spi.plan.SetOperationNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) NullLiteral(io.prestosql.sql.tree.NullLiteral) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) List(java.util.List) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) SymbolReference(io.prestosql.sql.tree.SymbolReference) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) UnionNode(io.prestosql.spi.plan.UnionNode) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) PlanNode(io.prestosql.spi.plan.PlanNode) UnionNode(io.prestosql.spi.plan.UnionNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) Symbol(io.prestosql.spi.plan.Symbol) AggregationNode(io.prestosql.spi.plan.AggregationNode)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.concat (com.google.common.collect.Iterables.concat)1 Metadata (io.prestosql.metadata.Metadata)1 DEFAULT_NAMESPACE (io.prestosql.spi.connector.CatalogSchemaName.DEFAULT_NAMESPACE)1 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1 AggregationNode.singleGroupingSet (io.prestosql.spi.plan.AggregationNode.singleGroupingSet)1 Assignments (io.prestosql.spi.plan.Assignments)1 PlanNode (io.prestosql.spi.plan.PlanNode)1 PlanNodeIdAllocator (io.prestosql.spi.plan.PlanNodeIdAllocator)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1 SetOperationNode (io.prestosql.spi.plan.SetOperationNode)1 Symbol (io.prestosql.spi.plan.Symbol)1 UnionNode (io.prestosql.spi.plan.UnionNode)1 CallExpression (io.prestosql.spi.relation.CallExpression)1 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)1