Search in sources :

Example 16 with Expression

use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testDateType.

private void testDateType() {
    mergeAndAssert(true, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-05")), equal(C_DATE, date("2020-01-06")), equal(C_DATE, date("2020-01-07")), and(greaterThan(C_DATE, date("2020-01-07")), lessThanOrEqual(C_DATE, date("2020-01-09"))), between(C_DATE, date("2020-01-10"), date("2020-01-15")), between(C_DATE, date("2020-01-25"), date("2020-01-29"))), between(C_DATE, date("2020-01-02"), date("2020-01-12")));
    mergeAndAssert(true, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-05")), equal(C_DATE, date("2020-01-06")), equal(C_DATE, date("2020-01-07")), and(greaterThan(C_DATE, date("2020-01-07")), lessThanOrEqual(C_DATE, date("2020-01-09"))), between(C_DATE, date("2020-01-10"), date("2020-01-15")), between(C_DATE, date("2020-01-25"), date("2020-01-29"))), and(greaterThan(C_DATE, date("2020-01-02")), lessThan(C_DATE, date("2020-01-12"))));
    mergeAndAssert(true, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-05")), equal(C_DATE, date("2020-01-06")), equal(C_DATE, date("2020-01-07")), and(greaterThan(C_DATE, date("2020-01-07")), lessThanOrEqual(C_DATE, date("2020-01-09"))), between(C_DATE, date("2020-01-10"), date("2020-01-15")), between(C_DATE, date("2020-01-25"), date("2020-01-29"))), or(equal(C_DATE, date("2020-01-02")), equal(C_DATE, date("2020-01-05"))));
    mergeAndAssert(false, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-05")), equal(C_DATE, date("2020-01-06")), equal(C_DATE, date("2020-01-07")), and(greaterThan(C_DATE, date("2020-01-07")), lessThanOrEqual(C_DATE, date("2020-01-09"))), between(C_DATE, date("2020-01-10"), date("2020-01-15")), between(C_DATE, date("2020-01-25"), date("2020-01-29"))), between(C_DATE, date("2020-01-10"), date("2020-01-16")));
    Expression merged = mergeAndAssert(false, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-04")), between(C_DATE, date("2020-01-08"), date("2020-01-10"))), between(C_DATE, date("2020-01-02"), date("2020-01-06")));
    mergeAndAssert(true, ExpressionUtils.or(merged, equal(C_DATE, date("2020-01-05")), between(C_DATE, date("2020-01-06"), date("2020-01-07"))), between(C_DATE, date("2020-01-02"), date("2020-01-10")));
    mergeAndAssert(true, ExpressionUtils.or(between(C_DATE, date("2020-01-01"), date("2020-01-05")), equal(C_DATE, date("2020-01-06")), equal(C_DATE, date("2020-01-07")), equal(C_DATE, nullLiteral()), and(greaterThan(C_DATE, date("2020-01-07")), lessThanOrEqual(C_DATE, date("2020-01-09"))), between(C_DATE, date("2020-01-10"), date("2020-01-15")), between(C_DATE, date("2020-01-25"), date("2020-01-29"))), between(C_DATE, date("2020-01-02"), date("2020-01-12")));
}
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)

Example 17 with Expression

use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testTinyIntType.

private void testTinyIntType() {
    mergeAndAssert(true, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("5")), equal(C_TINYINT, tinyIntLiteral("6")), equal(C_TINYINT, tinyIntLiteral("7")), and(greaterThan(C_TINYINT, tinyIntLiteral("7")), lessThanOrEqual(C_TINYINT, tinyIntLiteral("9"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("15")), between(C_TINYINT, tinyIntLiteral("25"), tinyIntLiteral("35"))), between(C_TINYINT, tinyIntLiteral("2"), tinyIntLiteral("12")));
    mergeAndAssert(true, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("5")), equal(C_TINYINT, tinyIntLiteral("6")), equal(C_TINYINT, tinyIntLiteral("7")), and(greaterThan(C_TINYINT, tinyIntLiteral("7")), lessThanOrEqual(C_TINYINT, tinyIntLiteral("9"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("15")), between(C_TINYINT, tinyIntLiteral("25"), tinyIntLiteral("35"))), and(greaterThan(C_TINYINT, tinyIntLiteral("2")), lessThan(C_TINYINT, tinyIntLiteral("12"))));
    mergeAndAssert(true, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("5")), equal(C_TINYINT, tinyIntLiteral("6")), equal(C_TINYINT, tinyIntLiteral("7")), and(greaterThan(C_TINYINT, tinyIntLiteral("7")), lessThanOrEqual(C_TINYINT, tinyIntLiteral("9"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("15")), between(C_TINYINT, tinyIntLiteral("25"), tinyIntLiteral("35"))), or(equal(C_TINYINT, tinyIntLiteral("2")), equal(C_TINYINT, tinyIntLiteral("5"))));
    mergeAndAssert(false, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("5")), equal(C_TINYINT, tinyIntLiteral("6")), equal(C_TINYINT, tinyIntLiteral("7")), and(greaterThan(C_TINYINT, tinyIntLiteral("7")), lessThanOrEqual(C_TINYINT, tinyIntLiteral("9"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("15")), between(C_TINYINT, tinyIntLiteral("25"), tinyIntLiteral("35"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("16")));
    Expression merged = mergeAndAssert(false, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("4")), between(C_TINYINT, tinyIntLiteral("8"), tinyIntLiteral("10"))), between(C_TINYINT, tinyIntLiteral("2"), tinyIntLiteral("6")));
    mergeAndAssert(true, ExpressionUtils.or(merged, equal(C_TINYINT, tinyIntLiteral("5")), between(C_TINYINT, tinyIntLiteral("6"), tinyIntLiteral("7"))), between(C_TINYINT, tinyIntLiteral("2"), tinyIntLiteral("10")));
    mergeAndAssert(true, ExpressionUtils.or(between(C_TINYINT, tinyIntLiteral("1"), tinyIntLiteral("5")), equal(C_TINYINT, tinyIntLiteral("6")), equal(C_TINYINT, tinyIntLiteral("7")), equal(C_TINYINT, nullLiteral()), and(greaterThan(C_TINYINT, tinyIntLiteral("7")), lessThanOrEqual(C_TINYINT, tinyIntLiteral("9"))), between(C_TINYINT, tinyIntLiteral("10"), tinyIntLiteral("15")), between(C_TINYINT, tinyIntLiteral("25"), tinyIntLiteral("35"))), between(C_TINYINT, tinyIntLiteral("2"), tinyIntLiteral("12")));
}
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)

Example 18 with Expression

use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testCubeRangeVisitorRightSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorRightSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new LongLiteral("1"), new SymbolReference(C_TINYINT.getName()));
    List<Expression> predicates = ExpressionUtils.extractDisjuncts(cubePredicate);
    Expression transformed = ExpressionUtils.or(predicates.stream().map(visitor::process).collect(Collectors.toList()));
    assertNotNull(transformed);
}
Also used : 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 19 with Expression

use of io.prestosql.sql.tree.Expression 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 20 with Expression

use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.

the class TestExpressionDomainTranslator method testConjunctExpression.

@Test
public void testConjunctExpression() {
    Expression expression = and(comparison(GREATER_THAN, toSymbolReference(C_DOUBLE), doubleLiteral(0)), comparison(GREATER_THAN, toSymbolReference(C_BIGINT), bigintLiteral(0)));
    assertPredicateTranslates(expression, withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.greaterThan(BIGINT, 0L)), false), C_DOUBLE, Domain.create(ValueSet.ofRanges(Range.greaterThan(DOUBLE, .0)), false))));
    assertEquals(toPredicate(fromPredicate(expression).getTupleDomain()), and(comparison(GREATER_THAN, toSymbolReference(C_BIGINT), bigintLiteral(0)), comparison(GREATER_THAN, toSymbolReference(C_DOUBLE), doubleLiteral(0))));
}
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)

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