use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class CassandraSession method getTableMetadata.
private static AbstractTableMetadata getTableMetadata(KeyspaceMetadata keyspace, String caseInsensitiveTableName) {
List<AbstractTableMetadata> tables = Stream.concat(keyspace.getTables().stream(), keyspace.getMaterializedViews().stream()).filter(table -> table.getName().equalsIgnoreCase(caseInsensitiveTableName)).collect(toImmutableList());
if (tables.size() == 0) {
throw new TableNotFoundException(new SchemaTableName(keyspace.getName(), caseInsensitiveTableName));
}
if (tables.size() == 1) {
return tables.get(0);
}
String tableNames = tables.stream().map(AbstractTableMetadata::getName).sorted().collect(joining(", "));
throw new TrinoException(NOT_SUPPORTED, format("More than one table has been found for the case insensitive table name: %s -> (%s)", caseInsensitiveTableName, tableNames));
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class TestHiveGlueMetastore method createDummyPartitionedTable.
private void createDummyPartitionedTable(SchemaTableName tableName, List<ColumnMetadata> columns, List<String> partitionColumnNames, List<PartitionValues> partitionValues) throws Exception {
doCreateEmptyTable(tableName, ORC, columns, partitionColumnNames);
HiveMetastoreClosure metastoreClient = new HiveMetastoreClosure(getMetastoreClient());
Table table = metastoreClient.getTable(tableName.getSchemaName(), tableName.getTableName()).orElseThrow(() -> new TableNotFoundException(tableName));
List<PartitionWithStatistics> partitions = new ArrayList<>();
List<String> partitionNames = new ArrayList<>();
partitionValues.stream().map(partitionValue -> makePartName(partitionColumnNames, partitionValue.values)).forEach(partitionName -> {
partitions.add(new PartitionWithStatistics(createDummyPartition(table, partitionName), partitionName, PartitionStatistics.empty()));
partitionNames.add(partitionName);
});
metastoreClient.addPartitions(tableName.getSchemaName(), tableName.getTableName(), partitions);
partitionNames.forEach(partitionName -> metastoreClient.updatePartitionStatistics(tableName.getSchemaName(), tableName.getTableName(), partitionName, currentStatistics -> EMPTY_TABLE_STATISTICS));
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class InMemoryThriftMetastore method dropTable.
@Override
public synchronized void dropTable(HiveIdentity identity, String databaseName, String tableName, boolean deleteData) {
List<String> locations = listAllDataPaths(identity, this, databaseName, tableName);
SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
Table table = relations.remove(schemaTableName);
if (table == null) {
throw new TableNotFoundException(schemaTableName);
}
views.remove(schemaTableName);
partitions.keySet().removeIf(partitionName -> partitionName.matches(databaseName, tableName));
// remove data
if (deleteData && table.getTableType().equals(MANAGED_TABLE.name())) {
for (String location : locations) {
if (location != null) {
File directory = new File(new Path(location).toUri());
checkArgument(isParentDir(directory, baseDirectory), "Table directory must be inside of the metastore base directory");
deleteDirectory(directory);
}
}
}
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class HiveMetastoreBackedDeltaLakeMetastore method getTableLocation.
@Override
public String getTableLocation(SchemaTableName table, ConnectorSession session) {
Map<String, String> serdeParameters = getTable(table.getSchemaName(), table.getTableName()).orElseThrow(() -> new TableNotFoundException(table)).getStorage().getSerdeParameters();
String location = serdeParameters.get(PATH_PROPERTY);
if (location == null) {
throw new TrinoException(DELTA_LAKE_INVALID_SCHEMA, format("No %s property defined for table: %s", PATH_PROPERTY, table));
}
return location;
}
use of io.trino.spi.connector.TableNotFoundException in project trino by trinodb.
the class BaseJdbcClient method getColumns.
@Override
public List<JdbcColumnHandle> getColumns(ConnectorSession session, JdbcTableHandle tableHandle) {
if (tableHandle.getColumns().isPresent()) {
return tableHandle.getColumns().get();
}
checkArgument(tableHandle.isNamedRelation(), "Cannot get columns for %s", tableHandle);
SchemaTableName schemaTableName = tableHandle.getRequiredNamedRelation().getSchemaTableName();
RemoteTableName remoteTableName = tableHandle.getRequiredNamedRelation().getRemoteTableName();
try (Connection connection = connectionFactory.openConnection(session);
ResultSet resultSet = getColumns(tableHandle, connection.getMetaData())) {
int allColumns = 0;
List<JdbcColumnHandle> columns = new ArrayList<>();
while (resultSet.next()) {
// skip if table doesn't match expected
if (!(Objects.equals(remoteTableName, getRemoteTable(resultSet)))) {
continue;
}
allColumns++;
String columnName = resultSet.getString("COLUMN_NAME");
JdbcTypeHandle typeHandle = new JdbcTypeHandle(getInteger(resultSet, "DATA_TYPE").orElseThrow(() -> new IllegalStateException("DATA_TYPE is null")), Optional.ofNullable(resultSet.getString("TYPE_NAME")), getInteger(resultSet, "COLUMN_SIZE"), getInteger(resultSet, "DECIMAL_DIGITS"), Optional.empty(), Optional.empty());
Optional<ColumnMapping> columnMapping = toColumnMapping(session, connection, typeHandle);
log.debug("Mapping data type of '%s' column '%s': %s mapped to %s", schemaTableName, columnName, typeHandle, columnMapping);
boolean nullable = (resultSet.getInt("NULLABLE") != columnNoNulls);
// Note: some databases (e.g. SQL Server) do not return column remarks/comment here.
Optional<String> comment = Optional.ofNullable(emptyToNull(resultSet.getString("REMARKS")));
// skip unsupported column types
columnMapping.ifPresent(mapping -> columns.add(JdbcColumnHandle.builder().setColumnName(columnName).setJdbcTypeHandle(typeHandle).setColumnType(mapping.getType()).setNullable(nullable).setComment(comment).build()));
if (columnMapping.isEmpty()) {
UnsupportedTypeHandling unsupportedTypeHandling = getUnsupportedTypeHandling(session);
verify(unsupportedTypeHandling == IGNORE, "Unsupported type handling is set to %s, but toColumnMapping() returned empty for %s", unsupportedTypeHandling, typeHandle);
}
}
if (columns.isEmpty()) {
// A table may have no supported columns. In rare cases (e.g. PostgreSQL) a table might have no columns at all.
throw new TableNotFoundException(schemaTableName, format("Table '%s' has no supported columns (all %s columns are not supported)", schemaTableName, allColumns));
}
return ImmutableList.copyOf(columns);
} catch (SQLException e) {
throw new TrinoException(JDBC_ERROR, e);
}
}
Aggregations