Search in sources :

Example 11 with ExtractionResult

use of com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult in project presto by prestodb.

the class TestRowExpressionDomainTranslator method assertPredicateIsAlwaysFalse.

private void assertPredicateIsAlwaysFalse(RowExpression expression) {
    ExtractionResult result = fromPredicate(expression);
    assertEquals(result.getRemainingExpression(), TRUE_CONSTANT);
    assertTrue(result.getTupleDomain().isNone());
}
Also used : ExtractionResult(com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult)

Example 12 with ExtractionResult

use of com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult in project presto by prestodb.

the class TestRowExpressionDomainTranslator method testExpressionConstantFolding.

@Test
public void testExpressionConstantFolding() {
    FunctionHandle hex = metadata.getFunctionAndTypeManager().lookupFunction("from_hex", fromTypes(VARCHAR));
    RowExpression originalExpression = greaterThan(C_VARBINARY, call("from_hex", hex, VARBINARY, stringLiteral("123456")));
    ExtractionResult result = fromPredicate(originalExpression);
    assertEquals(result.getRemainingExpression(), TRUE_CONSTANT);
    Slice value = Slices.wrappedBuffer(BaseEncoding.base16().decode("123456"));
    assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(C_VARBINARY, Domain.create(ValueSet.ofRanges(Range.greaterThan(VARBINARY, value)), false))));
    RowExpression expression = toPredicate(result.getTupleDomain());
    assertEquals(expression, greaterThan(C_VARBINARY, varbinaryLiteral(value)));
}
Also used : Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) Slice(io.airlift.slice.Slice) LiteralEncoder.toRowExpression(com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) ExtractionResult(com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

ExtractionResult (com.facebook.presto.spi.relation.DomainTranslator.ExtractionResult)12 Test (org.testng.annotations.Test)7 RowExpression (com.facebook.presto.spi.relation.RowExpression)5 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)5 LiteralEncoder.toRowExpression (com.facebook.presto.sql.planner.LiteralEncoder.toRowExpression)4 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)3 Logger (com.facebook.airlift.log.Logger)1 Session (com.facebook.presto.Session)1 QualifiedObjectName (com.facebook.presto.common.QualifiedObjectName)1 Domain (com.facebook.presto.common.predicate.Domain)1 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)1 LogicalRowExpressions.and (com.facebook.presto.expressions.LogicalRowExpressions.and)1 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)1 Metadata (com.facebook.presto.metadata.Metadata)1 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)1 AccessControl (com.facebook.presto.security.AccessControl)1 ColumnHandle (com.facebook.presto.spi.ColumnHandle)1 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)1 TableHandle (com.facebook.presto.spi.TableHandle)1 WarningCollector (com.facebook.presto.spi.WarningCollector)1