Search in sources :

Example 1 with IsNotNullPredicate

use of com.facebook.presto.sql.tree.IsNotNullPredicate in project presto by prestodb.

the class TestEqualityInference method testExpressionsThatMayReturnNullOnNonNullInput.

@Test
public void testExpressionsThatMayReturnNullOnNonNullInput() throws Exception {
    List<Expression> candidates = ImmutableList.of(// try_cast
    new Cast(nameReference("b"), "BIGINT", true), new FunctionCall(QualifiedName.of("try"), ImmutableList.of(nameReference("b"))), new NullIfExpression(nameReference("b"), number(1)), new IfExpression(nameReference("b"), number(1), new NullLiteral()), new DereferenceExpression(nameReference("b"), "x"), new InPredicate(nameReference("b"), new InListExpression(ImmutableList.of(new NullLiteral()))), new SearchedCaseExpression(ImmutableList.of(new WhenClause(new IsNotNullPredicate(nameReference("b")), new NullLiteral())), Optional.empty()), new SimpleCaseExpression(nameReference("b"), ImmutableList.of(new WhenClause(number(1), new NullLiteral())), Optional.empty()), new SubscriptExpression(new ArrayConstructor(ImmutableList.of(new NullLiteral())), nameReference("b")));
    for (Expression candidate : candidates) {
        EqualityInference.Builder builder = new EqualityInference.Builder();
        builder.extractInferenceCandidates(equals(nameReference("b"), nameReference("x")));
        builder.extractInferenceCandidates(equals(nameReference("a"), candidate));
        EqualityInference inference = builder.build();
        List<Expression> equalities = inference.generateEqualitiesPartitionedBy(matchesSymbols("b")).getScopeStraddlingEqualities();
        assertEquals(equalities.size(), 1);
        assertTrue(equalities.get(0).equals(equals(nameReference("x"), nameReference("b"))) || equalities.get(0).equals(equals(nameReference("b"), nameReference("x"))));
    }
}
Also used : Cast(com.facebook.presto.sql.tree.Cast) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) IfExpression(com.facebook.presto.sql.tree.IfExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) InPredicate(com.facebook.presto.sql.tree.InPredicate) IsNotNullPredicate(com.facebook.presto.sql.tree.IsNotNullPredicate) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) WhenClause(com.facebook.presto.sql.tree.WhenClause) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) InListExpression(com.facebook.presto.sql.tree.InListExpression) DereferenceExpression(com.facebook.presto.sql.tree.DereferenceExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) Expression(com.facebook.presto.sql.tree.Expression) IfExpression(com.facebook.presto.sql.tree.IfExpression) ArithmeticBinaryExpression(com.facebook.presto.sql.tree.ArithmeticBinaryExpression) SearchedCaseExpression(com.facebook.presto.sql.tree.SearchedCaseExpression) SimpleCaseExpression(com.facebook.presto.sql.tree.SimpleCaseExpression) NullIfExpression(com.facebook.presto.sql.tree.NullIfExpression) SubscriptExpression(com.facebook.presto.sql.tree.SubscriptExpression) ArrayConstructor(com.facebook.presto.sql.tree.ArrayConstructor) FunctionCall(com.facebook.presto.sql.tree.FunctionCall) NullLiteral(com.facebook.presto.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Aggregations

ArithmeticBinaryExpression (com.facebook.presto.sql.tree.ArithmeticBinaryExpression)1 ArrayConstructor (com.facebook.presto.sql.tree.ArrayConstructor)1 Cast (com.facebook.presto.sql.tree.Cast)1 ComparisonExpression (com.facebook.presto.sql.tree.ComparisonExpression)1 DereferenceExpression (com.facebook.presto.sql.tree.DereferenceExpression)1 Expression (com.facebook.presto.sql.tree.Expression)1 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)1 IfExpression (com.facebook.presto.sql.tree.IfExpression)1 InListExpression (com.facebook.presto.sql.tree.InListExpression)1 InPredicate (com.facebook.presto.sql.tree.InPredicate)1 IsNotNullPredicate (com.facebook.presto.sql.tree.IsNotNullPredicate)1 NullIfExpression (com.facebook.presto.sql.tree.NullIfExpression)1 NullLiteral (com.facebook.presto.sql.tree.NullLiteral)1 SearchedCaseExpression (com.facebook.presto.sql.tree.SearchedCaseExpression)1 SimpleCaseExpression (com.facebook.presto.sql.tree.SimpleCaseExpression)1 SubscriptExpression (com.facebook.presto.sql.tree.SubscriptExpression)1 WhenClause (com.facebook.presto.sql.tree.WhenClause)1 Test (org.testng.annotations.Test)1