use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionInterpreter method evaluate.
private static Object evaluate(String expression) {
assertRoundTrip(expression);
Expression parsedExpression = FunctionAssertions.createExpression(expression, METADATA, SYMBOL_TYPES);
return evaluate(parsedExpression);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestExpressionVerifier method test.
@Test
public void test() {
Expression actual = expression("NOT(orderkey = 3 AND custkey = 3 AND orderkey < 10)");
SymbolAliases symbolAliases = SymbolAliases.builder().put("X", new SymbolReference("orderkey")).put("Y", new SymbolReference("custkey")).build();
ExpressionVerifier verifier = new ExpressionVerifier(symbolAliases);
assertTrue(verifier.process(actual, expression("NOT(X = 3 AND Y = 3 AND X < 10)")));
assertThrows(() -> verifier.process(actual, expression("NOT(X = 3 AND Y = 3 AND Z < 10)")));
assertFalse(verifier.process(actual, expression("NOT(X = 3 AND X = 3 AND X < 10)")));
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testTableScan.
@Test
public void testTableScan() {
// Effective predicate is True if there is no effective predicate
Map<Symbol, ColumnHandle> assignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C, D)));
PlanNode node = TableScanNode.newInstance(newId(), makeTableHandle(TupleDomain.all()), ImmutableList.copyOf(assignments.keySet()), assignments, ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL);
node = new TableScanNode(newId(), makeTableHandle(TupleDomain.none()), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.none(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(effectivePredicate, FALSE_LITERAL);
TupleDomain<ColumnHandle> predicate = TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L)));
node = new TableScanNode(newId(), makeTableHandle(predicate), ImmutableList.copyOf(assignments.keySet()), assignments, predicate, Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(1L), AE)));
predicate = TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L), scanAssignments.get(B), Domain.singleValue(BIGINT, 2L)));
node = new TableScanNode(newId(), makeTableHandle(TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L)))), ImmutableList.copyOf(assignments.keySet()), assignments, predicate, Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractorWithoutTableProperties.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(bigintLiteral(2L), BE), equals(bigintLiteral(1L), AE)));
node = new TableScanNode(newId(), makeTableHandle(predicate), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(effectivePredicate, and(equals(AE, bigintLiteral(1)), equals(BE, bigintLiteral(2))));
node = new TableScanNode(newId(), makeTableHandle(predicate), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L)), scanAssignments.get(B), Domain.multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L)))), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjunctsSet(equals(bigintLiteral(2L), BE), equals(bigintLiteral(1L), AE)));
node = new TableScanNode(newId(), makeTableHandle(TupleDomain.all()), ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), Optional.empty(), ReuseExchangeOperator.STRATEGY.REUSE_STRATEGY_DEFAULT, new UUID(0, 0), 0, false);
effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testGroupByEmpty.
@Test
public void testGroupByEmpty() {
PlanNode node = new AggregationNode(newId(), filter(baseTableScan, FALSE_LITERAL), ImmutableMap.of(), globalAggregation(), ImmutableList.of(), AggregationNode.Step.FINAL, Optional.empty(), Optional.empty(), AggregationNode.AggregationType.HASH, Optional.empty());
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
assertEquals(effectivePredicate, TRUE_LITERAL);
}
use of io.prestosql.sql.tree.Expression in project hetu-core by openlookeng.
the class TestEffectivePredicateExtractor method testFilter.
@Test
public void testFilter() {
PlanNode node = filter(baseTableScan, and(greaterThan(AE, new FunctionCallBuilder(metadata).setName(QualifiedName.of("rand")).build()), lessThan(BE, bigintLiteral(10))));
Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
// Non-deterministic functions should be purged
assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10))));
}
Aggregations