Search in sources :

Example 1 with RowExpressionTreeRewriter

use of io.prestosql.expressions.RowExpressionTreeRewriter in project hetu-core by openlookeng.

the class CubeOptimizer method rewriteJoinNode.

private JoinNode rewriteJoinNode(JoinNode original, PlanNode rewrittenLeftChild, PlanNode rewrittenRightChild) {
    List<Symbol> joinOutputSymbols = new ArrayList<>(rewrittenLeftChild.getOutputSymbols());
    joinOutputSymbols.addAll(rewrittenRightChild.getOutputSymbols());
    List<JoinNode.EquiJoinClause> rewrittenJoinCriteria = new ArrayList<>();
    for (JoinNode.EquiJoinClause criteria : original.getCriteria()) {
        Symbol rewrittenLeft = optimizedPlanMappings.get(columnRewritesMap.get(criteria.getLeft().getName()));
        Symbol rewrittenRight = optimizedPlanMappings.get(columnRewritesMap.get(criteria.getRight().getName()));
        rewrittenJoinCriteria.add(new JoinNode.EquiJoinClause(rewrittenLeft, rewrittenRight));
    }
    Optional<Symbol> leftHashSymbol = original.getLeftHashSymbol().map(Symbol::getName).map(columnRewritesMap::get).map(optimizedPlanMappings::get);
    Optional<Symbol> rightHashSymbol = original.getRightHashSymbol().map(Symbol::getName).map(columnRewritesMap::get).map(optimizedPlanMappings::get);
    Optional<RowExpression> rewrittenJoinFilter = original.getFilter().map(rowExpression -> RowExpressionTreeRewriter.rewriteWith(new RowExpressionRewriter<Void>() {

        @Override
        public RowExpression rewriteVariableReference(VariableReferenceExpression variable, Void context, RowExpressionTreeRewriter<Void> treeRewriter) {
            return new VariableReferenceExpression(optimizedPlanMappings.get(columnRewritesMap.get(variable.getName())).getName(), variable.getType());
        }
    }, rowExpression));
    Map<String, Symbol> rewrittenDynamicFilters = original.getDynamicFilters().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> optimizedPlanMappings.get(columnRewritesMap.get(entry.getValue().getName()))));
    return new JoinNode(context.getIdAllocator().getNextId(), original.getType(), rewrittenLeftChild, rewrittenRightChild, rewrittenJoinCriteria, joinOutputSymbols, rewrittenJoinFilter, leftHashSymbol, rightHashSymbol, original.getDistributionType(), original.isSpillable(), rewrittenDynamicFilters);
}
Also used : LongSupplier(java.util.function.LongSupplier) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) PrestoWarning(io.prestosql.spi.PrestoWarning) TypeProvider(io.prestosql.sql.planner.TypeProvider) SqlParser(io.prestosql.sql.parser.SqlParser) ColumnNotFoundException(io.prestosql.spi.connector.ColumnNotFoundException) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Cast(io.prestosql.sql.tree.Cast) FilterNode(io.prestosql.spi.plan.FilterNode) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Type(io.prestosql.spi.type.Type) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) CubeFilter(io.hetu.core.spi.cube.CubeFilter) ENGLISH(java.util.Locale.ENGLISH) Identifier(io.prestosql.sql.tree.Identifier) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) CubeMetaStore(io.hetu.core.spi.cube.io.CubeMetaStore) PrestoException(io.prestosql.spi.PrestoException) SymbolsExtractor(io.prestosql.sql.planner.SymbolsExtractor) SUM(io.hetu.core.spi.cube.CubeAggregateFunction.SUM) ImmutableMap(com.google.common.collect.ImmutableMap) CubeAggregateFunction(io.hetu.core.spi.cube.CubeAggregateFunction) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) UUID(java.util.UUID) ProjectNode(io.prestosql.spi.plan.ProjectNode) Collectors(java.util.stream.Collectors) Metadata(io.prestosql.metadata.Metadata) String.format(java.lang.String.format) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Objects(java.util.Objects) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ReuseExchangeOperator(io.prestosql.spi.operator.ReuseExchangeOperator) List(java.util.List) ExpressionUtils(io.prestosql.sql.ExpressionUtils) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolReference(io.prestosql.sql.tree.SymbolReference) AggregationSignature(io.hetu.core.spi.cube.aggregator.AggregationSignature) Optional(java.util.Optional) NOT_SUPPORTED(io.prestosql.spi.StandardErrorCode.NOT_SUPPORTED) TypeSignature(io.prestosql.spi.type.TypeSignature) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) Iterables(com.google.common.collect.Iterables) COUNT(io.hetu.core.spi.cube.CubeAggregateFunction.COUNT) TableMetadata(io.prestosql.metadata.TableMetadata) Logger(io.airlift.log.Logger) TypeSignatureProvider(io.prestosql.sql.analyzer.TypeSignatureProvider) Literal(io.prestosql.sql.tree.Literal) HashMap(java.util.HashMap) TableHandle(io.prestosql.spi.metadata.TableHandle) ExpressionTreeRewriter(io.prestosql.sql.tree.ExpressionTreeRewriter) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Lists(com.google.common.collect.Lists) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) ImmutableList(com.google.common.collect.ImmutableList) ExpressionDomainTranslator(io.prestosql.sql.planner.ExpressionDomainTranslator) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RowExpressionRewriter(io.prestosql.expressions.RowExpressionRewriter) RowExpressionTreeRewriter(io.prestosql.expressions.RowExpressionTreeRewriter) ExpressionRewriter(io.prestosql.sql.tree.ExpressionRewriter) JoinNode(io.prestosql.spi.plan.JoinNode) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) EXPIRED_CUBE(io.prestosql.spi.connector.StandardWarningCode.EXPIRED_CUBE) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) SymbolAllocator(io.prestosql.spi.SymbolAllocator) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) CUBE_ERROR(io.prestosql.spi.StandardErrorCode.CUBE_ERROR) RowExpression(io.prestosql.spi.relation.RowExpression) CubeMetadata(io.hetu.core.spi.cube.CubeMetadata) Comparator(java.util.Comparator) Expression(io.prestosql.sql.tree.Expression) RowExpressionTreeRewriter(io.prestosql.expressions.RowExpressionTreeRewriter) Symbol(io.prestosql.spi.plan.Symbol) JoinNode(io.prestosql.spi.plan.JoinNode) ArrayList(java.util.ArrayList) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) RowExpression(io.prestosql.spi.relation.RowExpression) RowExpressionRewriter(io.prestosql.expressions.RowExpressionRewriter) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Logger (io.airlift.log.Logger)1 CubeAggregateFunction (io.hetu.core.spi.cube.CubeAggregateFunction)1 COUNT (io.hetu.core.spi.cube.CubeAggregateFunction.COUNT)1 SUM (io.hetu.core.spi.cube.CubeAggregateFunction.SUM)1 CubeFilter (io.hetu.core.spi.cube.CubeFilter)1 CubeMetadata (io.hetu.core.spi.cube.CubeMetadata)1 AggregationSignature (io.hetu.core.spi.cube.aggregator.AggregationSignature)1 CubeMetaStore (io.hetu.core.spi.cube.io.CubeMetaStore)1 Session (io.prestosql.Session)1 RowExpressionRewriter (io.prestosql.expressions.RowExpressionRewriter)1 RowExpressionTreeRewriter (io.prestosql.expressions.RowExpressionTreeRewriter)1 Metadata (io.prestosql.metadata.Metadata)1 TableMetadata (io.prestosql.metadata.TableMetadata)1 PrestoException (io.prestosql.spi.PrestoException)1 PrestoWarning (io.prestosql.spi.PrestoWarning)1 CUBE_ERROR (io.prestosql.spi.StandardErrorCode.CUBE_ERROR)1