Search in sources :

Example 96 with Expression

use of io.trino.sql.tree.Expression in project trino by trinodb.

the class TestDynamicFilterService method testShortCircuitOnAllTupleDomain.

@Test
public void testShortCircuitOnAllTupleDomain() {
    DynamicFilterService dynamicFilterService = createDynamicFilterService();
    DynamicFilterId filterId1 = new DynamicFilterId("df1");
    SymbolAllocator symbolAllocator = new SymbolAllocator();
    Symbol symbol1 = symbolAllocator.newSymbol("DF_SYMBOL1", INTEGER);
    Expression df1 = symbol1.toSymbolReference();
    QueryId queryId = new QueryId("query");
    StageId stageId1 = new StageId(queryId, 1);
    dynamicFilterService.registerQuery(queryId, session, ImmutableSet.of(filterId1), ImmutableSet.of(filterId1), ImmutableSet.of());
    dynamicFilterService.stageCannotScheduleMoreTasks(stageId1, 0, 2);
    DynamicFilter dynamicFilter = dynamicFilterService.createDynamicFilter(queryId, ImmutableList.of(new DynamicFilters.Descriptor(filterId1, df1)), ImmutableMap.of(symbol1, new TestingColumnHandle("probeColumnA")), symbolAllocator.getTypes());
    // dynamic filter is initially blocked
    assertTrue(dynamicFilter.getCurrentPredicate().isAll());
    assertFalse(dynamicFilter.isComplete());
    assertFalse(dynamicFilter.isBlocked().isDone());
    dynamicFilterService.addTaskDynamicFilters(new TaskId(stageId1, 1, 0), ImmutableMap.of(filterId1, Domain.all(INTEGER)));
    // dynamic filter should be unblocked and completed
    assertTrue(dynamicFilter.getCurrentPredicate().isAll());
    assertTrue(dynamicFilter.isComplete());
    assertTrue(dynamicFilter.isBlocked().isDone());
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) TestingColumnHandle(io.trino.spi.connector.TestingColumnHandle) TaskId(io.trino.execution.TaskId) DynamicFilters.createDynamicFilterExpression(io.trino.sql.DynamicFilters.createDynamicFilterExpression) Expression(io.trino.sql.tree.Expression) DynamicFilter(io.trino.spi.connector.DynamicFilter) Symbol(io.trino.sql.planner.Symbol) QueryId(io.trino.spi.QueryId) StageId(io.trino.execution.StageId) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) Test(org.testng.annotations.Test)

Example 97 with Expression

use of io.trino.sql.tree.Expression in project trino by trinodb.

the class ExpressionVerifier method visitInPredicate.

@Override
protected Boolean visitInPredicate(InPredicate actual, Node expectedExpression) {
    if (!(expectedExpression instanceof InPredicate)) {
        return false;
    }
    InPredicate expected = (InPredicate) expectedExpression;
    if (actual.getValueList() instanceof InListExpression || !(expected.getValueList() instanceof InListExpression)) {
        return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), expected.getValueList());
    }
    /*
         * In some cases, actual.getValueList() and expected.getValueList() might be of different types,
         * although they originated from identical single-element InListExpression.
         *
         * This happens because actual passes through the analyzer, planner, and possibly optimizers,
         * one of which sometimes takes the liberty of unpacking the InListExpression.
         *
         * Since the expected value doesn't go through all of that, we have to deal with the case
         * of the actual value being unpacked, but the expected value being an InListExpression.
         *
         * If the expected value is a value list, but the actual is e.g. a SymbolReference,
         * we need to unpack the value from the list to enable comparison: so that when we hit
         * visitSymbolReference, the expected.toString() call returns something that the symbolAliases
         * actually contains.
         * For example, InListExpression.toString returns "(onlyitem)" rather than "onlyitem".
         */
    List<Expression> values = ((InListExpression) expected.getValueList()).getValues();
    checkState(values.size() == 1, "Multiple expressions in expected value list %s, but actual value is not a list", values, actual.getValue());
    Expression onlyExpectedExpression = values.get(0);
    return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), onlyExpectedExpression);
}
Also used : SimpleCaseExpression(io.trino.sql.tree.SimpleCaseExpression) LambdaExpression(io.trino.sql.tree.LambdaExpression) SubscriptExpression(io.trino.sql.tree.SubscriptExpression) SearchedCaseExpression(io.trino.sql.tree.SearchedCaseExpression) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) NotExpression(io.trino.sql.tree.NotExpression) TryExpression(io.trino.sql.tree.TryExpression) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) IfExpression(io.trino.sql.tree.IfExpression) QuantifiedComparisonExpression(io.trino.sql.tree.QuantifiedComparisonExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) Expression(io.trino.sql.tree.Expression) InListExpression(io.trino.sql.tree.InListExpression) InListExpression(io.trino.sql.tree.InListExpression) InPredicate(io.trino.sql.tree.InPredicate)

Example 98 with Expression

use of io.trino.sql.tree.Expression in project trino by trinodb.

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());
    FilterNode filterNode = (FilterNode) node;
    Expression filterPredicate = filterNode.getPredicate();
    ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
    if (dynamicFilter.isPresent()) {
        return new MatchResult(verifier.process(filterPredicate, combineConjuncts(metadata, predicate, dynamicFilter.get())));
    }
    DynamicFilters.ExtractResult extractResult = extractDynamicFilters(filterPredicate);
    return new MatchResult(verifier.process(combineConjuncts(metadata, extractResult.getStaticConjuncts()), predicate));
}
Also used : DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) DynamicFilters(io.trino.sql.DynamicFilters) Expression(io.trino.sql.tree.Expression) FilterNode(io.trino.sql.planner.plan.FilterNode)

Example 99 with Expression

use of io.trino.sql.tree.Expression in project trino by trinodb.

the class FunctionCallProvider method getExpectedValue.

@Override
public FunctionCall getExpectedValue(SymbolAliases aliases) {
    List<Expression> symbolReferences = toSymbolReferences(args, aliases);
    if (isWindowFunction) {
        verify(!distinct, "window does not support distinct");
        verify(orderBy.isEmpty(), "window does not support order by");
        return new ExpectedWindowFunctionCall(symbolReferences);
    }
    Optional<OrderBy> orderByClause = Optional.empty();
    if (!orderBy.isEmpty()) {
        orderByClause = Optional.of(new OrderBy(orderBy.stream().map(item -> new SortItem(Symbol.from(aliases.get(item.getField())).toSymbolReference(), item.getOrdering(), item.getNullOrdering())).collect(Collectors.toList())));
    }
    return new FunctionCall(Optional.empty(), name, Optional.empty(), filter.map(symbol -> symbol.toSymbol(aliases).toSymbolReference()), orderByClause, distinct, Optional.empty(), Optional.empty(), symbolReferences);
}
Also used : OrderBy(io.trino.sql.tree.OrderBy) Symbol(io.trino.sql.planner.Symbol) SortItem(io.trino.sql.tree.SortItem) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) QualifiedName(io.trino.sql.tree.QualifiedName) Objects(java.util.Objects) PlanMatchPattern.toSymbolReferences(io.trino.sql.planner.assertions.PlanMatchPattern.toSymbolReferences) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) WindowFrame(io.trino.sql.tree.WindowFrame) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) FunctionCall(io.trino.sql.tree.FunctionCall) OrderBy(io.trino.sql.tree.OrderBy) Joiner(com.google.common.base.Joiner) WindowSpecification(io.trino.sql.tree.WindowSpecification) SortItem(io.trino.sql.tree.SortItem) Expression(io.trino.sql.tree.Expression) FunctionCall(io.trino.sql.tree.FunctionCall)

Example 100 with Expression

use of io.trino.sql.tree.Expression in project trino by trinodb.

the class PatternRecognitionExpressionRewriter method rewrite.

public static ExpressionAndValuePointers rewrite(Expression definition, Map<IrLabel, Set<IrLabel>> subsets) {
    Expression expression = rewriteIdentifiers(definition);
    Map<Symbol, Type> types = extractExpressions(ImmutableList.of(expression), SymbolReference.class).stream().collect(toImmutableMap(Symbol::from, reference -> BIGINT));
    return LogicalIndexExtractor.rewrite(expression, subsets, new SymbolAllocator(types), createTestMetadataManager());
}
Also used : ExpressionTreeUtils.extractExpressions(io.trino.sql.analyzer.ExpressionTreeUtils.extractExpressions) ParsingOptions(io.trino.sql.parser.ParsingOptions) SymbolAllocator(io.trino.sql.planner.SymbolAllocator) Type(io.trino.spi.type.Type) LambdaExpression(io.trino.sql.tree.LambdaExpression) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RowDataType(io.trino.sql.tree.RowDataType) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) GenericDataType(io.trino.sql.tree.GenericDataType) SqlParser(io.trino.sql.parser.SqlParser) ExpressionRewriter(io.trino.sql.tree.ExpressionRewriter) ExpressionAndValuePointers(io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers) Identifier(io.trino.sql.tree.Identifier) Symbol(io.trino.sql.planner.Symbol) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) LabelDereference(io.trino.sql.tree.LabelDereference) ExpressionTreeRewriter(io.trino.sql.tree.ExpressionTreeRewriter) LogicalIndexExtractor(io.trino.sql.planner.rowpattern.LogicalIndexExtractor) Set(java.util.Set) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) BIGINT(io.trino.spi.type.BigintType.BIGINT) SymbolReference(io.trino.sql.tree.SymbolReference) MetadataManager.createTestMetadataManager(io.trino.metadata.MetadataManager.createTestMetadataManager) Expression(io.trino.sql.tree.Expression) SymbolAllocator(io.trino.sql.planner.SymbolAllocator) Type(io.trino.spi.type.Type) RowDataType(io.trino.sql.tree.RowDataType) GenericDataType(io.trino.sql.tree.GenericDataType) LambdaExpression(io.trino.sql.tree.LambdaExpression) DereferenceExpression(io.trino.sql.tree.DereferenceExpression) Expression(io.trino.sql.tree.Expression) Symbol(io.trino.sql.planner.Symbol)

Aggregations

Expression (io.trino.sql.tree.Expression)257 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)111 ImmutableList (com.google.common.collect.ImmutableList)88 Symbol (io.trino.sql.planner.Symbol)77 ProjectNode (io.trino.sql.planner.plan.ProjectNode)65 PlanNode (io.trino.sql.planner.plan.PlanNode)63 Map (java.util.Map)63 NotExpression (io.trino.sql.tree.NotExpression)62 Test (org.testng.annotations.Test)58 Objects.requireNonNull (java.util.Objects.requireNonNull)57 Assignments (io.trino.sql.planner.plan.Assignments)55 InListExpression (io.trino.sql.tree.InListExpression)55 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)54 SymbolReference (io.trino.sql.tree.SymbolReference)53 Type (io.trino.spi.type.Type)52 List (java.util.List)52 Set (java.util.Set)52 SubscriptExpression (io.trino.sql.tree.SubscriptExpression)48 ImmutableMap (com.google.common.collect.ImmutableMap)47 Optional (java.util.Optional)47