diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/SchemaAlreadyExistsException.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/SchemaAlreadyExistsException.java index 5511366ddecc..8bff8da39a12 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/SchemaAlreadyExistsException.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/SchemaAlreadyExistsException.java @@ -25,12 +25,17 @@ public class SchemaAlreadyExistsException public SchemaAlreadyExistsException(String schemaName) { - this(schemaName, format("Schema already exists: '%s'", schemaName)); + this(schemaName, null); } - public SchemaAlreadyExistsException(String schemaName, String message) + public SchemaAlreadyExistsException(String schemaName, Throwable cause) { - super(ALREADY_EXISTS, message); + this(schemaName, format("Schema already exists: '%s'", schemaName), cause); + } + + public SchemaAlreadyExistsException(String schemaName, String message, Throwable cause) + { + super(ALREADY_EXISTS, message, cause); this.schemaName = schemaName; } diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TableAlreadyExistsException.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TableAlreadyExistsException.java index 157e0744f8c1..ff0e9fdae2bb 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TableAlreadyExistsException.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/TableAlreadyExistsException.java @@ -26,12 +26,12 @@ public class TableAlreadyExistsException public TableAlreadyExistsException(SchemaTableName tableName) { - this(tableName, format("Table already exists: '%s'", tableName)); + this(tableName, null); } - public TableAlreadyExistsException(SchemaTableName tableName, String message) + public TableAlreadyExistsException(SchemaTableName tableName, Throwable cause) { - this(tableName, message, null); + this(tableName, format("Table already exists: '%s'", tableName), cause); } public TableAlreadyExistsException(SchemaTableName tableName, String message, Throwable cause) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueHiveMetastore.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueHiveMetastore.java index 98ff48bd4664..c81e36ccc4cc 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueHiveMetastore.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/glue/GlueHiveMetastore.java @@ -354,7 +354,7 @@ private void updateTableStatisticsInternal(String databaseName, String tableName columnStatisticsProvider.updateTableColumnStatistics(table, updatedStatistics.getColumnStatistics()); } catch (EntityNotFoundException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -486,7 +486,7 @@ public void createDatabase(Database database) glueClient.createDatabase(new CreateDatabaseRequest().withDatabaseInput(databaseInput))); } catch (AlreadyExistsException e) { - throw new SchemaAlreadyExistsException(database.getDatabaseName()); + throw new SchemaAlreadyExistsException(database.getDatabaseName(), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -518,7 +518,7 @@ public void dropDatabase(String databaseName, boolean deleteData) glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(databaseName))); } catch (EntityNotFoundException e) { - throw new SchemaNotFoundException(databaseName); + throw new SchemaNotFoundException(databaseName, e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -562,10 +562,10 @@ public void createTable(Table table, PrincipalPrivileges principalPrivileges) .withTableInput(input))); } catch (AlreadyExistsException e) { - throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName())); + throw new TableAlreadyExistsException(new SchemaTableName(table.getDatabaseName(), table.getTableName()), e); } catch (EntityNotFoundException e) { - throw new SchemaNotFoundException(table.getDatabaseName()); + throw new SchemaNotFoundException(table.getDatabaseName(), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -625,7 +625,7 @@ public void replaceTable(String databaseName, String tableName, Table newTable, .withTableInput(newTableInput))); } catch (EntityNotFoundException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -706,7 +706,7 @@ public void setTableOwner(String databaseName, String tableName, HivePrincipal p .withTableInput(newTableInput))); } catch (EntityNotFoundException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -1121,7 +1121,7 @@ public void alterPartition(String databaseName, String tableName, PartitionWithS partition.getStatistics().getColumnStatistics()); } catch (EntityNotFoundException e) { - throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues()); + throw new PartitionNotFoundException(new SchemaTableName(databaseName, tableName), partition.getPartition().getValues(), e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -1265,10 +1265,10 @@ public void createFunction(String databaseName, String functionName, LanguageFun .withFunctionInput(functionInput))); } catch (AlreadyExistsException e) { - throw new TrinoException(ALREADY_EXISTS, "Function already exists"); + throw new TrinoException(ALREADY_EXISTS, "Function already exists", e); } catch (EntityNotFoundException e) { - throw new SchemaNotFoundException(databaseName); + throw new SchemaNotFoundException(databaseName, e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -1301,7 +1301,7 @@ public void dropFunction(String databaseName, String functionName, String signat .withFunctionName(metastoreFunctionName(functionName, signatureToken)))); } catch (EntityNotFoundException e) { - throw new TrinoException(FUNCTION_NOT_FOUND, "Function not found"); + throw new TrinoException(FUNCTION_NOT_FOUND, "Function not found", e); } catch (AmazonServiceException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftHiveMetastore.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftHiveMetastore.java index f7127dbe9605..d68c09a2902f 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftHiveMetastore.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftHiveMetastore.java @@ -366,7 +366,7 @@ private Map getTableColumnStatistics(String databa })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -480,7 +480,7 @@ private Map> getMetastorePartitionColumnStatis })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -561,7 +561,7 @@ private void setTableColumnStatistics(String databaseName, String tableName, Lis })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -585,7 +585,7 @@ private void deleteTableColumnStatistics(String databaseName, String tableName, })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -655,7 +655,7 @@ private void setPartitionColumnStatistics(String databaseName, String tableName, })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -679,7 +679,7 @@ private void deletePartitionColumnStatistics(String databaseName, String tableNa })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -974,7 +974,7 @@ public void createDatabase(Database database) })); } catch (AlreadyExistsException e) { - throw new SchemaAlreadyExistsException(database.getName()); + throw new SchemaAlreadyExistsException(database.getName(), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -999,7 +999,7 @@ public void dropDatabase(String databaseName, boolean deleteData) })); } catch (NoSuchObjectException e) { - throw new SchemaNotFoundException(databaseName); + throw new SchemaNotFoundException(databaseName, e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -1027,7 +1027,7 @@ public void alterDatabase(String databaseName, Database database) })); } catch (NoSuchObjectException e) { - throw new SchemaNotFoundException(databaseName); + throw new SchemaNotFoundException(databaseName, e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); @@ -1053,10 +1053,10 @@ public void createTable(Table table) })); } catch (AlreadyExistsException e) { - throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName())); + throw new TableAlreadyExistsException(new SchemaTableName(table.getDbName(), table.getTableName()), e); } catch (NoSuchObjectException e) { - throw new SchemaNotFoundException(table.getDbName()); + throw new SchemaNotFoundException(table.getDbName(), e); } catch (InvalidObjectException e) { boolean databaseMissing; @@ -1068,7 +1068,7 @@ public void createTable(Table table) databaseMissing = false; // we don't know, assume it exists for the purpose of error reporting } if (databaseMissing) { - throw new SchemaNotFoundException(table.getDbName()); + throw new SchemaNotFoundException(table.getDbName(), e); } throw new TrinoException(HIVE_METASTORE_ERROR, e); } @@ -1100,7 +1100,7 @@ public void dropTable(String databaseName, String tableName, boolean deleteData) })); } catch (NoSuchObjectException e) { - throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); + throw new TableNotFoundException(new SchemaTableName(databaseName, tableName), e); } catch (TException e) { throw new TrinoException(HIVE_METASTORE_ERROR, e); diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java index 2c069ae085a9..c16fd92fc68d 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/catalog/glue/TrinoGlueCatalog.java @@ -256,7 +256,7 @@ public void dropNamespace(ConnectorSession session, String namespace) glueClient.deleteDatabase(new DeleteDatabaseRequest().withName(namespace))); } catch (EntityNotFoundException e) { - throw new SchemaNotFoundException(namespace); + throw new SchemaNotFoundException(namespace, e); } catch (AmazonServiceException e) { throw new TrinoException(ICEBERG_CATALOG_ERROR, e); @@ -280,7 +280,7 @@ public Map loadNamespaceMetadata(ConnectorSession session, Strin return metadata.buildOrThrow(); } catch (EntityNotFoundException e) { - throw new SchemaNotFoundException(namespace); + throw new SchemaNotFoundException(namespace, e); } catch (AmazonServiceException e) { throw new TrinoException(ICEBERG_CATALOG_ERROR, e); @@ -305,7 +305,7 @@ public void createNamespace(ConnectorSession session, String namespace, Map