use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class PhoenixMetadata method dropTable.
@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
// if we autogenerated a ROWKEY for this table, delete the associated sequence as well
boolean hasRowkey = getColumnHandles(session, tableHandle).values().stream().map(JdbcColumnHandle.class::cast).map(JdbcColumnHandle::getColumnName).anyMatch(ROWKEY::equals);
if (hasRowkey) {
JdbcTableHandle jdbcHandle = (JdbcTableHandle) tableHandle;
phoenixClient.execute(session, format("DROP SEQUENCE %s", getEscapedTableName(jdbcHandle.getSchemaName(), jdbcHandle.getTableName() + "_sequence")));
}
phoenixClient.dropTable(session, (JdbcTableHandle) tableHandle);
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class PhoenixSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy, DynamicFilter dynamicFilter) {
JdbcTableHandle tableHandle = (JdbcTableHandle) table;
try (Connection connection = phoenixClient.getConnection(session)) {
List<JdbcColumnHandle> columns = tableHandle.getColumns().map(columnSet -> columnSet.stream().map(JdbcColumnHandle.class::cast).collect(toList())).orElseGet(() -> phoenixClient.getColumns(session, tableHandle));
PhoenixPreparedStatement inputQuery = (PhoenixPreparedStatement) phoenixClient.prepareStatement(session, connection, tableHandle, columns, Optional.empty());
int maxScansPerSplit = session.getProperty(PhoenixSessionProperties.MAX_SCANS_PER_SPLIT, Integer.class);
List<ConnectorSplit> splits = getSplits(inputQuery, maxScansPerSplit).stream().map(PhoenixInputSplit.class::cast).map(split -> new PhoenixSplit(getSplitAddresses(split), SerializedPhoenixInputSplit.serialize(split))).collect(toImmutableList());
return new FixedSplitSource(splits);
} catch (IOException | SQLException e) {
throw new TrinoException(PHOENIX_SPLIT_ERROR, "Couldn't get Phoenix splits", e);
}
}
use of io.trino.plugin.jdbc.JdbcColumnHandle in project trino by trinodb.
the class PhoenixMetadata method dropTable.
@Override
public void dropTable(ConnectorSession session, ConnectorTableHandle tableHandle) {
// if we autogenerated a ROWKEY for this table, delete the associated sequence as well
boolean hasRowkey = getColumnHandles(session, tableHandle).values().stream().map(JdbcColumnHandle.class::cast).map(JdbcColumnHandle::getColumnName).anyMatch(ROWKEY::equals);
if (hasRowkey) {
JdbcTableHandle jdbcHandle = (JdbcTableHandle) tableHandle;
phoenixClient.execute(session, format("DROP SEQUENCE %s", getEscapedTableName(jdbcHandle.getSchemaName(), jdbcHandle.getTableName() + "_sequence")));
}
phoenixClient.dropTable(session, (JdbcTableHandle) tableHandle);
}
use of io.trino.plugin.jdbc.JdbcColumnHandle 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.JdbcColumnHandle 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()));
}
Aggregations