Search in sources :

Example 41 with ComparisonExpression

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

the class TestExpressionDomainTranslator method testCubeRangeVisitorLeftCastedSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorLeftCastedSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new Cast(new SymbolReference(C_TINYINT.getName()), "integer"), new LongLiteral("1"));
    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 42 with ComparisonExpression

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

the class TestEffectivePredicateExtractor method testValues.

@Test
public void testValues() {
    TypeProvider types = TypeProvider.copyOf(ImmutableMap.<Symbol, Type>builder().put(A, BIGINT).put(B, BIGINT).build());
    // one column
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(bigintLiteralRowExpression(2)))), types, typeAnalyzer), new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))));
    // one column with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(bigintLiteralRowExpression(2)), ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))))), types, typeAnalyzer), or(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new IsNullPredicate(AE)));
    // all nulls
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))))), types, typeAnalyzer), new IsNullPredicate(AE));
    // many rows
    List<List<RowExpression>> rows = IntStream.range(0, 500).mapToObj(TestEffectivePredicateExtractor::bigintLiteralRowExpression).map(ImmutableList::of).collect(toImmutableList());
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), rows), types, typeAnalyzer), new BetweenPredicate(AE, bigintLiteral(0), bigintLiteral(499)));
    // multiple columns
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), bigintLiteralRowExpression(100)), ImmutableList.of(bigintLiteralRowExpression(2), bigintLiteralRowExpression(200)))), types, typeAnalyzer), and(new InPredicate(AE, new InListExpression(ImmutableList.of(bigintLiteral(1), bigintLiteral(2)))), new InPredicate(BE, new InListExpression(ImmutableList.of(bigintLiteral(100), bigintLiteral(200))))));
    // multiple columns with null
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString()))), ImmutableList.of(castToRowExpression(new Cast(new NullLiteral(), BIGINT.toString())), bigintLiteralRowExpression(200)))), types, typeAnalyzer), and(or(new ComparisonExpression(EQUAL, AE, bigintLiteral(1)), new IsNullPredicate(AE)), or(new ComparisonExpression(EQUAL, BE, bigintLiteral(200)), new IsNullPredicate(BE))));
    // non-deterministic
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A, B), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1), castToRowExpression(new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()))))), types, typeAnalyzer), new ComparisonExpression(EQUAL, AE, bigintLiteral(1)));
    // non-constant
    assertEquals(effectivePredicateExtractor.extract(SESSION, new ValuesNode(newId(), ImmutableList.of(A), ImmutableList.of(ImmutableList.of(bigintLiteralRowExpression(1)), ImmutableList.of(castToRowExpression(BE)))), types, typeAnalyzer), TRUE_LITERAL);
}
Also used : Cast(io.prestosql.sql.tree.Cast) ValuesNode(io.prestosql.spi.plan.ValuesNode) BetweenPredicate(io.prestosql.sql.tree.BetweenPredicate) Symbol(io.prestosql.spi.plan.Symbol) InListExpression(io.prestosql.sql.tree.InListExpression) InPredicate(io.prestosql.sql.tree.InPredicate) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) OperatorType(io.prestosql.spi.function.OperatorType) Type(io.prestosql.spi.type.Type) IsNullPredicate(io.prestosql.sql.tree.IsNullPredicate) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FunctionCall(io.prestosql.sql.tree.FunctionCall) NullLiteral(io.prestosql.sql.tree.NullLiteral) Test(org.testng.annotations.Test)

Example 43 with ComparisonExpression

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

the class TestEqualityInference method equalityAsSet.

private static Set<Expression> equalityAsSet(Expression expression) {
    Preconditions.checkArgument(expression instanceof ComparisonExpression);
    ComparisonExpression comparisonExpression = (ComparisonExpression) expression;
    Preconditions.checkArgument(comparisonExpression.getOperator() == EQUAL);
    return ImmutableSet.of(comparisonExpression.getLeft(), comparisonExpression.getRight());
}
Also used : ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression)

Example 44 with ComparisonExpression

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

the class TestExpressionDomainTranslator method testCubeRangeVisitorLeftSymbolReferenceComparisonExpression.

@Test
public void testCubeRangeVisitorLeftSymbolReferenceComparisonExpression() {
    CubeRangeCanonicalizer.CubeRangeVisitor visitor = new CubeRangeCanonicalizer.CubeRangeVisitor(TYPES, metadata, TEST_SESSION.toConnectorSession());
    Expression cubePredicate = new ComparisonExpression(EQUAL, new SymbolReference(C_TINYINT.getName()), new LongLiteral("1"));
    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)

Aggregations

ComparisonExpression (io.prestosql.sql.tree.ComparisonExpression)44 Test (org.testng.annotations.Test)21 SymbolReference (io.prestosql.sql.tree.SymbolReference)20 Expression (io.prestosql.sql.tree.Expression)19 LongLiteral (io.prestosql.sql.tree.LongLiteral)17 Symbol (io.prestosql.spi.plan.Symbol)13 InListExpression (io.prestosql.sql.tree.InListExpression)11 LogicalBinaryExpression (io.prestosql.sql.tree.LogicalBinaryExpression)10 NotExpression (io.prestosql.sql.tree.NotExpression)10 StringLiteral (io.prestosql.sql.tree.StringLiteral)10 Cast (io.prestosql.sql.tree.Cast)9 ArrayList (java.util.ArrayList)9 SymbolUtils.toSymbolReference (io.prestosql.sql.planner.SymbolUtils.toSymbolReference)8 Identifier (io.prestosql.sql.tree.Identifier)8 InPredicate (io.prestosql.sql.tree.InPredicate)8 ProjectNode (io.prestosql.spi.plan.ProjectNode)7 BetweenPredicate (io.prestosql.sql.tree.BetweenPredicate)7 GenericLiteral (io.prestosql.sql.tree.GenericLiteral)7 ImmutableList (com.google.common.collect.ImmutableList)6 PlanNode (io.prestosql.spi.plan.PlanNode)6