Search in sources :

Example 51 with RowExpression

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))));
}
Also used : LiteralEncoder.toRowExpression(com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) Test(org.testng.annotations.Test)

Example 52 with RowExpression

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);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 53 with RowExpression

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"));
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) Test(org.testng.annotations.Test)

Example 54 with RowExpression

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));
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression) Test(org.testng.annotations.Test)

Example 55 with RowExpression

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);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) OperatorFactory(com.facebook.presto.operator.OperatorFactory) DataSize(io.airlift.units.DataSize) Metadata(com.facebook.presto.metadata.Metadata) RowExpression(com.facebook.presto.spi.relation.RowExpression) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) FilterAndProjectOperator(com.facebook.presto.operator.FilterAndProjectOperator)

Aggregations

RowExpression (com.facebook.presto.spi.relation.RowExpression)237 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)97 Test (org.testng.annotations.Test)87 ImmutableList (com.google.common.collect.ImmutableList)58 CallExpression (com.facebook.presto.spi.relation.CallExpression)52 Map (java.util.Map)49 List (java.util.List)42 Type (com.facebook.presto.common.type.Type)41 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)40 ImmutableMap (com.google.common.collect.ImmutableMap)38 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)37 SpecialFormExpression (com.facebook.presto.spi.relation.SpecialFormExpression)35 Optional (java.util.Optional)35 Expression (com.facebook.presto.sql.tree.Expression)31 ColumnHandle (com.facebook.presto.spi.ColumnHandle)27 Objects.requireNonNull (java.util.Objects.requireNonNull)27 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)24 Set (java.util.Set)24 ArrayList (java.util.ArrayList)23