use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.
the class DruidJdbcClient method prepareTableHandleForQuery.
private JdbcTableHandle prepareTableHandleForQuery(JdbcTableHandle table) {
if (table.isNamedRelation()) {
String schemaName = table.getSchemaName();
checkArgument("druid".equals(schemaName), "Only \"druid\" schema is supported");
table = new JdbcTableHandle(new JdbcNamedRelationHandle(table.getRequiredNamedRelation().getSchemaTableName(), // Druid doesn't like table names to be qualified with catalog names in the SQL query, hence we null out the catalog.
new RemoteTableName(Optional.empty(), table.getRequiredNamedRelation().getRemoteTableName().getSchemaName(), table.getRequiredNamedRelation().getRemoteTableName().getTableName()), Optional.empty()), table.getConstraint(), table.getConstraintExpressions(), table.getSortOrder(), table.getLimit(), table.getColumns(), table.getOtherReferencedTables(), table.getNextSyntheticColumnId());
}
return table;
}
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);
}
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()));
}
use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.
the class SqlServerClient method getTableDataCompressionWithRetries.
private static Optional<DataCompression> getTableDataCompressionWithRetries(Handle handle, JdbcTableHandle table) {
// DDL operations can take out locks against system tables causing the `getTableDataCompression` query to deadlock
final int maxAttemptCount = 3;
RetryPolicy<Optional<DataCompression>> retryPolicy = new RetryPolicy<Optional<DataCompression>>().withMaxAttempts(maxAttemptCount).handleIf(throwable -> {
final int deadlockErrorCode = 1205;
Throwable rootCause = Throwables.getRootCause(throwable);
return rootCause instanceof SQLServerException && ((SQLServerException) (rootCause)).getSQLServerError().getErrorNumber() == deadlockErrorCode;
}).onFailedAttempt(event -> log.warn(event.getLastFailure(), "Attempt %d of %d: error when getting table compression info for '%s'", event.getAttemptCount(), maxAttemptCount, table));
return Failsafe.with(retryPolicy).get(() -> getTableDataCompression(handle, table));
}
use of io.trino.plugin.jdbc.JdbcTableHandle in project trino by trinodb.
the class BaseSqlServerConnectorTest method testPredicatePushdown.
@Test
public void testPredicatePushdown() {
// varchar equality
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name = 'ROMANIA'")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isNotFullyPushedDown(FilterNode.class);
// varchar range
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name BETWEEN 'POLAND' AND 'RPA'")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isNotFullyPushedDown(FilterNode.class);
// varchar IN without domain compaction
assertThat(query("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, // verify that pushed down constraint is applied by the connector
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).equals(Domain.multipleValues(createVarcharType(25), ImmutableList.of(utf8Slice("POLAND"), utf8Slice("ROMANIA"), utf8Slice("VIETNAM"))));
}, TupleDomain.all(), ImmutableMap.of())));
// varchar IN with small compaction threshold
assertThat(query(Session.builder(getSession()).setCatalogSessionProperty("sqlserver", "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, // verify that no constraint is applied by the connector
tableScan(tableHandle -> ((JdbcTableHandle) tableHandle).getConstraint().isAll(), TupleDomain.all(), ImmutableMap.of())));
// varchar different case
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE name = 'romania'")).returnsEmptyResult().isNotFullyPushedDown(FilterNode.class);
// bigint equality
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE nationkey = 19")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isFullyPushedDown();
// bigint equality with small compaction threshold
assertThat(query(Session.builder(getSession()).setCatalogSessionProperty("sqlserver", "domain_compaction_threshold", "1").build(), "SELECT regionkey, nationkey, name FROM nation WHERE nationkey IN (19, 21)")).matches("VALUES " + "(BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25))), " + "(BIGINT '2', BIGINT '21', CAST('VIETNAM' AS varchar(25)))").isNotFullyPushedDown(FilterNode.class);
// bigint range, with decimal to bigint simplification
assertThat(query("SELECT regionkey, nationkey, name FROM nation WHERE nationkey BETWEEN 18.5 AND 19.5")).matches("VALUES (BIGINT '3', BIGINT '19', CAST('ROMANIA' AS varchar(25)))").isFullyPushedDown();
// date equality
assertThat(query("SELECT orderkey FROM orders WHERE orderdate = DATE '1992-09-29'")).matches("VALUES BIGINT '1250', 34406, 38436, 57570").isFullyPushedDown();
// predicate over aggregation key (likely to be optimized before being pushed down into the connector)
assertThat(query("SELECT * FROM (SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey) WHERE regionkey = 3")).matches("VALUES (BIGINT '3', BIGINT '77')").isFullyPushedDown();
// predicate over aggregation result
assertThat(query("SELECT regionkey, sum(nationkey) FROM nation GROUP BY regionkey HAVING sum(nationkey) = 77")).matches("VALUES (BIGINT '3', BIGINT '77')").isFullyPushedDown();
// decimals
try (TestTable testTable = new TestTable(onRemoteDatabase(), "test_decimal_pushdown", "(short_decimal decimal(9, 3), long_decimal decimal(30, 10))", List.of("123.321, 123456789.987654321"))) {
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE short_decimal <= 124")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE short_decimal <= 124")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE long_decimal <= 123456790")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE short_decimal <= 123.321")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE long_decimal <= 123456789.987654321")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE short_decimal = 123.321")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
assertThat(query("SELECT * FROM " + testTable.getName() + " WHERE long_decimal = 123456789.987654321")).matches("VALUES (CAST(123.321 AS decimal(9,3)), CAST(123456789.987654321 AS decimal(30, 10)))").isFullyPushedDown();
}
}
Aggregations