use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression.
@Test
public void testCubeRangeVisitorRightCastedSymbolReferenceComparisonExpression() {
CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new Cast(new SymbolReference(C_TINYINT.getName()), "integer"));
List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
assertNotNull(transformed);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionDomainTranslator method testFromAndPredicate.
@Test
public void testFromAndPredicate() {
Expression originalPredicate = and(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)));
ExtractionResult result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), and(unprocessableExpression1(C_BIGINT), unprocessableExpression2(C_BIGINT)));
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, false, 5L, false)), false))));
// Test complements
assertUnsupportedPredicate(not(and(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT)), and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)))));
originalPredicate = not(and(not(and(greaterThan(C_BIGINT, bigintLiteral(1L)), unprocessableExpression1(C_BIGINT))), not(and(lessThan(C_BIGINT, bigintLiteral(5L)), unprocessableExpression2(C_BIGINT)))));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.notNull(BIGINT))));
}
use of io.prestosql.sql.tree.Expression 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"));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestTupleDomainFilterUtils method testDecimal.
@Test
public void testDecimal() {
Long decimal = shortDecimal("-99.33");
Expression decimalLiteral = toExpression(decimal, TYPES.get(C_DECIMAL_6_1));
assertEquals(toFilter(equal(C_DECIMAL_6_1, decimalLiteral)), TupleDomainFilter.BigintRange.of(decimal, decimal, false));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestTypeValidator method testInvalidProject.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'expr(_[0-9]+)?' is expected to be bigint, but the actual type is integer")
public void testInvalidProject() {
Expression expression1 = new Cast(toSymbolReference(columnB), StandardTypes.INTEGER);
Expression expression2 = new Cast(toSymbolReference(columnA), StandardTypes.INTEGER);
Assignments assignments = Assignments.builder().put(planSymbolAllocator.newSymbol(expression1, BIGINT), // should be INTEGER
castToRowExpression(expression1)).put(planSymbolAllocator.newSymbol(expression1, INTEGER), castToRowExpression(expression2)).build();
PlanNode node = new ProjectNode(newId(), baseTableScan, assignments);
assertTypesValid(node);
}
Aggregations