Search in sources :

Example 21 with Expression

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);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) CubeRangeCanonicalizer(io.prestosql.operator.CubeRangeCanonicalizer) InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) LongLiteral(io.prestosql.sql.tree.LongLiteral) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) SymbolReference(io.prestosql.sql.tree.SymbolReference) Test(org.testng.annotations.Test)

Example 22 with Expression

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))));
}
Also used : InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) ExtractionResult(io.prestosql.sql.planner.ExpressionDomainTranslator.ExtractionResult) Test(org.testng.annotations.Test)

Example 23 with Expression

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

Example 24 with Expression

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));
}
Also used : InListExpression(io.prestosql.sql.tree.InListExpression) NotExpression(io.prestosql.sql.tree.NotExpression) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Expression(io.prestosql.sql.tree.Expression) Test(org.testng.annotations.Test)

Example 25 with Expression

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);
}
Also used : Cast(io.prestosql.sql.tree.Cast) PlanNode(io.prestosql.spi.plan.PlanNode) CallExpression(io.prestosql.spi.relation.CallExpression) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) Expression(io.prestosql.sql.tree.Expression) Assignments(io.prestosql.spi.plan.Assignments) ProjectNode(io.prestosql.spi.plan.ProjectNode) Test(org.testng.annotations.Test)

Aggregations

Expression (io.prestosql.sql.tree.Expression)206 ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)114 RowExpression (io.prestosql.spi.relation.RowExpression)80 OriginalExpressionUtils.castToRowExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression)80 InListExpression (io.prestosql.sql.tree.InListExpression)73 Symbol (io.prestosql.spi.plan.Symbol)68 NotExpression (io.prestosql.sql.tree.NotExpression)58 PlanNode (io.prestosql.spi.plan.PlanNode)47 CallExpression (io.prestosql.spi.relation.CallExpression)47 ArithmeticBinaryExpression (io.prestosql.sql.tree.ArithmeticBinaryExpression)43 ArrayList (java.util.ArrayList)42 Test (org.testng.annotations.Test)42 Type (io.prestosql.spi.type.Type)41 DereferenceExpression (io.prestosql.sql.tree.DereferenceExpression)41 LambdaExpression (io.prestosql.sql.tree.LambdaExpression)41 ImmutableList (com.google.common.collect.ImmutableList)40 List (java.util.List)40 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)38 SymbolReference (io.prestosql.sql.tree.SymbolReference)36 OriginalExpressionUtils.castToExpression (io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression)35