use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.
the class TestPushProjectionThroughUnion method test.
@Test
public void test() {
FunctionResolution functionResolution = new FunctionResolution(tester().getMetadata().getFunctionAndTypeManager());
tester().assertThat(new PushProjectionThroughUnion()).on(p -> {
Symbol a = p.symbol("a");
Symbol b = p.symbol("b");
Symbol c = p.symbol("c");
Symbol cTimes3 = p.symbol("c_times_3");
return p.project(Assignments.of(cTimes3, call("c * 3", functionResolution.arithmeticFunction(MULTIPLY, BIGINT, BIGINT), BIGINT, p.variable("c"), constant(3L, BIGINT))), p.union(ImmutableListMultimap.<Symbol, Symbol>builder().put(c, a).put(c, b).build(), ImmutableList.of(p.values(a), p.values(b))));
}).matches(union(project(ImmutableMap.of("a_times_3", expression("a * 3")), values(ImmutableList.of("a"))), project(ImmutableMap.of("b_times_3", expression("b * 3")), values(ImmutableList.of("b")))).withNumberOfOutputColumns(1).withAlias("a_times_3").withAlias("b_times_3"));
}
use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.
the class FilterMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
FunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), functionResolution, metadata.getFunctionAndTypeManager());
FilterNode filterNode = (FilterNode) node;
if (isExpression(filterNode.getPredicate())) {
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
if (dynamicFilter.isPresent()) {
return new MatchResult(verifier.process(castToExpression(filterNode.getPredicate()), combineConjuncts(castToExpression(predicate), castToExpression(dynamicFilter.get()))));
}
DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
List<Expression> expressionList = extractResult.getStaticConjuncts().stream().map(OriginalExpressionUtils::castToExpression).collect(Collectors.toList());
return new MatchResult(verifier.process(combineConjuncts(expressionList), castToExpression(predicate)));
}
RowExpressionVerifier verifier = new RowExpressionVerifier(symbolAliases, metadata, session, filterNode.getOutputSymbols());
if (dynamicFilter.isPresent()) {
return new MatchResult(verifier.process(combineConjuncts(castToExpression(predicate), castToExpression(dynamicFilter.get())), filterNode.getPredicate()));
}
DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterNode.getPredicate());
return new MatchResult(verifier.process(castToExpression(predicate), logicalRowExpressions.combineConjuncts(extractResult.getStaticConjuncts())));
}
use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.
the class DynamicFilterMatcher method match.
public MatchResult match(FilterNode filterNode, Metadata metadata, Session session, SymbolAliases symbolAliases) {
checkState(this.filterNode == null, "filterNode must be null at this point");
this.filterNode = filterNode;
this.symbolAliases = symbolAliases;
FunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), functionResolution, metadata.getFunctionAndTypeManager());
boolean staticFilterMatches = expectedStaticFilter.map(filter -> {
RowExpressionVerifier verifier = new RowExpressionVerifier(symbolAliases, metadata, session, filterNode.getOutputSymbols());
RowExpression staticFilter = logicalRowExpressions.combineConjuncts(extractDynamicFilters(filterNode.getPredicate()).getStaticConjuncts());
return verifier.process(filter, staticFilter);
}).orElse(true);
return new MatchResult(match() && staticFilterMatches);
}
use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testAggregation.
@Test
public void testAggregation() {
PlanNode node = new AggregationNode(newId(), filter(baseTableScan, and(equals(AE, DE), equals(BE, EE), equals(CE, FE), lessThan(DE, bigintLiteral(10)), lessThan(CE, DE), greaterThan(AE, bigintLiteral(2)), equals(EE, FE))), ImmutableMap.of(C, new Aggregation(new CallExpression("test", new FunctionResolution(metadata.getFunctionAndTypeManager()).countFunction(), BIGINT, ImmutableList.of()), ImmutableList.of(), false, Optional.empty(), Optional.empty(), Optional.empty()), D, new Aggregation(new CallExpression("test", new FunctionResolution(metadata.getFunctionAndTypeManager()).countFunction(), BIGINT, ImmutableList.of()), ImmutableList.of(), false, Optional.empty(), Optional.empty(), Optional.empty())), singleGroupingSet(ImmutableList.of(A, B, C)), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Rewrite in terms of group by symbols
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(lessThan(AE, bigintLiteral(10)), lessThan(BE, AE), greaterThan(AE, bigintLiteral(2)), equals(BE, CE)));
}
use of io.prestosql.sql.relational.FunctionResolution in project hetu-core by openlookeng.
the class TestDynamicFilters method testExtractStaticFilters.
@Test
public void testExtractStaticFilters() {
LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
ConstantExpression staticExpression = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
VariableReferenceExpression variableExpression = new VariableReferenceExpression("col", VarcharType.VARCHAR);
FunctionHandle functionHandle = metadata.getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
RowExpression dynamicFilterExpression = call(DynamicFilters.Function.NAME, functionHandle, staticExpression.getType(), asList(staticExpression, variableExpression), Optional.empty());
RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, dynamicFilterExpression);
Optional<RowExpression> extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), staticExpression);
RowExpression combinedStaticExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression);
combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression, variableExpression, dynamicFilterExpression);
extractedExpression = DynamicFilters.extractStaticFilters(Optional.of(combinedExpression), metadata);
assertEquals(extractedExpression.get(), combinedStaticExpression);
}
Aggregations