Search in sources :

Example 11 with FunctionResolution

use of io.prestosql.sql.relational.FunctionResolution in project boostkit-bigdata by kunpengcompute.

the class TestHivePlanOptimizerProvider method testProvider.

@Test
public void testProvider() {
    RowExpressionService expressionService = new ConnectorRowExpressionService(new RowExpressionDomainTranslator(OFFLOAD_METADATA), new RowExpressionDeterminismEvaluator(OFFLOAD_METADATA));
    HiveTransactionManager transactionManager = simulationHiveTransactionManager();
    StandardFunctionResolution resolution = new FunctionResolution(OFFLOAD_METADATA.getFunctionAndTypeManager());
    HivePartitionManager partitionManager = new HivePartitionManager(OFFLOAD_METADATA.getFunctionAndTypeManager(), 1, false, 1);
    ScalarStatsCalculator scalarStatsCalculator = new ScalarStatsCalculator(OFFLOAD_METADATA);
    StatsNormalizer normalizer = new StatsNormalizer();
    FilterStatsCalculator statsCalculator = new FilterStatsCalculator(OFFLOAD_METADATA, scalarStatsCalculator, normalizer);
    FilterStatsCalculatorService calculatorService = new ConnectorFilterStatsCalculatorService(statsCalculator);
    HiveMetadataFactory hiveMetadataFactory = Mockito.mock(HiveMetadataFactory.class);
    HiveMetadata hiveMetadata = simulationHiveMetadata();
    Mockito.when(hiveMetadataFactory.get()).thenReturn(hiveMetadata);
    HivePlanOptimizerProvider hivePlanOptimizerProvider = new HivePlanOptimizerProvider(transactionManager, expressionService, resolution, partitionManager, OFFLOAD_METADATA.getFunctionAndTypeManager(), calculatorService, hiveMetadataFactory);
    assertEquals(hivePlanOptimizerProvider.getLogicalPlanOptimizers().size(), 3);
    assertEquals(hivePlanOptimizerProvider.getPhysicalPlanOptimizers().size(), 3);
}
Also used : ConnectorFilterStatsCalculatorService(io.prestosql.cost.ConnectorFilterStatsCalculatorService) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) StatsNormalizer(io.prestosql.cost.StatsNormalizer) HiveMetadataFactory(io.prestosql.plugin.hive.HiveMetadataFactory) ConnectorRowExpressionService(io.prestosql.sql.relational.ConnectorRowExpressionService) HivePartitionManager(io.prestosql.plugin.hive.HivePartitionManager) FilterStatsCalculatorService(io.prestosql.spi.plan.FilterStatsCalculatorService) ConnectorFilterStatsCalculatorService(io.prestosql.cost.ConnectorFilterStatsCalculatorService) ScalarStatsCalculator(io.prestosql.cost.ScalarStatsCalculator) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) FilterStatsCalculator(io.prestosql.cost.FilterStatsCalculator) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) ConnectorRowExpressionService(io.prestosql.sql.relational.ConnectorRowExpressionService) TestHivePushdownUtil.simulationHiveMetadata(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.simulationHiveMetadata) HiveMetadata(io.prestosql.plugin.hive.HiveMetadata) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) HiveTransactionManager(io.prestosql.plugin.hive.HiveTransactionManager) TestHivePushdownUtil.simulationHiveTransactionManager(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.simulationHiveTransactionManager) Test(org.testng.annotations.Test)

Example 12 with FunctionResolution

use of io.prestosql.sql.relational.FunctionResolution in project boostkit-bigdata by kunpengcompute.

the class TestHiveFilterPushdown method createOptimizer.

private static HiveFilterPushdown createOptimizer() {
    RowExpressionService expressionService = new ConnectorRowExpressionService(new RowExpressionDomainTranslator(OFFLOAD_METADATA), new RowExpressionDeterminismEvaluator(OFFLOAD_METADATA));
    HiveTransactionManager transactionManager = simulationHiveTransactionManager();
    StandardFunctionResolution resolution = new FunctionResolution(OFFLOAD_METADATA.getFunctionAndTypeManager());
    HivePartitionManager partitionManager = new HivePartitionManager(OFFLOAD_METADATA.getFunctionAndTypeManager(), 1, false, 1);
    ScalarStatsCalculator scalarStatsCalculator = new ScalarStatsCalculator(OFFLOAD_METADATA);
    StatsNormalizer normalizer = new StatsNormalizer();
    FilterStatsCalculator statsCalculator = new FilterStatsCalculator(OFFLOAD_METADATA, scalarStatsCalculator, normalizer);
    FilterStatsCalculatorService calculatorService = new ConnectorFilterStatsCalculatorService(statsCalculator);
    HiveFilterPushdown optimizer = new HiveFilterPushdown(transactionManager, expressionService, resolution, partitionManager, calculatorService, OFFLOAD_METADATA.getFunctionAndTypeManager());
    return optimizer;
}
Also used : ConnectorFilterStatsCalculatorService(io.prestosql.cost.ConnectorFilterStatsCalculatorService) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) StatsNormalizer(io.prestosql.cost.StatsNormalizer) ConnectorRowExpressionService(io.prestosql.sql.relational.ConnectorRowExpressionService) HivePartitionManager(io.prestosql.plugin.hive.HivePartitionManager) ConnectorFilterStatsCalculatorService(io.prestosql.cost.ConnectorFilterStatsCalculatorService) FilterStatsCalculatorService(io.prestosql.spi.plan.FilterStatsCalculatorService) ScalarStatsCalculator(io.prestosql.cost.ScalarStatsCalculator) RowExpressionDomainTranslator(io.prestosql.sql.relational.RowExpressionDomainTranslator) FilterStatsCalculator(io.prestosql.cost.FilterStatsCalculator) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) ConnectorRowExpressionService(io.prestosql.sql.relational.ConnectorRowExpressionService) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) HiveTransactionManager(io.prestosql.plugin.hive.HiveTransactionManager) TestHivePushdownUtil.simulationHiveTransactionManager(io.prestosql.plugin.hive.rule.TestHivePushdownUtil.simulationHiveTransactionManager)

Example 13 with FunctionResolution

use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.

the class TransformFilteringSemiJoinToInnerJoin method apply.

@Override
public Result apply(FilterNode filterNode, Captures captures, Context context) {
    SemiJoinNode semiJoin = captures.get(SEMI_JOIN);
    // Do no transform semi-join in context of DELETE
    if (PlanNodeSearcher.searchFrom(semiJoin.getSource(), context.getLookup()).where(node -> node instanceof TableScanNode && ((TableScanNode) node).isForDelete()).matches()) {
        return Result.empty();
    }
    Symbol semiJoinSymbol = semiJoin.getSemiJoinOutput();
    TypeProvider types = context.getSymbolAllocator().getTypes();
    Predicate<RowExpression> isSemiJoinSymbol = expression -> expression.equals(toVariableReference(semiJoinSymbol, types));
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    List<RowExpression> conjuncts = LogicalRowExpressions.extractConjuncts(filterNode.getPredicate());
    if (conjuncts.stream().noneMatch(isSemiJoinSymbol)) {
        return Result.empty();
    }
    RowExpression filteredPredicate = LogicalRowExpressions.and(conjuncts.stream().filter(expression -> !expression.equals(toVariableReference(semiJoinSymbol, types))).collect(toImmutableList()));
    RowExpression simplifiedPredicate = inlineVariables(variable -> {
        if (variable.equals(toVariableReference(semiJoinSymbol, types))) {
            return TRUE_CONSTANT;
        }
        return variable;
    }, filteredPredicate);
    Optional<RowExpression> joinFilter = simplifiedPredicate.equals(TRUE_CONSTANT) ? Optional.empty() : Optional.of(simplifiedPredicate);
    PlanNode filteringSourceDistinct = new AggregationNode(context.getIdAllocator().getNextId(), semiJoin.getFilteringSource(), ImmutableMap.of(), singleGroupingSet(ImmutableList.of(semiJoin.getFilteringSourceJoinSymbol())), ImmutableList.of(), SINGLE, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
    JoinNode innerJoin = new JoinNode(semiJoin.getId(), INNER, semiJoin.getSource(), filteringSourceDistinct, ImmutableList.of(new EquiJoinClause(semiJoin.getSourceJoinSymbol(), semiJoin.getFilteringSourceJoinSymbol())), semiJoin.getSource().getOutputSymbols(), joinFilter.isPresent() ? Optional.of(joinFilter.get()) : Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), // TODO: dynamic filter from SemiJoinNode
    ImmutableMap.of());
    ProjectNode project = new ProjectNode(context.getIdAllocator().getNextId(), innerJoin, Assignments.builder().putAll(AssignmentUtils.identityAsSymbolReferences(innerJoin.getOutputSymbols())).put(semiJoinSymbol, TRUE_CONSTANT).build());
    return Result.ofPlanNode(project);
}
Also used : TRUE_CONSTANT(io.prestosql.expressions.LogicalRowExpressions.TRUE_CONSTANT) Patterns.source(io.prestosql.sql.planner.plan.Patterns.source) EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) TypeProvider(io.prestosql.sql.planner.TypeProvider) Pattern(io.prestosql.matching.Pattern) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) AggregationNode(io.prestosql.spi.plan.AggregationNode) SystemSessionProperties.isRewriteFilteringSemiJoinToInnerJoin(io.prestosql.SystemSessionProperties.isRewriteFilteringSemiJoinToInnerJoin) Capture.newCapture(io.prestosql.matching.Capture.newCapture) ImmutableList(com.google.common.collect.ImmutableList) FilterNode(io.prestosql.spi.plan.FilterNode) SINGLE(io.prestosql.spi.plan.AggregationNode.Step.SINGLE) RowExpressionVariableInliner.inlineVariables(io.prestosql.sql.planner.RowExpressionVariableInliner.inlineVariables) Session(io.prestosql.Session) JoinNode(io.prestosql.spi.plan.JoinNode) AggregationNode.singleGroupingSet(io.prestosql.spi.plan.AggregationNode.singleGroupingSet) Symbol(io.prestosql.spi.plan.Symbol) AssignmentUtils(io.prestosql.sql.planner.plan.AssignmentUtils) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) Rule(io.prestosql.sql.planner.iterative.Rule) Predicate(java.util.function.Predicate) Patterns.filter(io.prestosql.sql.planner.plan.Patterns.filter) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TableScanNode(io.prestosql.spi.plan.TableScanNode) Patterns.semiJoin(io.prestosql.sql.planner.plan.Patterns.semiJoin) PlanNode(io.prestosql.spi.plan.PlanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode) VariableReferenceSymbolConverter.toVariableReference(io.prestosql.sql.planner.VariableReferenceSymbolConverter.toVariableReference) Metadata(io.prestosql.metadata.Metadata) Captures(io.prestosql.matching.Captures) List(java.util.List) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) PlanNodeSearcher(io.prestosql.sql.planner.optimizations.PlanNodeSearcher) Capture(io.prestosql.matching.Capture) RowExpression(io.prestosql.spi.relation.RowExpression) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) Symbol(io.prestosql.spi.plan.Symbol) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) JoinNode(io.prestosql.spi.plan.JoinNode) EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) TypeProvider(io.prestosql.sql.planner.TypeProvider) RowExpression(io.prestosql.spi.relation.RowExpression) AggregationNode(io.prestosql.spi.plan.AggregationNode) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) SemiJoinNode(io.prestosql.sql.planner.plan.SemiJoinNode) PlanNode(io.prestosql.spi.plan.PlanNode) TableScanNode(io.prestosql.spi.plan.TableScanNode) ProjectNode(io.prestosql.spi.plan.ProjectNode)

Example 14 with FunctionResolution

use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.

the class TestJoinEnumerator method testDoesNotCreateJoinWhenPartitionedOnCrossJoin.

@Test
public void testDoesNotCreateJoinWhenPartitionedOnCrossJoin() {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = new PlanBuilder(idAllocator, queryRunner.getMetadata());
    Symbol a1 = p.symbol("A1");
    Symbol b1 = p.symbol("B1");
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(queryRunner.getMetadata()), new FunctionResolution(queryRunner.getMetadata().getFunctionAndTypeManager()), queryRunner.getMetadata().getFunctionAndTypeManager());
    MultiJoinNode multiJoinNode = new MultiJoinNode(new LinkedHashSet<>(ImmutableList.of(p.values(a1), p.values(b1))), TRUE_CONSTANT, ImmutableList.of(a1, b1), logicalRowExpressions);
    JoinEnumerator joinEnumerator = new JoinEnumerator(new CostComparator(1, 1, 1), multiJoinNode.getFilter(), createContext(), queryRunner.getMetadata(), logicalRowExpressions);
    JoinEnumerationResult actual = joinEnumerator.createJoinAccordingToPartitioning(multiJoinNode.getSources(), multiJoinNode.getOutputSymbols(), ImmutableSet.of(0));
    assertFalse(actual.getPlanNode().isPresent());
    assertEquals(actual.getCost(), PlanCostEstimate.infinite());
}
Also used : CostComparator(io.prestosql.cost.CostComparator) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) JoinEnumerator(io.prestosql.sql.planner.iterative.rule.ReorderJoins.JoinEnumerator) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) Symbol(io.prestosql.spi.plan.Symbol) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) JoinEnumerationResult(io.prestosql.sql.planner.iterative.rule.ReorderJoins.JoinEnumerationResult) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) MultiJoinNode(io.prestosql.sql.planner.iterative.rule.ReorderJoins.MultiJoinNode) Test(org.testng.annotations.Test)

Example 15 with FunctionResolution

use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.

the class TestDynamicFilters method testExtractDynamicFiltersAsUnion.

@Test
public void testExtractDynamicFiltersAsUnion() {
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    ConstantExpression staticExpression1 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression1 = new VariableReferenceExpression("col1", VarcharType.VARCHAR);
    ConstantExpression staticExpression2 = new ConstantExpression(utf8Slice("id"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression2 = new VariableReferenceExpression("col2", VarcharType.VARCHAR);
    FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
    RowExpression dynamicFilterExpression1 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression1.getType(), asList(staticExpression1, variableExpression1), Optional.empty());
    RowExpression dynamicFilterExpression2 = call(DynamicFilters.Function.NAME, functionHandle, staticExpression2.getType(), asList(staticExpression2, variableExpression2), Optional.empty());
    List<DynamicFilters.Descriptor> dynamicFilter1 = new ArrayList<>();
    dynamicFilter1.add(new DynamicFilters.Descriptor("age", variableExpression1, Optional.empty()));
    List<DynamicFilters.Descriptor> dynamicFilter2 = new ArrayList<>();
    dynamicFilter2.add(new DynamicFilters.Descriptor("id", variableExpression2, Optional.empty()));
    List<List<DynamicFilters.Descriptor>> dynamicFilterUnion = new ArrayList<>();
    dynamicFilterUnion.add(dynamicFilter1);
    dynamicFilterUnion.add(dynamicFilter2);
    RowExpression combineDynamicFilterExpression = logicalRowExpressions.combineDisjuncts(asList(dynamicFilterExpression1, dynamicFilterExpression2));
    RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression1, combineDynamicFilterExpression);
    List<List<DynamicFilters.Descriptor>> extractedExpression = DynamicFilters.extractDynamicFiltersAsUnion(Optional.of(combinedExpression), metadata);
    assertEquals(extractedExpression, dynamicFilterUnion);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) ArrayList(java.util.ArrayList) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Arrays.asList(java.util.Arrays.asList) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

FunctionResolution (io.prestosql.sql.relational.FunctionResolution)21 RowExpressionDeterminismEvaluator (io.prestosql.sql.relational.RowExpressionDeterminismEvaluator)12 LogicalRowExpressions (io.prestosql.expressions.LogicalRowExpressions)10 RowExpression (io.prestosql.spi.relation.RowExpression)10 Test (org.testng.annotations.Test)10 Symbol (io.prestosql.spi.plan.Symbol)7 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)5 Metadata (io.prestosql.metadata.Metadata)4 StandardFunctionResolution (io.prestosql.spi.function.StandardFunctionResolution)4 FilterNode (io.prestosql.spi.plan.FilterNode)4 List (java.util.List)4 Session (io.prestosql.Session)3 ConnectorFilterStatsCalculatorService (io.prestosql.cost.ConnectorFilterStatsCalculatorService)3 FunctionHandle (io.prestosql.spi.function.FunctionHandle)3 AggregationNode (io.prestosql.spi.plan.AggregationNode)3 PlanNode (io.prestosql.spi.plan.PlanNode)3 RowExpressionDomainTranslator (io.prestosql.sql.relational.RowExpressionDomainTranslator)3