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)));
}
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)));
}
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();
}
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")));
}
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;
}
Aggregations