use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class BridgingHiveMetastore method dropColumn.
@Override
public void dropColumn(String databaseName, String tableName, String columnName) {
verifyCanDropColumn(this, databaseName, tableName, columnName);
org.apache.hadoop.hive.metastore.api.Table table = delegate.getTable(identity, databaseName, tableName).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(databaseName, tableName)));
table.getSd().getCols().removeIf(fieldSchema -> fieldSchema.getName().equals(columnName));
alterTable(databaseName, tableName, table);
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class BridgingHiveMetastore method commentColumn.
@Override
public void commentColumn(String databaseName, String tableName, String columnName, Optional<String> comment) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(identity, databaseName, tableName);
if (source.isEmpty()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
for (FieldSchema fieldSchema : table.getSd().getCols()) {
if (fieldSchema.getName().equals(columnName)) {
if (comment.isPresent()) {
fieldSchema.setComment(comment.get());
} else {
fieldSchema.unsetComment();
}
}
}
alterTable(databaseName, tableName, table);
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class BridgingHiveMetastore method renameColumn.
@Override
public void renameColumn(String databaseName, String tableName, String oldColumnName, String newColumnName) {
Optional<org.apache.hadoop.hive.metastore.api.Table> source = delegate.getTable(identity, databaseName, tableName);
if (source.isEmpty()) {
throw new TableNotFoundException(new SchemaTableName(databaseName, tableName));
}
org.apache.hadoop.hive.metastore.api.Table table = source.get();
for (FieldSchema fieldSchema : table.getPartitionKeys()) {
if (fieldSchema.getName().equals(oldColumnName)) {
throw new TrinoException(NOT_SUPPORTED, "Renaming partition columns is not supported");
}
}
for (FieldSchema fieldSchema : table.getSd().getCols()) {
if (fieldSchema.getName().equals(oldColumnName)) {
fieldSchema.setName(newColumnName);
}
}
alterTable(databaseName, tableName, table);
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class IcebergMetadata method listTableColumns.
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
List<SchemaTableName> tables = prefix.getTable().map(ignored -> singletonList(prefix.toSchemaTableName())).orElseGet(() -> listTables(session, prefix.getSchema()));
ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
for (SchemaTableName table : tables) {
try {
columns.put(table, getTableMetadata(session, table).getColumns());
} catch (TableNotFoundException e) {
// table disappeared during listing operation
} catch (UnknownTableTypeException e) {
// ignore table of unknown type
} catch (RuntimeException e) {
// Table can be being removed and this may cause all sorts of exceptions. Log, because we're catching broadly.
log.warn(e, "Failed to access metadata of table %s during column listing for %s", table, prefix);
}
}
return columns.buildOrThrow();
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class IcebergMetadata method getTableHandle.
@Override
public IcebergTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) {
IcebergTableName name = IcebergTableName.from(tableName.getTableName());
verify(name.getTableType() == DATA, "Wrong table type: " + name.getTableNameWithType());
Table table;
try {
table = catalog.loadTable(session, new SchemaTableName(tableName.getSchemaName(), name.getTableName()));
} catch (TableNotFoundException e) {
return null;
}
Optional<Long> snapshotId = getSnapshotId(table, name.getSnapshotId());
String nameMappingJson = table.properties().get(TableProperties.DEFAULT_NAME_MAPPING);
return new IcebergTableHandle(tableName.getSchemaName(), name.getTableName(), name.getTableType(), snapshotId, TupleDomain.all(), TupleDomain.all(), ImmutableSet.of(), Optional.ofNullable(nameMappingJson));
}
Aggregations