Search in sources :

Example 6 with JdbcTableLayoutHandle

use of com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle in project presto by prestodb.

the class TestJdbcComputePushdown method testJdbcComputePushdownAll.

@Test
public void testJdbcComputePushdownAll() {
    String table = "test_table";
    String schema = "test_schema";
    String expression = "(c1 + c2) - c2";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("c1", BIGINT, "c2", BIGINT));
    RowExpression rowExpression = sqlToRowExpressionTranslator.translateAndOptimize(expression(expression), typeProvider);
    Set<ColumnHandle> columns = Stream.of("c1", "c2").map(TestJdbcComputePushdown::integerJdbcColumnHandle).collect(Collectors.toSet());
    PlanNode original = filter(jdbcTableScan(schema, table, BIGINT, "c1", "c2"), rowExpression);
    JdbcTableHandle jdbcTableHandle = new JdbcTableHandle(CONNECTOR_ID, new SchemaTableName(schema, table), CATALOG_NAME, schema, table);
    ConnectorSession session = new TestingConnectorSession(ImmutableList.of());
    JdbcTableLayoutHandle jdbcTableLayoutHandle = new JdbcTableLayoutHandle(session.getSqlFunctionProperties(), jdbcTableHandle, TupleDomain.none(), Optional.of(new JdbcExpression("(('c1' + 'c2') - 'c2')")));
    PlanNode actual = this.jdbcComputePushdown.optimize(original, session, null, ID_ALLOCATOR);
    assertPlanMatch(actual, PlanMatchPattern.filter(expression, JdbcTableScanMatcher.jdbcTableScanPattern(jdbcTableLayoutHandle, columns)));
}
Also used : JdbcColumnHandle(com.facebook.presto.plugin.jdbc.JdbcColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) PlanNode(com.facebook.presto.spi.plan.PlanNode) JdbcTableLayoutHandle(com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Aggregations

JdbcTableHandle (com.facebook.presto.plugin.jdbc.JdbcTableHandle)6 JdbcTableLayoutHandle (com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle)6 SchemaTableName (com.facebook.presto.spi.SchemaTableName)6 JdbcColumnHandle (com.facebook.presto.plugin.jdbc.JdbcColumnHandle)5 ColumnHandle (com.facebook.presto.spi.ColumnHandle)5 ConnectorSession (com.facebook.presto.spi.ConnectorSession)5 PlanNode (com.facebook.presto.spi.plan.PlanNode)5 RowExpression (com.facebook.presto.spi.relation.RowExpression)5 TypeProvider (com.facebook.presto.sql.planner.TypeProvider)5 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)5 Test (org.testng.annotations.Test)5 ConnectorId (com.facebook.presto.spi.ConnectorId)1 TableHandle (com.facebook.presto.spi.TableHandle)1 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)1 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)1