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;
}
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));
}
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))))));
}
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))))));
}
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"));
}
Aggregations