Search in sources :

Example 1 with InListExpression

use of io.prestosql.sql.tree.InListExpression 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 InListExpression

use of io.prestosql.sql.tree.InListExpression 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 InListExpression

use of io.prestosql.sql.tree.InListExpression 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 InListExpression

use of io.prestosql.sql.tree.InListExpression 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 InListExpression

use of io.prestosql.sql.tree.InListExpression 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

InListExpression (io.prestosql.sql.tree.InListExpression)12 InPredicate (io.prestosql.sql.tree.InPredicate)12 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)9 Expression (io.prestosql.sql.tree.Expression)8 Test (org.testng.annotations.Test)6 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)5 NotExpression (io.prestosql.sql.tree.NotExpression)5 Type (io.prestosql.spi.type.Type)4 Cast (io.prestosql.sql.tree.Cast)3 NullLiteral (io.prestosql.sql.tree.NullLiteral)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 Symbol (io.prestosql.spi.plan.Symbol)2 Range (io.prestosql.spi.predicate.Range)2 SortedRangeSet (io.prestosql.spi.predicate.SortedRangeSet)2 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)2 IsNotNullPredicate (io.prestosql.sql.tree.IsNotNullPredicate)2 SimpleCaseExpression (io.prestosql.sql.tree.SimpleCaseExpression)2 ArrayList (java.util.ArrayList)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1