Search in sources :

Example 21 with Assignments

use of io.prestosql.spi.plan.Assignments in project boostkit-bigdata by kunpengcompute.

the class TestHivePartialAggregationPushdown method testPartialAggregationAndProjectPushdown.

@Test
public void testPartialAggregationAndProjectPushdown() {
    // select count(x + 5) from table group by x
    TableScanNode tableScanNode = buildTableScanNode(COLUMN_INT);
    CallExpression callExpression = createOperationExpression(OperatorType.ADD, new VariableReferenceExpression(COLUMN_INT.getName(), INTEGER), new ConstantExpression(5, INTEGER));
    List<Symbol> symbols = ImmutableList.of(new Symbol(COLUMN_INT.getName()));
    List<RowExpression> rowExpressions = ImmutableList.of(callExpression);
    ProjectNode projectNode = buildProjectNode(tableScanNode, symbols, rowExpressions);
    AggregationNode aggregationNode = buildCountAggregationNode(projectNode);
    PlanNode output = AGGREGATION_OPTIMIZER.optimize(aggregationNode, OFFLOAD_SESSION, COLUMN_TYPE_MAP, SYMBOL_ALLOCATOR, ID_ALLOCATOR);
    Assignments assignmentsExpected = buildAssignments(symbols, rowExpressions);
    matchProjection(output, assignmentsExpected.getMap());
}
Also used : PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) TestHivePushdownUtil.buildTableScanNode(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildTableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Symbol(io.prestosql.spi.plan.Symbol) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) Assignments(io.prestosql.spi.plan.Assignments) TestHivePushdownUtil.buildAssignments(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildAssignments) RowExpression(io.prestosql.spi.relation.RowExpression) TestHivePushdownUtil.buildProjectNode(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildProjectNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) TestHivePushdownUtil.buildAggregationNode(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.buildAggregationNode) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 22 with Assignments

use of io.prestosql.spi.plan.Assignments in project hetu-core by openlookeng.

the class TestBaseJdbcPushDownBase method tableScan.

protected TableScanNode tableScan(PlanBuilder planBuilder, JdbcTableHandle connectorTableHandle, JdbcColumnHandle... columnHandles) {
    List<Symbol> symbols = Arrays.stream(columnHandles).map(column -> new Symbol(column.getColumnName().toLowerCase(Locale.ENGLISH))).collect(toImmutableList());
    ImmutableMap.Builder<Symbol, ColumnHandle> assignments = ImmutableMap.builder();
    for (int i = 0; i < symbols.size(); i++) {
        assignments.put(symbols.get(i), columnHandles[i]);
    }
    TableHandle tableHandle = new TableHandle(catalogName, connectorTableHandle, TestingTransactionHandle.create(), Optional.empty());
    return planBuilder.tableScan(tableHandle, symbols, assignments.build());
}
Also used : Arrays(java.util.Arrays) TestingSession(io.prestosql.testing.TestingSession) SystemSessionProperties(io.prestosql.SystemSessionProperties) TypeProvider(io.prestosql.sql.planner.TypeProvider) DecimalType(io.prestosql.spi.type.DecimalType) SqlParser(io.prestosql.sql.parser.SqlParser) DeterminismEvaluator(io.prestosql.spi.relation.DeterminismEvaluator) ExpressionAnalyzer(io.prestosql.sql.analyzer.ExpressionAnalyzer) HetuConfig(io.prestosql.utils.HetuConfig) WarningCollector(io.prestosql.execution.warnings.WarningCollector) JdbcTypeHandle(io.prestosql.plugin.jdbc.JdbcTypeHandle) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) FilterNode(io.prestosql.spi.plan.FilterNode) Collectors.toMap(java.util.stream.Collectors.toMap) ParametricType(io.prestosql.spi.type.ParametricType) Locale(java.util.Locale) JDBC_BIGINT(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_BIGINT) OperatorType(io.prestosql.spi.function.OperatorType) Map(java.util.Map) FunctionMetadataManager(io.prestosql.spi.function.FunctionMetadataManager) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) SqlToRowExpressionTranslator(io.prestosql.sql.relational.SqlToRowExpressionTranslator) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ImmutableMap(com.google.common.collect.ImmutableMap) RealType(io.prestosql.spi.type.RealType) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) CatalogName(io.prestosql.spi.connector.CatalogName) DriverConnectionFactory(io.prestosql.plugin.jdbc.DriverConnectionFactory) TableScanNode(io.prestosql.spi.plan.TableScanNode) PlanNode(io.prestosql.spi.plan.PlanNode) Driver(org.h2.Driver) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) ProjectNode(io.prestosql.spi.plan.ProjectNode) Metadata(io.prestosql.metadata.Metadata) MetadataManager(io.prestosql.metadata.MetadataManager) String.format(java.lang.String.format) NodeRef(io.prestosql.sql.tree.NodeRef) TimestampType(io.prestosql.spi.type.TimestampType) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) List(java.util.List) HYPER_LOG_LOG(io.prestosql.spi.type.HyperLogLogType.HYPER_LOG_LOG) ExpressionUtils(io.prestosql.sql.ExpressionUtils) TestingTransactionHandle(io.prestosql.testing.TestingTransactionHandle) SessionPropertyManager(io.prestosql.metadata.SessionPropertyManager) FULL_PUSHDOWN(io.prestosql.plugin.jdbc.optimization.JdbcPushDownModule.FULL_PUSHDOWN) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) TypeSignature(io.prestosql.spi.type.TypeSignature) JdbcTableHandle(io.prestosql.plugin.jdbc.JdbcTableHandle) Types(java.sql.Types) BigintType(io.prestosql.spi.type.BigintType) JdbcColumnHandle(io.prestosql.plugin.jdbc.JdbcColumnHandle) MethodHandle(java.lang.invoke.MethodHandle) FunctionKind(io.prestosql.spi.function.FunctionKind) SESSION(io.prestosql.testing.TestingConnectorSession.SESSION) TypeSignatureParameter(io.prestosql.spi.type.TypeSignatureParameter) HashMap(java.util.HashMap) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) ID(io.prestosql.spi.type.TestingIdType.ID) TypeNotFoundException(io.prestosql.spi.type.TypeNotFoundException) TableHandle(io.prestosql.spi.metadata.TableHandle) JDBC_VARCHAR(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_VARCHAR) QueryGenerator(io.prestosql.spi.sql.QueryGenerator) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) DoubleType(io.prestosql.spi.type.DoubleType) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) DATE(io.prestosql.spi.type.DateType.DATE) ParsingOptions(io.prestosql.sql.parser.ParsingOptions) Symbol(io.prestosql.spi.plan.Symbol) JDBC_INTEGER(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_INTEGER) Properties(java.util.Properties) Assignments(io.prestosql.spi.plan.Assignments) IntegerType(io.prestosql.spi.type.IntegerType) BaseJdbcConfig(io.prestosql.plugin.jdbc.BaseJdbcConfig) TypeManager(io.prestosql.spi.type.TypeManager) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) BaseJdbcClient(io.prestosql.plugin.jdbc.BaseJdbcClient) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) JDBC_REAL(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_REAL) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) LimitNode(io.prestosql.spi.plan.LimitNode) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) RowExpression(io.prestosql.spi.relation.RowExpression) JdbcClient(io.prestosql.plugin.jdbc.JdbcClient) JDBC_BOOLEAN(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_BOOLEAN) JDBC_DOUBLE(io.prestosql.plugin.jdbc.TestingJdbcTypeHandle.JDBC_DOUBLE) BooleanType(io.prestosql.spi.type.BooleanType) VarcharType(io.prestosql.spi.type.VarcharType) Expression(io.prestosql.sql.tree.Expression) JdbcColumnHandle(io.prestosql.plugin.jdbc.JdbcColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Symbol(io.prestosql.spi.plan.Symbol) JdbcTableHandle(io.prestosql.plugin.jdbc.JdbcTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with Assignments

use of io.prestosql.spi.plan.Assignments in project hetu-core by openlookeng.

the class TransformCorrelatedSingleRowSubqueryToProject method apply.

@Override
public Result apply(LateralJoinNode parent, Captures captures, Context context) {
    List<ValuesNode> values = searchFrom(parent.getSubquery(), context.getLookup()).recurseOnlyWhen(ProjectNode.class::isInstance).where(ValuesNode.class::isInstance).findAll();
    if (values.size() != 1 || !isSingleRowValuesWithNoColumns(values.get(0))) {
        return Result.empty();
    }
    List<ProjectNode> subqueryProjections = searchFrom(parent.getSubquery(), context.getLookup()).where(node -> node instanceof ProjectNode && !node.getOutputSymbols().equals(parent.getCorrelation())).findAll();
    if (subqueryProjections.size() == 0) {
        return Result.ofPlanNode(parent.getInput());
    }
    if (subqueryProjections.size() == 1) {
        Assignments assignments = Assignments.builder().putAll(AssignmentUtils.identityAsSymbolReferences(parent.getInput().getOutputSymbols())).putAll(subqueryProjections.get(0).getAssignments()).build();
        return Result.ofPlanNode(projectNode(parent.getInput(), assignments, context));
    }
    return Result.empty();
}
Also used : AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) Patterns.lateralJoin(io.prestosql.sql.planner.plan.Patterns.lateralJoin) LateralJoin.filter(io.prestosql.sql.planner.plan.Patterns.LateralJoin.filter) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) Pattern(io.prestosql.matching.Pattern) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) TRUE_LITERAL(io.prestosql.sql.tree.BooleanLiteral.TRUE_LITERAL) PlanNodeSearcher.searchFrom(io.prestosql.sql.planner.optimizations.PlanNodeSearcher.searchFrom) Captures(io.prestosql.matching.Captures) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) ValuesNode(io.prestosql.spi.plan.ValuesNode) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 24 with Assignments

use of io.prestosql.spi.plan.Assignments in project hetu-core by openlookeng.

the class TransformExistsApplyToLateralNode method rewriteToNonDefaultAggregation.

private Optional<PlanNode> rewriteToNonDefaultAggregation(ApplyNode applyNode, Context context) {
    checkState(applyNode.getSubquery().getOutputSymbols().isEmpty(), "Expected subquery output symbols to be pruned");
    Symbol exists = getOnlyElement(applyNode.getSubqueryAssignments().getSymbols());
    Symbol subqueryTrue = context.getSymbolAllocator().newSymbol("subqueryTrue", BOOLEAN);
    Assignments.Builder assignments = Assignments.builder();
    assignments.putAll(AssignmentUtils.identityAsSymbolReferences(applyNode.getInput().getOutputSymbols()));
    assignments.put(exists, castToRowExpression(new CoalesceExpression(ImmutableList.of(toSymbolReference(subqueryTrue), BooleanLiteral.FALSE_LITERAL))));
    PlanNode subquery = new ProjectNode(context.getIdAllocator().getNextId(), new LimitNode(context.getIdAllocator().getNextId(), applyNode.getSubquery(), 1L, false), Assignments.of(subqueryTrue, castToRowExpression(TRUE_LITERAL)));
    PlanNodeDecorrelator decorrelator = new PlanNodeDecorrelator(context.getIdAllocator(), context.getLookup());
    if (!decorrelator.decorrelateFilters(subquery, applyNode.getCorrelation()).isPresent()) {
        return Optional.empty();
    }
    return Optional.of(new ProjectNode(context.getIdAllocator().getNextId(), new LateralJoinNode(applyNode.getId(), applyNode.getInput(), subquery, applyNode.getCorrelation(), LEFT, TRUE_LITERAL, applyNode.getOriginSubquery()), assignments.build()));
}
Also used : PlanNodeDecorrelator(io.prestosql.sql.planner.optimizations.PlanNodeDecorrelator) PlanNode(io.prestosql.spi.plan.PlanNode) LateralJoinNode(io.prestosql.sql.planner.plan.LateralJoinNode) LimitNode(io.prestosql.spi.plan.LimitNode) Symbol(io.prestosql.spi.plan.Symbol) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression)

Example 25 with Assignments

use of io.prestosql.spi.plan.Assignments in project hetu-core by openlookeng.

the class PushPartialAggregationThroughExchange method pushPartial.

private PlanNode pushPartial(AggregationNode aggregation, ExchangeNode exchange, Context context) {
    List<PlanNode> partials = new ArrayList<>();
    for (int i = 0; i < exchange.getSources().size(); i++) {
        PlanNode source = exchange.getSources().get(i);
        SymbolMapper.Builder mappingsBuilder = SymbolMapper.builder();
        for (int outputIndex = 0; outputIndex < exchange.getOutputSymbols().size(); outputIndex++) {
            Symbol output = exchange.getOutputSymbols().get(outputIndex);
            Symbol input = exchange.getInputs().get(i).get(outputIndex);
            if (!output.equals(input)) {
                mappingsBuilder.put(output, input);
            }
        }
        SymbolMapper symbolMapper = mappingsBuilder.build();
        if (symbolMapper.getTypes() == null) {
            symbolMapper.setTypes(context.getSymbolAllocator().getTypes());
        }
        AggregationNode mappedPartial = symbolMapper.map(aggregation, source, context.getIdAllocator());
        Assignments.Builder assignments = Assignments.builder();
        for (Symbol output : aggregation.getOutputSymbols()) {
            Symbol input = symbolMapper.map(output);
            assignments.put(output, VariableReferenceSymbolConverter.toVariableReference(input, context.getSymbolAllocator().getTypes()));
        }
        partials.add(new ProjectNode(context.getIdAllocator().getNextId(), mappedPartial, assignments.build()));
    }
    for (PlanNode node : partials) {
        verify(aggregation.getOutputSymbols().equals(node.getOutputSymbols()));
    }
    // Since this exchange source is now guaranteed to have the same symbols as the inputs to the the partial
    // aggregation, we don't need to rewrite symbols in the partitioning function
    PartitioningScheme partitioning = new PartitioningScheme(exchange.getPartitioningScheme().getPartitioning(), aggregation.getOutputSymbols(), exchange.getPartitioningScheme().getHashColumn(), exchange.getPartitioningScheme().isReplicateNullsAndAny(), exchange.getPartitioningScheme().getBucketToPartition());
    return new ExchangeNode(context.getIdAllocator().getNextId(), exchange.getType(), exchange.getScope(), partitioning, partials, ImmutableList.copyOf(Collections.nCopies(partials.size(), aggregation.getOutputSymbols())), Optional.empty(), aggregation.getAggregationType());
}
Also used : SymbolMapper(io.prestosql.sql.planner.optimizations.SymbolMapper) ExchangeNode(io.prestosql.sql.planner.plan.ExchangeNode) Symbol(io.prestosql.spi.plan.Symbol) PartitioningScheme(io.prestosql.sql.planner.PartitioningScheme) ArrayList(java.util.ArrayList) Assignments(io.prestosql.spi.plan.Assignments) AggregationNode(io.prestosql.spi.plan.AggregationNode) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Aggregations

Assignments (io.prestosql.spi.plan.Assignments)34 ProjectNode (io.prestosql.spi.plan.ProjectNode)31 Symbol (io.prestosql.spi.plan.Symbol)25 PlanNode (io.prestosql.spi.plan.PlanNode)20 Expression (io.prestosql.sql.tree.Expression)18 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)16 Cast (io.prestosql.sql.tree.Cast)15 RowExpression (io.prestosql.spi.relation.RowExpression)14 ImmutableList (com.google.common.collect.ImmutableList)13 Type (io.prestosql.spi.type.Type)13 HashMap (java.util.HashMap)13 Map (java.util.Map)13 AggregationNode (io.prestosql.spi.plan.AggregationNode)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 TableScanNode (io.prestosql.spi.plan.TableScanNode)11 List (java.util.List)11 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)10 Metadata (io.prestosql.metadata.Metadata)10 CallExpression (io.prestosql.spi.relation.CallExpression)10 ArrayList (java.util.ArrayList)10