Search in sources :

Example 11 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle 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);
}
Also used : JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

Example 12 with JdbcTableHandle

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

the class PhoenixMetadata method getTableProperties.

@Override
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle table) {
    JdbcTableHandle tableHandle = (JdbcTableHandle) table;
    List<LocalProperty<ColumnHandle>> sortingProperties = tableHandle.getSortOrder().map(properties -> properties.stream().map(item -> (LocalProperty<ColumnHandle>) new SortingProperty<ColumnHandle>(item.getColumn(), item.getSortOrder())).collect(toImmutableList())).orElse(ImmutableList.of());
    return new ConnectorTableProperties(TupleDomain.all(), Optional.empty(), Optional.empty(), Optional.empty(), sortingProperties);
}
Also used : ConnectorTableLayout(io.trino.spi.connector.ConnectorTableLayout) ConnectorInsertTableHandle(io.trino.spi.connector.ConnectorInsertTableHandle) Connection(java.sql.Connection) Slice(io.airlift.slice.Slice) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) AggregateFunction(io.trino.spi.connector.AggregateFunction) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) Inject(javax.inject.Inject) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) SQLException(java.sql.SQLException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ImmutableList(com.google.common.collect.ImmutableList) ConnectorOutputTableHandle(io.trino.spi.connector.ConnectorOutputTableHandle) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) PHOENIX_METADATA_ERROR(io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_METADATA_ERROR) SchemaUtil.getEscapedArgument(org.apache.phoenix.util.SchemaUtil.getEscapedArgument) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ComputedStatistics(io.trino.spi.statistics.ComputedStatistics) MetadataUtil.getEscapedTableName(io.trino.plugin.phoenix5.MetadataUtil.getEscapedTableName) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) MetadataUtil.toTrinoSchemaName(io.trino.plugin.phoenix5.MetadataUtil.toTrinoSchemaName) TupleDomain(io.trino.spi.predicate.TupleDomain) ConnectorOutputMetadata(io.trino.spi.connector.ConnectorOutputMetadata) SchemaTableName(io.trino.spi.connector.SchemaTableName) SortingProperty(io.trino.spi.connector.SortingProperty) String.format(java.lang.String.format) ConnectorTableSchema(io.trino.spi.connector.ConnectorTableSchema) AggregationApplicationResult(io.trino.spi.connector.AggregationApplicationResult) IdentifierMapping(io.trino.plugin.jdbc.mapping.IdentifierMapping) LocalProperty(io.trino.spi.connector.LocalProperty) List(java.util.List) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties) TrinoPrincipal(io.trino.spi.security.TrinoPrincipal) Optional(java.util.Optional) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) DefaultJdbcMetadata(io.trino.plugin.jdbc.DefaultJdbcMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) LocalProperty(io.trino.spi.connector.LocalProperty) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) ConnectorTableProperties(io.trino.spi.connector.ConnectorTableProperties)

Example 13 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle 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);
    }
}
Also used : ConnectorSplitManager(io.trino.spi.connector.ConnectorSplitManager) KeyRange(org.apache.phoenix.query.KeyRange) Connection(java.sql.Connection) Logger(io.airlift.log.Logger) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) QueryPlan(org.apache.phoenix.compile.QueryPlan) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) InputSplit(org.apache.hadoop.mapreduce.InputSplit) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TrinoException(io.trino.spi.TrinoException) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) IOException(java.io.IOException) ConnectorSession(io.trino.spi.connector.ConnectorSession) Scan(org.apache.hadoop.hbase.client.Scan) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DynamicFilter(io.trino.spi.connector.DynamicFilter) PHOENIX_INTERNAL_ERROR(io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_INTERNAL_ERROR) Optional(java.util.Optional) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) PHOENIX_SPLIT_ERROR(io.trino.plugin.phoenix5.PhoenixErrorCode.PHOENIX_SPLIT_ERROR) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) HostAddress(io.trino.spi.HostAddress) EXPECTED_UPPER_REGION_KEY(org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EXPECTED_UPPER_REGION_KEY) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) SQLException(java.sql.SQLException) Connection(java.sql.Connection) JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) IOException(java.io.IOException) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle) FixedSplitSource(io.trino.spi.connector.FixedSplitSource) PhoenixInputSplit(org.apache.phoenix.mapreduce.PhoenixInputSplit) TrinoException(io.trino.spi.TrinoException) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) ConnectorSplit(io.trino.spi.connector.ConnectorSplit)

Example 14 with JdbcTableHandle

use of io.trino.plugin.jdbc.JdbcTableHandle 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);
}
Also used : JdbcColumnHandle(io.trino.plugin.jdbc.JdbcColumnHandle) JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

Example 15 with JdbcTableHandle

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

the class PhoenixMetadata method addColumn.

@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
    JdbcTableHandle handle = (JdbcTableHandle) tableHandle;
    phoenixClient.execute(session, format("ALTER TABLE %s ADD %s %s", getEscapedTableName(handle.getSchemaName(), handle.getTableName()), column.getName(), phoenixClient.toWriteMapping(session, column.getType()).getDataType()));
}
Also used : JdbcTableHandle(io.trino.plugin.jdbc.JdbcTableHandle)

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