Search in sources :

Example 1 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestRemoveUnsupportedDynamicFilters method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    builder = new PlanBuilder(getQueryRunner().getDefaultSession(), new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(connectorId, new TpchTableHandle("lineitem", 1.0), TestingTransactionHandle.create(), Optional.empty());
    lineitemOrderKeyVariable = builder.variable("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeyVariable), ImmutableMap.of(lineitemOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(connectorId, new TpchTableHandle("orders", 1.0), TestingTransactionHandle.create(), Optional.empty());
    ordersOrderKeyVariable = builder.variable("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeyVariable), ImmutableMap.of(ordersOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestDynamicFiltersChecker method setup.

@BeforeClass
public void setup() {
    metadata = getQueryRunner().getMetadata();
    logicalRowExpressions = new LogicalRowExpressions(new RowExpressionDeterminismEvaluator(metadata.getFunctionAndTypeManager()), new FunctionResolution(metadata.getFunctionAndTypeManager()), metadata.getFunctionAndTypeManager());
    builder = new PlanBuilder(getQueryRunner().getDefaultSession(), new PlanNodeIdAllocator(), metadata);
    ConnectorId connectorId = getCurrentConnectorId();
    TableHandle lineitemTableHandle = new TableHandle(connectorId, new TpchTableHandle("lineitem", 1.0), TestingTransactionHandle.create(), Optional.empty());
    lineitemOrderKeyVariable = builder.variable("LINEITEM_OK", BIGINT);
    lineitemTableScanNode = builder.tableScan(lineitemTableHandle, ImmutableList.of(lineitemOrderKeyVariable), ImmutableMap.of(lineitemOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
    TableHandle ordersTableHandle = new TableHandle(connectorId, new TpchTableHandle("orders", 1.0), TestingTransactionHandle.create(), Optional.empty());
    ordersOrderKeyVariable = builder.variable("ORDERS_OK", BIGINT);
    ordersTableScanNode = builder.tableScan(ordersTableHandle, ImmutableList.of(ordersOrderKeyVariable), ImmutableMap.of(ordersOrderKeyVariable, new TpchColumnHandle("orderkey", BIGINT)));
}
Also used : RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) PlanNodeIdAllocator(com.facebook.presto.spi.plan.PlanNodeIdAllocator) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) TableHandle(com.facebook.presto.spi.TableHandle) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanBuilder(com.facebook.presto.sql.planner.iterative.rule.test.PlanBuilder) ConnectorId(com.facebook.presto.spi.ConnectorId) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestDomainTranslator method setup.

@BeforeClass
public void setup() {
    metadata = createTestMetadataManager();
    domainTranslator = new RowExpressionDomainTranslator(metadata);
    columnExtractor = new SubfieldExtractor(new FunctionResolution(metadata.getFunctionAndTypeManager()), TEST_EXPRESSION_OPTIMIZER, new TestingConnectorSession(new HiveSessionProperties(new HiveClientConfig().setRangeFiltersOnSubscriptsEnabled(true), new OrcFileWriterConfig(), new ParquetFileWriterConfig(), new CacheConfig()).getSessionProperties())).toColumnExtractor();
}
Also used : RowExpressionDomainTranslator(com.facebook.presto.sql.relational.RowExpressionDomainTranslator) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) CacheConfig(com.facebook.presto.cache.CacheConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestHiveLogicalPlanner method testPushdownFilter.

@Test
public void testPushdownFilter() {
    Session pushdownFilterEnabled = pushdownFilterEnabled();
    // Only domain predicates
    assertPlan("SELECT linenumber FROM lineitem WHERE partkey = 10", output(exchange(project(filter("partkey = 10", strictTableScan("lineitem", identityMap("linenumber", "partkey")))))));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE partkey = 10", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), TRUE_CONSTANT, ImmutableSet.of("partkey")));
    assertPlan(pushdownFilterEnabled, "SELECT partkey, linenumber FROM lineitem WHERE partkey = 10", output(exchange(strictTableScan("lineitem", identityMap("partkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), TRUE_CONSTANT, ImmutableSet.of("partkey")));
    // Only remaining predicate
    assertPlan("SELECT linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(project(filter("mod(orderkey, 2) = 1", strictTableScan("lineitem", identityMap("linenumber", "orderkey")))))));
    // Remaining predicate is NULL
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE cardinality(NULL) > 0", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey > 10 AND cardinality(NULL) > 0", output(values("linenumber")));
    // Remaining predicate is always FALSE
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE cardinality(ARRAY[1]) > 1", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey > 10 AND cardinality(ARRAY[1]) > 1", output(values("linenumber")));
    // TupleDomain predicate is always FALSE
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey = 1 AND orderkey = 2", output(values("linenumber")));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE orderkey = 1 AND orderkey = 2 AND linenumber % 2 = 1", output(values("linenumber")));
    FunctionAndTypeManager functionAndTypeManager = getQueryRunner().getMetadata().getFunctionAndTypeManager();
    FunctionResolution functionResolution = new FunctionResolution(functionAndTypeManager);
    RowExpression remainingPredicate = new CallExpression(EQUAL.name(), functionResolution.comparisonFunction(EQUAL, BIGINT, BIGINT), BOOLEAN, ImmutableList.of(new CallExpression("mod", functionAndTypeManager.lookupFunction("mod", fromTypes(BIGINT, BIGINT)), BIGINT, ImmutableList.of(new VariableReferenceExpression(Optional.empty(), "orderkey", BIGINT), constant(2))), constant(1)));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", TupleDomain.all(), remainingPredicate, ImmutableSet.of("orderkey")));
    assertPlan(pushdownFilterEnabled, "SELECT orderkey, linenumber FROM lineitem WHERE mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("orderkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", TupleDomain.all(), remainingPredicate, ImmutableSet.of("orderkey")));
    // A mix of domain and remaining predicates
    assertPlan("SELECT linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(project(filter("partkey = 10 AND mod(orderkey, 2) = 1", strictTableScan("lineitem", identityMap("linenumber", "orderkey", "partkey")))))));
    assertPlan(pushdownFilterEnabled, "SELECT linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), remainingPredicate, ImmutableSet.of("partkey", "orderkey")));
    assertPlan(pushdownFilterEnabled, "SELECT partkey, orderkey, linenumber FROM lineitem WHERE partkey = 10 AND mod(orderkey, 2) = 1", output(exchange(strictTableScan("lineitem", identityMap("partkey", "orderkey", "linenumber")))), plan -> assertTableLayout(plan, "lineitem", withColumnDomains(ImmutableMap.of(new Subfield("partkey", ImmutableList.of()), singleValue(BIGINT, 10L))), remainingPredicate, ImmutableSet.of("partkey", "orderkey")));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) CallExpression(com.facebook.presto.spi.relation.CallExpression) ParquetTypeUtils.pushdownColumnNameForSubfield(com.facebook.presto.parquet.ParquetTypeUtils.pushdownColumnNameForSubfield) HiveColumnHandle.isPushedDownSubfield(com.facebook.presto.hive.HiveColumnHandle.isPushedDownSubfield) Subfield(com.facebook.presto.common.Subfield) Session(com.facebook.presto.Session) Test(org.testng.annotations.Test)

Example 5 with FunctionResolution

use of com.facebook.presto.sql.relational.FunctionResolution in project presto by prestodb.

the class TestExpressionInterpreter method isRemovableCast.

private static boolean isRemovableCast(Object value) {
    if (value instanceof CallExpression && new FunctionResolution(METADATA.getFunctionAndTypeManager()).isCastFunction(((CallExpression) value).getFunctionHandle())) {
        Type targetType = ((CallExpression) value).getType();
        Type sourceType = ((CallExpression) value).getArguments().get(0).getType();
        return METADATA.getFunctionAndTypeManager().canCoerce(sourceType, targetType);
    }
    return false;
}
Also used : VarbinaryType(com.facebook.presto.common.type.VarbinaryType) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) DecimalType.createDecimalType(com.facebook.presto.common.type.DecimalType.createDecimalType) CallExpression(com.facebook.presto.spi.relation.CallExpression) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution)

Aggregations

FunctionResolution (com.facebook.presto.sql.relational.FunctionResolution)16 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)8 RowExpressionDeterminismEvaluator (com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator)7 LogicalRowExpressions (com.facebook.presto.expressions.LogicalRowExpressions)5 ImmutableList (com.google.common.collect.ImmutableList)5 Optional (java.util.Optional)5 BeforeClass (org.testng.annotations.BeforeClass)5 Test (org.testng.annotations.Test)5 Session (com.facebook.presto.Session)4 TableHandle (com.facebook.presto.spi.TableHandle)4 RowExpression (com.facebook.presto.spi.relation.RowExpression)4 Expressions.call (com.facebook.presto.sql.relational.Expressions.call)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 VarcharType.createVarcharType (com.facebook.presto.common.type.VarcharType.createVarcharType)3 Metadata (com.facebook.presto.metadata.Metadata)3 Expressions.constant (com.facebook.presto.sql.relational.Expressions.constant)3 RowExpressionDomainTranslator (com.facebook.presto.sql.relational.RowExpressionDomainTranslator)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)2