Search in sources :

Example 1 with JdbcTableLayoutHandle

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

the class TestJdbcComputePushdown method testJdbcComputePushdownBooleanOperations.

@Test
public void testJdbcComputePushdownBooleanOperations() {
    String table = "test_table";
    String schema = "test_schema";
    String expression = "(((c1 + c2) - c2 <> c2) OR c2 = c1) AND c1 <> 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') <> 'c2')) OR (('c2' = 'c1')))) AND (('c1' <> '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)

Example 2 with JdbcTableLayoutHandle

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

the class TestJdbcComputePushdown method testJdbcComputePushdownUnsupported.

@Test
public void testJdbcComputePushdownUnsupported() {
    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());
    // Test should expect an empty entry for translatedSql since > is an unsupported function currently in the optimizer
    JdbcTableLayoutHandle jdbcTableLayoutHandle = new JdbcTableLayoutHandle(session.getSqlFunctionProperties(), jdbcTableHandle, TupleDomain.none(), Optional.empty());
    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)

Example 3 with JdbcTableLayoutHandle

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

the class TestJdbcComputePushdown method jdbcTableScan.

private TableScanNode jdbcTableScan(String schema, String table, Type type, String... columnNames) {
    JdbcTableHandle jdbcTableHandle = new JdbcTableHandle(CONNECTOR_ID, new SchemaTableName(schema, table), CATALOG_NAME, schema, table);
    JdbcTableLayoutHandle jdbcTableLayoutHandle = new JdbcTableLayoutHandle(TEST_SESSION.getSqlFunctionProperties(), jdbcTableHandle, TupleDomain.none(), Optional.empty());
    TableHandle tableHandle = new TableHandle(new ConnectorId(CATALOG_NAME), jdbcTableHandle, new ConnectorTransactionHandle() {
    }, Optional.of(jdbcTableLayoutHandle));
    return PLAN_BUILDER.tableScan(tableHandle, Arrays.stream(columnNames).map(column -> newVariable(column, type)).collect(toImmutableList()), Arrays.stream(columnNames).map(column -> newVariable(column, type)).collect(toMap(identity(), entry -> getColumnHandleForVariable(entry.getName(), type))));
}
Also used : JdbcTableLayoutHandle(com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TableHandle(com.facebook.presto.spi.TableHandle) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorId(com.facebook.presto.spi.ConnectorId)

Example 4 with JdbcTableLayoutHandle

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

the class TestJdbcComputePushdown method testJdbcComputePushdownNotOperator.

@Test
public void testJdbcComputePushdownNotOperator() {
    String table = "test_table";
    String schema = "test_schema";
    String expression = "c1 AND NOT(c2)";
    TypeProvider typeProvider = TypeProvider.copyOf(ImmutableMap.of("c1", BOOLEAN, "c2", BOOLEAN));
    RowExpression rowExpression = sqlToRowExpressionTranslator.translateAndOptimize(expression(expression), typeProvider);
    PlanNode original = filter(jdbcTableScan(schema, table, BOOLEAN, "c1", "c2"), rowExpression);
    Set<ColumnHandle> columns = Stream.of("c1", "c2").map(TestJdbcComputePushdown::booleanJdbcColumnHandle).collect(Collectors.toSet());
    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') AND ((NOT('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)

Example 5 with JdbcTableLayoutHandle

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

the class TestJdbcComputePushdown method testJdbcComputePushdownWithConstants.

@Test
public void testJdbcComputePushdownWithConstants() {
    String table = "test_table";
    String schema = "test_schema";
    String expression = "(c1 + c2) = 3";
    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') = ?)", ImmutableList.of(new ConstantExpression(Long.valueOf(3), INTEGER)))));
    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) JdbcTableLayoutHandle(com.facebook.presto.plugin.jdbc.JdbcTableLayoutHandle) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) RowExpression(com.facebook.presto.spi.relation.RowExpression) JdbcTableHandle(com.facebook.presto.plugin.jdbc.JdbcTableHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) PlanNode(com.facebook.presto.spi.plan.PlanNode) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) 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