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);
}
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;
}
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);
}
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());
}
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);
}
Aggregations