Search in sources :

Example 1 with InPredicate

use of io.prestosql.sql.tree.InPredicate in project hetu-core by openlookeng.

the class ExpressionVerifier method visitInPredicate.

@Override
protected Boolean visitInPredicate(InPredicate actual, Node expectedExpression) {
    if (expectedExpression instanceof InPredicate) {
        InPredicate expected = (InPredicate) expectedExpression;
        if (actual.getValueList() instanceof InListExpression) {
            return process(actual.getValue(), expected.getValue()) && process(actual.getValueList(), expected.getValueList());
        } else {
            checkState(expected.getValueList() instanceof InListExpression, "ExpressionVerifier doesn't support unpacked expected values. Feel free to add support if needed");
            /*
                 * 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 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".
                 *
                 * This is required 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.
                 */
            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);
        }
    }
    return false;
}
Also used : InListExpression(io.prestosql.sql.tree.InListExpression) CoalesceExpression(io.prestosql.sql.tree.CoalesceExpression) ArithmeticBinaryExpression(io.prestosql.sql.tree.ArithmeticBinaryExpression) SimpleCaseExpression(io.prestosql.sql.tree.SimpleCaseExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) TryExpression(io.prestosql.sql.tree.TryExpression) Expression(io.prestosql.sql.tree.Expression) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate)

Example 2 with InPredicate

use of io.prestosql.sql.tree.InPredicate in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method in.

private InPredicate in(Expression expression, Type expressisonType, List<?> values) {
    List<Type> types = nCopies(values.size(), expressisonType);
    List<Expression> expressions = literalEncoder.toExpressions(values, types);
    return new InPredicate(expression, new InListExpression(expressions));
}
Also used : DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) DecimalType.createDecimalType(io.prestosql.spi.type.DecimalType.createDecimalType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate)

Example 3 with InPredicate

use of io.prestosql.sql.tree.InPredicate in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testFromUnprocessableInPredicate.

@Test
public void testFromUnprocessableInPredicate() {
    assertUnsupportedPredicate(new InPredicate(unprocessableExpression1(C_BIGINT), new InListExpression(ImmutableList.of(TRUE_LITERAL))));
    assertUnsupportedPredicate(new InPredicate(toSymbolReference(C_BOOLEAN), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN)))));
    assertUnsupportedPredicate(new InPredicate(toSymbolReference(C_BOOLEAN), new InListExpression(ImmutableList.of(TRUE_LITERAL, unprocessableExpression1(C_BOOLEAN)))));
    assertUnsupportedPredicate(not(new InPredicate(toSymbolReference(C_BOOLEAN), new InListExpression(ImmutableList.of(unprocessableExpression1(C_BOOLEAN))))));
}
Also used : InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) Test(org.testng.annotations.Test)

Example 4 with InPredicate

use of io.prestosql.sql.tree.InPredicate in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testFromInPredicateWithCastsAndNulls.

@Test
public void testFromInPredicateWithCastsAndNulls() {
    assertPredicateIsAlwaysFalse(new InPredicate(toSymbolReference(C_BIGINT), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT)))));
    assertUnsupportedPredicate(not(new InPredicate(cast(C_SMALLINT, BIGINT), new InListExpression(ImmutableList.of(toExpression(null, BIGINT))))));
    assertPredicateTranslates(new InPredicate(toSymbolReference(C_BIGINT), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT), toExpression(1L, BIGINT)))), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L)), false))));
    assertPredicateIsAlwaysFalse(not(new InPredicate(toSymbolReference(C_BIGINT), new InListExpression(ImmutableList.of(cast(toExpression(null, SMALLINT), BIGINT), toExpression(1L, SMALLINT))))));
}
Also used : InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) Test(org.testng.annotations.Test)

Example 5 with InPredicate

use of io.prestosql.sql.tree.InPredicate in project hetu-core by openlookeng.

the class HeuristicIndexUtilsTest method testExtractPartitions.

@Test
public void testExtractPartitions() {
    Expression equalExpName = new ComparisonExpression(EQUAL, name("a"), new LongLiteral("1"));
    System.out.println(equalExpName);
    assertEquals(HeuristicIndexUtils.extractPartitions(equalExpName), ImmutableList.of("a=1"));
    Expression equalExpNameExp = new ComparisonExpression(EQUAL, nameExp("a"), new LongLiteral("1"));
    System.out.println(equalExpNameExp);
    assertEquals(HeuristicIndexUtils.extractPartitions(equalExpName), ImmutableList.of("a=1"));
    Expression equalExp2Name = new ComparisonExpression(EQUAL, name("a"), new LongLiteral("2"));
    System.out.println(equalExp2Name);
    Expression orExp = new LogicalBinaryExpression(LogicalBinaryExpression.Operator.OR, equalExpName, equalExp2Name);
    System.out.println(orExp);
    assertEquals(HeuristicIndexUtils.extractPartitions(orExp), ImmutableList.of("a=1", "a=2"));
    Expression inExpInteger = new InPredicate(name("a"), new InListExpression(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3"), new LongLiteral("4"), new LongLiteral("5"), new LongLiteral("6"))));
    System.out.println(inExpInteger);
    assertEquals(HeuristicIndexUtils.extractPartitions(inExpInteger), ImmutableList.of("a=1", "a=2", "a=3", "a=4", "a=5", "a=6"));
    Expression inExpBigInt = new InPredicate(name("a"), new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2), bigintLiteral(3), bigintLiteral(4), bigintLiteral(5), bigintLiteral(6))));
    System.out.println(inExpBigInt);
    assertEquals(HeuristicIndexUtils.extractPartitions(inExpInteger), ImmutableList.of("a=1", "a=2", "a=3", "a=4", "a=5", "a=6"));
}
Also used : LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) LogicalBinaryExpression(io.prestosql.sql.tree.LogicalBinaryExpression) InListExpression(io.prestosql.sql.tree.InListExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) Test(org.testng.annotations.Test)

Aggregations

InPredicate (io.prestosql.sql.tree.InPredicate)20 Expression (io.prestosql.sql.tree.Expression)15 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)13 InListExpression (io.prestosql.sql.tree.InListExpression)12 Symbol (io.prestosql.spi.plan.Symbol)7 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)7 NotExpression (io.prestosql.sql.tree.NotExpression)6 Test (org.testng.annotations.Test)6 RowExpression (io.prestosql.spi.relation.RowExpression)4 Type (io.prestosql.spi.type.Type)4 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)4 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)3 Cast (io.prestosql.sql.tree.Cast)3 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)3 IsNotNullPredicate (io.prestosql.sql.tree.IsNotNullPredicate)3 ArrayList (java.util.ArrayList)3 ProjectNode (io.prestosql.spi.plan.ProjectNode)2