Search in sources :

Example 1 with LogicalRowExpressions

use of io.prestosql.expressions.LogicalRowExpressions 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 2 with LogicalRowExpressions

use of io.prestosql.expressions.LogicalRowExpressions 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 3 with LogicalRowExpressions

use of io.prestosql.expressions.LogicalRowExpressions 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)

Example 4 with LogicalRowExpressions

use of io.prestosql.expressions.LogicalRowExpressions in project hetu-core by openlookeng.

the class TestDynamicFilters method testExtractDynamicFilterExpression.

@Test
public void testExtractDynamicFilterExpression() {
    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("col", VarcharType.VARCHAR);
    ConstantExpression staticExpression2 = new ConstantExpression(utf8Slice("age"), VarcharType.VARCHAR);
    VariableReferenceExpression variableExpression2 = new VariableReferenceExpression("col", 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());
    RowExpression combineDynamicFilterExpression = logicalRowExpressions.combineDisjuncts(asList(dynamicFilterExpression1, dynamicFilterExpression2));
    RowExpression combinedExpression = logicalRowExpressions.combineConjuncts(staticExpression1, combineDynamicFilterExpression);
    RowExpression extractedExpression = DynamicFilters.extractDynamicFilterExpression(combinedExpression, metadata);
    assertEquals(extractedExpression, combineDynamicFilterExpression);
}
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)

Example 5 with LogicalRowExpressions

use of io.prestosql.expressions.LogicalRowExpressions in project hetu-core by openlookeng.

the class DynamicFilters method extractStaticFilters.

public static Optional<RowExpression> extractStaticFilters(Optional<RowExpression> expression, Metadata metadata) {
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    if (expression.isPresent()) {
        List<RowExpression> filters = extractConjuncts(expression.get());
        RowExpression staticFilters = TRUE_CONSTANT;
        for (RowExpression filter : filters) {
            List<RowExpression> predicates = extractAllPredicates(filter);
            for (RowExpression predicate : predicates) {
                if (!getDescriptor(predicate).isPresent()) {
                    staticFilters = logicalRowExpressions.combineConjuncts(staticFilters, filter);
                }
            }
        }
        return staticFilters.equals(TRUE_CONSTANT) ? Optional.empty() : Optional.of(staticFilters);
    } else {
        return Optional.empty();
    }
}
Also used : RowExpressionDeterminismEvaluator(io.prestosql.sql.relational.RowExpressionDeterminismEvaluator) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) RowExpression(io.prestosql.spi.relation.RowExpression) FunctionResolution(io.prestosql.sql.relational.FunctionResolution)

Aggregations

LogicalRowExpressions (io.prestosql.expressions.LogicalRowExpressions)11 FunctionResolution (io.prestosql.sql.relational.FunctionResolution)11 RowExpressionDeterminismEvaluator (io.prestosql.sql.relational.RowExpressionDeterminismEvaluator)11 RowExpression (io.prestosql.spi.relation.RowExpression)9 FilterNode (io.prestosql.spi.plan.FilterNode)5 Symbol (io.prestosql.spi.plan.Symbol)5 List (java.util.List)5 ImmutableList (com.google.common.collect.ImmutableList)4 Session (io.prestosql.Session)4 Metadata (io.prestosql.metadata.Metadata)4 PlanNode (io.prestosql.spi.plan.PlanNode)4 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)4 Optional (java.util.Optional)4 Test (org.testng.annotations.Test)4 Capture (io.prestosql.matching.Capture)3 Capture.newCapture (io.prestosql.matching.Capture.newCapture)3 Captures (io.prestosql.matching.Captures)3 Pattern (io.prestosql.matching.Pattern)3 FunctionHandle (io.prestosql.spi.function.FunctionHandle)3 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)3