Search in sources :

Example 16 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.

the class PhoenixMetadata method beginInsert.

@Override
public ConnectorInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle, List<ColumnHandle> columns) {
    JdbcTableHandle handle = (JdbcTableHandle) tableHandle;
    Optional<String> rowkeyColumn = phoenixClient.getColumns(session, handle).stream().map(JdbcColumnHandle::getColumnName).filter(ROWKEY::equalsIgnoreCase).findFirst();
    List<JdbcColumnHandle> columnHandles = columns.stream().map(JdbcColumnHandle.class::cast).collect(toImmutableList());
    return new PhoenixOutputTableHandle(handle.getSchemaName(), handle.getTableName(), columnHandles.stream().map(JdbcColumnHandle::getColumnName).collect(toImmutableList()), columnHandles.stream().map(JdbcColumnHandle::getColumnType).collect(toImmutableList()), Optional.of(columnHandles.stream().map(JdbcColumnHandle::getJdbcTypeHandle).collect(toImmutableList())), rowkeyColumn);
}
Also used : JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

Example 17 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.

the class PhoenixMetadata method dropColumn.

@Override
public void dropColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle column) {
    JdbcTableHandle handle = (JdbcTableHandle) tableHandle;
    JdbcColumnHandle columnHandle = (JdbcColumnHandle) column;
    phoenixClient.execute(session, format("ALTER TABLE %s DROP COLUMN %s", getEscapedTableName(handle.getSchemaName(), handle.getTableName()), columnHandle.getColumnName()));
}
Also used : JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

Example 18 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.

the class TestPostgreSqlConnectorTest method testStringPushdownWithCollate.

@Test
public void testStringPushdownWithCollate() {
    Session session = Session.builder(getSession()).setCatalogSessionProperty("postgresql", "enable_string_pushdown_with_collate", "true").build();
    // varchar range
    assertThat(query(session, "SELECT regionkey, nationkey, name FROM nation WHERE name BETWEEN 'POLAND' AND 'RPA'")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isFullyPushedDown();
    // varchar IN with small compaction threshold
    assertThat(query(Session.builder(session).setCatalogSessionProperty("postgresql", "domain_compaction_threshold", "1").build(), "SELECT regionkey, nationkey, name FROM nation WHERE name IN ('POLAND', 'ROMANIA', 'VIETNAM')")).matches("VALUES " + "(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25))), " + "(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar(25)))").isNotFullyPushedDown(node(FilterNode.class, tableScan(tableHandle -> {
        TupleDomain<ColumnHandle> constraint = ((JdbcTableHandle) tableHandle).getConstraint();
        ColumnHandle nameColumn = constraint.getDomains().orElseThrow().keySet().stream().map(JdbcColumnHandle.class::cast).filter(column -> column.getColumnName().equals("name")).collect(onlyElement());
        return constraint.getDomains().get().get(nameColumn).getValues().getRanges().getOrderedRanges().equals(ImmutableList.of(Range.range(createVarcharType(25), utf8Slice("POLAND"), true, utf8Slice("VIETNAM"), true)));
    }, TupleDomain.all(), ImmutableMap.of())));
    // varchar predicate over join
    Session joinPushdownEnabled = joinPushdownEnabled(session);
    assertThat(query(joinPushdownEnabled, "SELECT c.name, n.name FROM customer c JOIN nation n ON c.custkey = n.nationkey WHERE address < 'TcGe5gaZNgVePxU5kRrvXBfkasDTea'")).isFullyPushedDown();
    // join on varchar columns is not pushed down
    assertThat(query(joinPushdownEnabled, "SELECT c.name, n.name FROM customer c JOIN nation n ON c.address = n.name")).isNotFullyPushedDown(node(JoinNode.class, anyTree(node(TableScanNode.class)), anyTree(node(TableScanNode.class))));
}
Also used : Connection(java.sql.Connection) IntStream.range(java.util.stream.IntStream.range) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) TestTable(io.trino.testing.sql.TestTable) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) FilterNode(io.trino.sql.planner.plan.FilterNode) Duration(io.airlift.units.Duration) PlanMatchPattern.exchange(io.trino.sql.planner.assertions.PlanMatchPattern.exchange) Math.round(java.lang.Math.round) Map(java.util.Map) TestingConnectorBehavior(io.trino.testing.TestingConnectorBehavior) SqlExecutor(io.trino.testing.sql.SqlExecutor) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) JoinNode(io.trino.sql.planner.plan.JoinNode) Assert.assertFalse(org.testng.Assert.assertFalse) TableScanNode(io.trino.sql.planner.plan.TableScanNode) TestTable.randomTableSuffix(io.trino.testing.sql.TestTable.randomTableSuffix) ImmutableMap(com.google.common.collect.ImmutableMap) Range(io.trino.spi.predicate.Range) TestView(io.trino.testing.sql.TestView) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PostgreSqlQueryRunner.createPostgreSqlQueryRunner(io.trino.plugin.postgresql.PostgreSqlQueryRunner.createPostgreSqlQueryRunner) UUID(java.util.UUID) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) Stream(java.util.stream.Stream) PlanMatchPattern.anyTree(io.trino.sql.planner.assertions.PlanMatchPattern.anyTree) SUPPORTS_AGGREGATION_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_AGGREGATION_PUSHDOWN) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) Session(io.trino.Session) JoinCondition(io.trino.spi.connector.JoinCondition) Assert.assertEquals(org.testng.Assert.assertEquals) SUPPORTS_TOPN_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_TOPN_PUSHDOWN) JdbcSqlExecutor(io.trino.testing.sql.JdbcSqlExecutor) SQLException(java.sql.SQLException) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) SUPPORTS_LIMIT_PUSHDOWN(io.trino.testing.TestingConnectorBehavior.SUPPORTS_LIMIT_PUSHDOWN) ColumnHandle(io.trino.spi.connector.ColumnHandle) SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY(io.trino.testing.TestingConnectorBehavior.SUPPORTS_PREDICATE_PUSHDOWN_WITH_VARCHAR_EQUALITY) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) RemoteDatabaseEvent(io.trino.plugin.jdbc.RemoteDatabaseEvent) TopNNode(io.trino.sql.planner.plan.TopNNode) TupleDomain(io.trino.spi.predicate.TupleDomain) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest) PlanMatchPattern.node(io.trino.sql.planner.assertions.PlanMatchPattern.node) QueryRunner(io.trino.testing.QueryRunner) Statement(java.sql.Statement) Assert.assertTrue(org.testng.Assert.assertTrue) VarcharType.createVarcharType(io.trino.spi.type.VarcharType.createVarcharType) DriverManager(java.sql.DriverManager) PlanMatchPattern.tableScan(io.trino.sql.planner.assertions.PlanMatchPattern.tableScan) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ColumnHandle(io.trino.spi.connector.ColumnHandle) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) TableScanNode(io.trino.sql.planner.plan.TableScanNode) JoinNode(io.trino.sql.planner.plan.JoinNode) FilterNode(io.trino.sql.planner.plan.FilterNode) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) Session(io.trino.Session) Test(org.testng.annotations.Test) BaseJdbcConnectorTest(io.trino.plugin.jdbc.BaseJdbcConnectorTest)

Aggregations

JdbcTableHandle (io.trino.plugin.jdbc.JdbcTableHandle)18 JdbcColumnHandle (io.trino.plugin.jdbc.JdbcColumnHandle)13 Connection (java.sql.Connection)7 SQLException (java.sql.SQLException)7 List (java.util.List)7 ImmutableList (com.google.common.collect.ImmutableList)6 TrinoException (io.trino.spi.TrinoException)6 Optional (java.util.Optional)6 ColumnHandle (io.trino.spi.connector.ColumnHandle)5 ConnectorSession (io.trino.spi.connector.ConnectorSession)5 String.format (java.lang.String.format)5 Inject (javax.inject.Inject)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Slice (io.airlift.slice.Slice)3 Map (java.util.Map)3 Enums (com.google.common.base.Enums)2 Verify.verify (com.google.common.base.Verify.verify)2