use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestRowExpressionDomainTranslator method testConjunctExpression.
@Test
public void testConjunctExpression() {
RowExpression expression = and(greaterThan(C_DOUBLE, doubleLiteral(0)), greaterThan(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(greaterThan(C_DOUBLE, doubleLiteral(0)), greaterThan(C_BIGINT, bigintLiteral(0))));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestRowExpressionRewriter method testSimple.
@Test
public void testSimple() {
// successful rewrite
RowExpression predicate = call(GREATER_THAN.name(), functionAndTypeManager.resolveOperator(GREATER_THAN, fromTypes(BIGINT, BIGINT)), BOOLEAN, constant(1L, BIGINT), constant(2L, BIGINT));
RowExpression negatedPredicate = rewrite(predicate);
assertEquals(negatedPredicate.getType(), BOOLEAN);
assertTrue(negatedPredicate instanceof CallExpression);
assertTrue(((CallExpression) negatedPredicate).getArguments().get(0) instanceof CallExpression);
assertEquals(((CallExpression) negatedPredicate).getDisplayName(), "not");
assertEquals(((CallExpression) ((CallExpression) negatedPredicate).getArguments().get(0)).getDisplayName(), GREATER_THAN.name());
// no rewrite
RowExpression nonPredicate = call(ADD.name(), functionAndTypeManager.resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, constant(1L, BIGINT), constant(2L, BIGINT));
RowExpression samePredicate = rewrite(nonPredicate);
assertEquals(samePredicate, nonPredicate);
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEqualityInference method testTriviallyRewritable.
@Test
public void testTriviallyRewritable() {
EqualityInference.Builder builder = new EqualityInference.Builder(METADATA);
RowExpression expression = builder.build().rewriteExpression(someExpression("a1", "a2"), matchesVariables("a1", "a2"));
assertEquals(expression, someExpression("a1", "a2"));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class TestEqualityInference method testTransitivity.
@Test
public void testTransitivity() {
EqualityInference.Builder builder = new EqualityInference.Builder(METADATA);
addEquality("a1", "b1", builder);
addEquality("b1", "c1", builder);
addEquality("d1", "c1", builder);
addEquality("a2", "b2", builder);
addEquality("b2", "a2", builder);
addEquality("b2", "c2", builder);
addEquality("d2", "b2", builder);
addEquality("c2", "d2", builder);
EqualityInference inference = builder.build();
assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesVariables("d1", "d2")), someExpression("d1", "d2"));
assertEquals(inference.rewriteExpression(someExpression("a1", "c1"), matchesVariables("b1")), someExpression("b1", "b1"));
assertEquals(inference.rewriteExpression(someExpression("a1", "a2"), matchesVariables("b1", "d2", "c3")), someExpression("b1", "d2"));
// Both starting expressions should canonicalize to the same expression
assertEquals(inference.getScopedCanonical(variable("a2"), matchesVariables("c2", "d2")), inference.getScopedCanonical(variable("b2"), matchesVariables("c2", "d2")));
RowExpression canonical = inference.getScopedCanonical(variable("a2"), matchesVariables("c2", "d2"));
// Given multiple translatable candidates, should choose the canonical
assertEquals(inference.rewriteExpression(someExpression("a2", "b2"), matchesVariables("c2", "d2")), someExpression(canonical, canonical));
}
use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.
the class PredicateFilterBenchmark method createOperatorFactories.
@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
Metadata metadata = localQueryRunner.getMetadata();
OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "totalprice");
RowExpression filter = call(GREATER_THAN_OR_EQUAL.name(), metadata.getFunctionAndTypeManager().resolveOperator(GREATER_THAN_OR_EQUAL, fromTypes(DOUBLE, DOUBLE)), BOOLEAN, field(0, DOUBLE), constant(50000.0, DOUBLE));
ExpressionCompiler expressionCompiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
Supplier<PageProcessor> pageProcessor = expressionCompiler.compilePageProcessor(localQueryRunner.getDefaultSession().getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, DOUBLE)));
FilterAndProjectOperator.FilterAndProjectOperatorFactory filterAndProjectOperator = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(1, new PlanNodeId("test"), pageProcessor, ImmutableList.of(DOUBLE), new DataSize(0, BYTE), 0);
return ImmutableList.of(tableScanOperator, filterAndProjectOperator);
}
Aggregations