use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromBetweenPredicate.
@Test
public void testFromBetweenPredicate() throws Exception {
Expression originalExpression = between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L));
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 2L, true)), false))));
originalExpression = between(cast(C_BIGINT, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 2L, true)), false))));
originalExpression = between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
// Test complements
originalExpression = not(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(2L)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 2L)), false))));
originalExpression = not(between(cast(C_BIGINT, DOUBLE), cast(bigintLiteral(1L), DOUBLE), doubleLiteral(2.1)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 2L)), false))));
originalExpression = not(between(C_BIGINT, bigintLiteral(1L), nullLiteral(BIGINT)));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L)), false))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromBooleanLiteralPredicate.
@Test
public void testFromBooleanLiteralPredicate() throws Exception {
Expression originalExpression = TRUE_LITERAL;
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isAll());
originalExpression = not(TRUE_LITERAL);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = FALSE_LITERAL;
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalExpression = not(FALSE_LITERAL);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isAll());
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromIsNotNullPredicate.
@Test
public void testFromIsNotNullPredicate() throws Exception {
Expression originalExpression = isNotNull(C_BIGINT);
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
originalExpression = isNotNull(C_HYPER_LOG_LOG);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.notNull(HYPER_LOG_LOG))));
originalExpression = not(isNotNull(C_BIGINT));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.onlyNull(BIGINT))));
originalExpression = not(isNotNull(C_HYPER_LOG_LOG));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_HYPER_LOG_LOG, Domain.onlyNull(HYPER_LOG_LOG))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class TestDomainTranslator method testFromNotPredicate.
@Test
public void testFromNotPredicate() throws Exception {
Expression originalPredicate = not(and(equal(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)));
ExtractionResult result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertTrue(result.getTupleDomain().isAll());
originalPredicate = not(unprocessableExpression1(C_BIGINT));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertTrue(result.getTupleDomain().isAll());
originalPredicate = not(TRUE_LITERAL);
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalPredicate = not(equal(C_BIGINT, bigintLiteral(1L)));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 1L)), false))));
}
use of com.facebook.presto.sql.tree.Expression in project presto by prestodb.
the class ExpressionFormatter method formatGroupBy.
static String formatGroupBy(List<GroupingElement> groupingElements, Optional<List<Expression>> parameters) {
ImmutableList.Builder<String> resultStrings = ImmutableList.builder();
for (GroupingElement groupingElement : groupingElements) {
String result = "";
if (groupingElement instanceof SimpleGroupBy) {
Set<Expression> columns = ImmutableSet.copyOf(((SimpleGroupBy) groupingElement).getColumnExpressions());
if (columns.size() == 1) {
result = formatExpression(getOnlyElement(columns), parameters);
} else {
result = formatGroupingSet(columns, parameters);
}
} else if (groupingElement instanceof GroupingSets) {
result = format("GROUPING SETS (%s)", Joiner.on(", ").join(((GroupingSets) groupingElement).getSets().stream().map(ExpressionFormatter::formatGroupingSet).iterator()));
} else if (groupingElement instanceof Cube) {
result = format("CUBE %s", formatGroupingSet(((Cube) groupingElement).getColumns()));
} else if (groupingElement instanceof Rollup) {
result = format("ROLLUP %s", formatGroupingSet(((Rollup) groupingElement).getColumns()));
}
resultStrings.add(result);
}
return Joiner.on(", ").join(resultStrings.build());
}
Aggregations