Search in sources :

Example 1 with NotExpression

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

the class DomainTranslator method toPredicate.

private Expression toPredicate(Session session, Domain domain, SymbolReference reference) {
    if (domain.getValues().isNone()) {
        return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL;
    }
    if (domain.getValues().isAll()) {
        return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference));
    }
    List<Expression> disjuncts = new ArrayList<>();
    disjuncts.addAll(domain.getValues().getValuesProcessor().transform(ranges -> extractDisjuncts(session, domain.getType(), ranges, reference), discreteValues -> extractDisjuncts(session, domain.getType(), discreteValues, reference), allOrNone -> {
        throw new IllegalStateException("Case should not be reachable");
    }));
    // Add nullability disjuncts
    if (domain.isNullAllowed()) {
        disjuncts.add(new IsNullPredicate(reference));
    }
    return combineDisjunctsWithDefault(plannerContext.getMetadata(), disjuncts, TRUE_LITERAL);
}
Also used : IsNullPredicate(io.trino.sql.tree.IsNullPredicate) TableProceduresPropertyManager(io.trino.metadata.TableProceduresPropertyManager) FAIL_ON_NULL(io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL) ExpressionUtils.combineDisjunctsWithDefault(io.trino.sql.ExpressionUtils.combineDisjunctsWithDefault) InvocationConvention.simpleConvention(io.trino.spi.function.InvocationConvention.simpleConvention) PeekingIterator(com.google.common.collect.PeekingIterator) InterpretedFunctionInvoker(io.trino.sql.InterpretedFunctionInvoker) TypeUtils.isFloatingPointNaN(io.trino.spi.type.TypeUtils.isFloatingPointNaN) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BooleanLiteral(io.trino.sql.tree.BooleanLiteral) ExpressionUtils.or(io.trino.sql.ExpressionUtils.or) Slices(io.airlift.slice.Slices) Map(java.util.Map) GREATER_THAN(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN) DiscreteValues(io.trino.spi.predicate.DiscreteValues) SqlParser(io.trino.sql.parser.SqlParser) FunctionCall(io.trino.sql.tree.FunctionCall) BetweenPredicate(io.trino.sql.tree.BetweenPredicate) SliceUtf8.getCodePointAt(io.airlift.slice.SliceUtf8.getCodePointAt) SATURATED_FLOOR_CAST(io.trino.spi.function.OperatorType.SATURATED_FLOOR_CAST) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Range(io.trino.spi.predicate.Range) Ranges(io.trino.spi.predicate.Ranges) ResolvedFunction(io.trino.metadata.ResolvedFunction) Domain(io.trino.spi.predicate.Domain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) FALSE_LITERAL(io.trino.sql.tree.BooleanLiteral.FALSE_LITERAL) Set(java.util.Set) TrinoException(io.trino.spi.TrinoException) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) ValueSet(io.trino.spi.predicate.ValueSet) InPredicate(io.trino.sql.tree.InPredicate) Preconditions.checkState(com.google.common.base.Preconditions.checkState) LESS_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) SessionPropertyManager(io.trino.metadata.SessionPropertyManager) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) NOT_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.NOT_EQUAL) List(java.util.List) SymbolReference(io.trino.sql.tree.SymbolReference) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) InListExpression(io.trino.sql.tree.InListExpression) ExpressionUtils.combineConjuncts(io.trino.sql.ExpressionUtils.combineConjuncts) NEVER_NULL(io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.NEVER_NULL) Session(io.trino.Session) PlannerContext(io.trino.sql.PlannerContext) MethodHandle(java.lang.invoke.MethodHandle) Slice(io.airlift.slice.Slice) AllowAllAccessControl(io.trino.security.AllowAllAccessControl) NullableValue(io.trino.spi.predicate.NullableValue) DoubleType(io.trino.spi.type.DoubleType) LikePredicate(io.trino.sql.tree.LikePredicate) Type(io.trino.spi.type.Type) TypeCoercion(io.trino.type.TypeCoercion) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) ArrayList(java.util.ArrayList) Cast(io.trino.sql.tree.Cast) VarcharType(io.trino.spi.type.VarcharType) ImmutableList(com.google.common.collect.ImmutableList) IsNotNullPredicate(io.trino.sql.tree.IsNotNullPredicate) NodeRef(io.trino.sql.tree.NodeRef) NotExpression(io.trino.sql.tree.NotExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) NullLiteral(io.trino.sql.tree.NullLiteral) TableProceduresRegistry(io.trino.metadata.TableProceduresRegistry) Iterators.peekingIterator(com.google.common.collect.Iterators.peekingIterator) GREATER_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) Nullable(javax.annotation.Nullable) AstVisitor(io.trino.sql.tree.AstVisitor) SliceUtf8.lengthOfCodePoint(io.airlift.slice.SliceUtf8.lengthOfCodePoint) StringLiteral(io.trino.sql.tree.StringLiteral) OperatorNotFoundException(io.trino.metadata.OperatorNotFoundException) Throwables(com.google.common.base.Throwables) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) TupleDomain(io.trino.spi.predicate.TupleDomain) SliceUtf8.setCodePointAt(io.airlift.slice.SliceUtf8.setCodePointAt) GENERIC_INTERNAL_ERROR(io.trino.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR) LikeFunctions(io.trino.type.LikeFunctions) Collectors.toList(java.util.stream.Collectors.toList) ExpressionUtils.and(io.trino.sql.ExpressionUtils.and) StatementAnalyzerFactory(io.trino.sql.analyzer.StatementAnalyzerFactory) TablePropertyManager(io.trino.metadata.TablePropertyManager) RealType(io.trino.spi.type.RealType) LogicalExpression(io.trino.sql.tree.LogicalExpression) SliceUtf8.countCodePoints(io.airlift.slice.SliceUtf8.countCodePoints) AnalyzePropertyManager(io.trino.metadata.AnalyzePropertyManager) SortedRangeSet(io.trino.spi.predicate.SortedRangeSet) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) ArrayList(java.util.ArrayList) IsNullPredicate(io.trino.sql.tree.IsNullPredicate) NotExpression(io.trino.sql.tree.NotExpression)

Example 2 with NotExpression

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

the class SimpleFilterProjectSemiJoinStatsRule method extractSemiJoinOutputFilter.

private Optional<SemiJoinOutputFilter> extractSemiJoinOutputFilter(Expression predicate, Symbol semiJoinOutput) {
    List<Expression> conjuncts = extractConjuncts(predicate);
    List<Expression> semiJoinOutputReferences = conjuncts.stream().filter(conjunct -> isSemiJoinOutputReference(conjunct, semiJoinOutput)).collect(toImmutableList());
    if (semiJoinOutputReferences.size() != 1) {
        return Optional.empty();
    }
    Expression semiJoinOutputReference = Iterables.getOnlyElement(semiJoinOutputReferences);
    Expression remainingPredicate = combineConjuncts(metadata, conjuncts.stream().filter(conjunct -> conjunct != semiJoinOutputReference).collect(toImmutableList()));
    boolean negated = semiJoinOutputReference instanceof NotExpression;
    return Optional.of(new SemiJoinOutputFilter(negated, remainingPredicate));
}
Also used : Symbol(io.trino.sql.planner.Symbol) Iterables(com.google.common.collect.Iterables) Lookup(io.trino.sql.planner.iterative.Lookup) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Patterns.filter(io.trino.sql.planner.plan.Patterns.filter) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) UNKNOWN_FILTER_COEFFICIENT(io.trino.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) FilterNode(io.trino.sql.planner.plan.FilterNode) PlanNode(io.trino.sql.planner.plan.PlanNode) SemiJoinStatsCalculator.computeSemiJoin(io.trino.cost.SemiJoinStatsCalculator.computeSemiJoin) List(java.util.List) Pattern(io.trino.matching.Pattern) SymbolReference(io.trino.sql.tree.SymbolReference) SemiJoinStatsCalculator.computeAntiJoin(io.trino.cost.SemiJoinStatsCalculator.computeAntiJoin) NotExpression(io.trino.sql.tree.NotExpression) Objects.requireNonNull(java.util.Objects.requireNonNull) Metadata(io.trino.metadata.Metadata) TypeProvider(io.trino.sql.planner.TypeProvider) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) ExpressionUtils.extractConjuncts(io.trino.sql.ExpressionUtils.extractConjuncts) ExpressionUtils.combineConjuncts(io.trino.sql.ExpressionUtils.combineConjuncts) ProjectNode(io.trino.sql.planner.plan.ProjectNode) Session(io.trino.Session) NotExpression(io.trino.sql.tree.NotExpression) Expression(io.trino.sql.tree.Expression) NotExpression(io.trino.sql.tree.NotExpression)

Example 3 with NotExpression

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

the class TestSqlParser method testPrecedenceAndAssociativity.

@Test
public void testPrecedenceAndAssociativity() {
    assertThat(expression("1 AND 2 AND 3 AND 4")).isEqualTo(new LogicalExpression(location(1, 1), LogicalExpression.Operator.AND, ImmutableList.of(new LongLiteral(location(1, 1), "1"), new LongLiteral(location(1, 7), "2"), new LongLiteral(location(1, 13), "3"), new LongLiteral(location(1, 19), "4"))));
    assertThat(expression("1 OR 2 OR 3 OR 4")).isEqualTo(new LogicalExpression(location(1, 1), LogicalExpression.Operator.OR, ImmutableList.of(new LongLiteral(location(1, 1), "1"), new LongLiteral(location(1, 6), "2"), new LongLiteral(location(1, 11), "3"), new LongLiteral(location(1, 16), "4"))));
    assertThat(expression("1 AND 2 AND 3 OR 4 AND 5 AND 6 OR 7 AND 8 AND 9")).isEqualTo(new LogicalExpression(location(1, 1), LogicalExpression.Operator.OR, ImmutableList.of(new LogicalExpression(location(1, 1), LogicalExpression.Operator.AND, ImmutableList.of(new LongLiteral(location(1, 1), "1"), new LongLiteral(location(1, 7), "2"), new LongLiteral(location(1, 13), "3"))), new LogicalExpression(location(1, 18), LogicalExpression.Operator.AND, ImmutableList.of(new LongLiteral(location(1, 18), "4"), new LongLiteral(location(1, 24), "5"), new LongLiteral(location(1, 30), "6"))), new LogicalExpression(location(1, 35), LogicalExpression.Operator.AND, ImmutableList.of(new LongLiteral(location(1, 35), "7"), new LongLiteral(location(1, 41), "8"), new LongLiteral(location(1, 47), "9"))))));
    assertExpression("1 AND 2 OR 3", LogicalExpression.or(LogicalExpression.and(new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 OR 2 AND 3", LogicalExpression.or(new LongLiteral("1"), LogicalExpression.and(new LongLiteral("2"), new LongLiteral("3"))));
    assertExpression("NOT 1 AND 2", LogicalExpression.and(new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
    assertExpression("NOT 1 OR 2", LogicalExpression.or(new NotExpression(new LongLiteral("1")), new LongLiteral("2")));
    assertExpression("-1 + 2", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.ADD, new LongLiteral("-1"), new LongLiteral("2")));
    assertExpression("1 - 2 - 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.SUBTRACT, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.SUBTRACT, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 / 2 / 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.DIVIDE, new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.DIVIDE, new LongLiteral("1"), new LongLiteral("2")), new LongLiteral("3")));
    assertExpression("1 + 2 * 3", new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.ADD, new LongLiteral("1"), new ArithmeticBinaryExpression(ArithmeticBinaryExpression.Operator.MULTIPLY, new LongLiteral("2"), new LongLiteral("3"))));
}
Also used : ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) LogicalExpression(io.trino.sql.tree.LogicalExpression) LongLiteral(io.trino.sql.tree.LongLiteral) NotExpression(io.trino.sql.tree.NotExpression) Test(org.junit.jupiter.api.Test)

Example 4 with NotExpression

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

the class JoinMatcher method matchDynamicFilters.

private boolean matchDynamicFilters(JoinNode joinNode, SymbolAliases symbolAliases) {
    if (expectedDynamicFilter.isEmpty()) {
        return true;
    }
    Set<DynamicFilterId> dynamicFilterIds = joinNode.getDynamicFilters().keySet();
    List<DynamicFilters.Descriptor> descriptors = searchFrom(joinNode.getLeft()).where(FilterNode.class::isInstance).findAll().stream().flatMap(filterNode -> extractExpressions(filterNode).stream()).flatMap(expression -> extractDynamicFilters(expression).getDynamicConjuncts().stream()).filter(descriptor -> dynamicFilterIds.contains(descriptor.getId())).collect(toImmutableList());
    Map<DynamicFilterId, Symbol> idToBuildSymbolMap = joinNode.getDynamicFilters();
    Set<Expression> actual = new HashSet<>();
    for (DynamicFilters.Descriptor descriptor : descriptors) {
        Expression probe = descriptor.getInput();
        Symbol build = idToBuildSymbolMap.get(descriptor.getId());
        if (build == null) {
            return false;
        }
        Expression expression;
        if (descriptor.isNullAllowed()) {
            expression = new NotExpression(new ComparisonExpression(IS_DISTINCT_FROM, probe, build.toSymbolReference()));
        } else {
            expression = new ComparisonExpression(descriptor.getOperator(), probe, build.toSymbolReference());
        }
        actual.add(expression);
    }
    Set<Expression> expected = expectedDynamicFilter.get().stream().map(pattern -> pattern.getExpression(symbolAliases)).collect(toImmutableSet());
    return expected.equals(actual);
}
Also used : PlanNodeSearcher.searchFrom(io.trino.sql.planner.optimizations.PlanNodeSearcher.searchFrom) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) FilterNode(io.trino.sql.planner.plan.FilterNode) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) PlanNode(io.trino.sql.planner.plan.PlanNode) HashSet(java.util.HashSet) DynamicFilters(io.trino.sql.DynamicFilters) DistributionType(io.trino.sql.planner.plan.JoinNode.DistributionType) IS_DISTINCT_FROM(io.trino.sql.tree.ComparisonExpression.Operator.IS_DISTINCT_FROM) NotExpression(io.trino.sql.tree.NotExpression) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ExpressionExtractor.extractExpressions(io.trino.sql.planner.ExpressionExtractor.extractExpressions) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) DynamicFilterPattern(io.trino.sql.planner.assertions.PlanMatchPattern.DynamicFilterPattern) JoinNode(io.trino.sql.planner.plan.JoinNode) Symbol(io.trino.sql.planner.Symbol) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) StatsProvider(io.trino.cost.StatsProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) Metadata(io.trino.metadata.Metadata) Optional(java.util.Optional) NO_MATCH(io.trino.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.trino.sql.tree.Expression) Session(io.trino.Session) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Symbol(io.trino.sql.planner.Symbol) FilterNode(io.trino.sql.planner.plan.FilterNode) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) DynamicFilters(io.trino.sql.DynamicFilters) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) HashSet(java.util.HashSet)

Example 5 with NotExpression

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

the class TestEffectivePredicateExtractor method testValues.

@Test
public void testValues() {
    TypeProvider types = TypeProvider.copyOf(ImmutableMap.<Symbol, Type>builder().put(A, BIGINT).put(B, BIGINT).put(D, DOUBLE).put(R, RowType.anonymous(ImmutableList.of(BIGINT, BIGINT))).buildOrThrow());
    // one column
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1))), new Row(ImmutableList.of(bigintLiteral(2))))), types, typeAnalyzer), new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))));
    // one column with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1))), new Row(ImmutableList.of(bigintLiteral(2))), new Row(ImmutableList.of(new Cast(new NullLiteral(), toSqlType(BIGINT)))))), types, typeAnalyzer), or(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new IsNullPredicate(AE)));
    // all nulls
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(new Row(ImmutableList.of(new Cast(new NullLiteral(), toSqlType(BIGINT)))))), types, typeAnalyzer), new IsNullPredicate(AE));
    // nested row
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(R), ImmutableList.of(new Row(ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1), new NullLiteral())))))), types, typeAnalyzer), TRUE_LITERAL);
    // many rows
    List<Expression> rows = IntStream.range(0, 500).mapToObj(TestEffectivePredicateExtractor::bigintLiteral).map(ImmutableList::of).map(Row::new).collect(toImmutableList());
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), rows), types, typeAnalyzer), new BetweenPredicate(AE, bigintLiteral(0), bigintLiteral(499)));
    // NaN
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(D), ImmutableList.of(new Row(ImmutableList.of(doubleLiteral(Double.NaN))))), types, typeAnalyzer), new NotExpression(new IsNullPredicate(DE)));
    // NaN and NULL
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(D), ImmutableList.of(new Row(ImmutableList.of(new Cast(new NullLiteral(), toSqlType(DOUBLE)))), new Row(ImmutableList.of(doubleLiteral(Double.NaN))))), types, typeAnalyzer), TRUE_LITERAL);
    // NaN and value
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(D), ImmutableList.of(new Row(ImmutableList.of(doubleLiteral(42.))), new Row(ImmutableList.of(doubleLiteral(Double.NaN))))), types, typeAnalyzer), new NotExpression(new IsNullPredicate(DE)));
    // Real NaN
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(D), ImmutableList.of(new Row(ImmutableList.of(new Cast(doubleLiteral(Double.NaN), toSqlType(REAL)))))), TypeProvider.copyOf(ImmutableMap.of(D, REAL)), typeAnalyzer), new NotExpression(new IsNullPredicate(DE)));
    // multiple columns
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1), bigintLiteral(100))), new Row(ImmutableList.of(bigintLiteral(2), bigintLiteral(200))))), types, typeAnalyzer), and(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new InPredicate(BE, new InListExpression(ImmutableList.of(bigintLiteral(100), bigintLiteral(200))))));
    // multiple columns with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1), new Cast(new NullLiteral(), toSqlType(BIGINT)))), new Row(ImmutableList.of(new Cast(new NullLiteral(), toSqlType(BIGINT)), bigintLiteral(200))))), types, typeAnalyzer), and(or(new ComparisonExpression(EQUAL, AE, bigintLiteral(1)), new IsNullPredicate(AE)), or(new ComparisonExpression(EQUAL, BE, bigintLiteral(200)), new IsNullPredicate(BE))));
    // non-deterministic
    ResolvedFunction rand = functionResolution.resolveFunction(QualifiedName.of("rand"), ImmutableList.of());
    ValuesNode node = new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1), new FunctionCall(rand.toQualifiedName(), ImmutableList.of())))));
    assertEquals(extract(types, node), new ComparisonExpression(EQUAL, AE, bigintLiteral(1)));
    // non-constant
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(new Row(ImmutableList.of(bigintLiteral(1))), new Row(ImmutableList.of(BE)))), types, typeAnalyzer), TRUE_LITERAL);
}
Also used : Cast(io.trino.sql.tree.Cast) ValuesNode(io.trino.sql.planner.plan.ValuesNode) BetweenPredicate(io.trino.sql.tree.BetweenPredicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ResolvedFunction(io.trino.metadata.ResolvedFunction) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) InPredicate(io.trino.sql.tree.InPredicate) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) RowType(io.trino.spi.type.RowType) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) Type(io.trino.spi.type.Type) InListExpression(io.trino.sql.tree.InListExpression) NotExpression(io.trino.sql.tree.NotExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) Expression(io.trino.sql.tree.Expression) IsNullPredicate(io.trino.sql.tree.IsNullPredicate) Row(io.trino.sql.tree.Row) FunctionCall(io.trino.sql.tree.FunctionCall) NullLiteral(io.trino.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Aggregations

NotExpression (io.trino.sql.tree.NotExpression)8 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Expression (io.trino.sql.tree.Expression)5 Session (io.trino.Session)4 ComparisonExpression (io.trino.sql.tree.ComparisonExpression)4 List (java.util.List)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Optional (java.util.Optional)4 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 BetweenPredicate (io.trino.sql.tree.BetweenPredicate)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Throwables (com.google.common.base.Throwables)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 Iterators.peekingIterator (com.google.common.collect.Iterators.peekingIterator)2 PeekingIterator (com.google.common.collect.PeekingIterator)2 Slice (io.airlift.slice.Slice)2