Search in sources :

Example 1 with FunctionResolution

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"));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) MULTIPLY(io.prestosql.spi.function.OperatorType.MULTIPLY) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) PlanMatchPattern.project(io.prestosql.sql.planner.assertions.PlanMatchPattern.project) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.prestosql.spi.plan.Assignments) PlanMatchPattern.union(io.prestosql.sql.planner.assertions.PlanMatchPattern.union) Test(org.testng.annotations.Test) PlanMatchPattern.values(io.prestosql.sql.planner.assertions.PlanMatchPattern.values) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) ImmutableList(com.google.common.collect.ImmutableList) LongLiteral(io.prestosql.sql.tree.LongLiteral) Expressions.call(io.prestosql.sql.relational.Expressions.call) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) PlanMatchPattern.expression(io.prestosql.sql.planner.assertions.PlanMatchPattern.expression) OriginalExpressionUtils(io.prestosql.sql.relational.OriginalExpressionUtils) Symbol(io.prestosql.spi.plan.Symbol) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) BaseRuleTest(io.prestosql.sql.planner.iterative.rule.test.BaseRuleTest) Test(org.testng.annotations.Test)

Example 2 with FunctionResolution

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())));
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) DynamicFilters.extractDynamicFilters(io.prestosql.sql.DynamicFilters.extractDynamicFilters) DynamicFilters(io.prestosql.sql.DynamicFilters) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) RowExpression(io.prestosql.spi.relation.RowExpression) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) Expression(io.prestosql.sql.tree.Expression) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) FilterNode(io.prestosql.spi.plan.FilterNode) FunctionResolution(io.prestosql.sql.relational.FunctionResolution)

Example 3 with FunctionResolution

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);
}
Also used : DynamicFilters.extractDynamicFilters(io.prestosql.sql.DynamicFilters.extractDynamicFilters) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) HashMap(java.util.HashMap) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) DynamicFilters(io.prestosql.sql.DynamicFilters) PlanNode(io.prestosql.spi.plan.PlanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) Joiner(com.google.common.base.Joiner) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution)

Example 4 with FunctionResolution

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)));
}
Also used : AggregationNode.globalAggregation(io.prestosql.spi.plan.AggregationNode.globalAggregation) Aggregation(io.prestosql.spi.plan.AggregationNode.Aggregation) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) RowExpression(io.prestosql.spi.relation.RowExpression) Expression(io.prestosql.sql.tree.Expression) AggregationNode(io.prestosql.spi.plan.AggregationNode) CallExpression(io.prestosql.spi.relation.CallExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) Test(org.testng.annotations.Test)

Example 5 with FunctionResolution

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);
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) FunctionHandle(io.prestosql.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

FunctionResolution (io.prestosql.sql.relational.FunctionResolution)18 LogicalRowExpressions (io.prestosql.expressions.LogicalRowExpressions)10 RowExpression (io.prestosql.spi.relation.RowExpression)10 RowExpressionDeterminismEvaluator (io.prestosql.sql.relational.RowExpressionDeterminismEvaluator)10 Test (org.testng.annotations.Test)9 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 FilterNode (io.prestosql.spi.plan.FilterNode)4 List (java.util.List)4 Session (io.prestosql.Session)3 FunctionHandle (io.prestosql.spi.function.FunctionHandle)3 AggregationNode (io.prestosql.spi.plan.AggregationNode)3 PlanNode (io.prestosql.spi.plan.PlanNode)3 Expression (io.prestosql.sql.tree.Expression)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 TRUE_CONSTANT (io.prestosql.expressions.LogicalRowExpressions.TRUE_CONSTANT)2