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 4264190cd0bd..1991c2d869ff 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 @@ -355,7 +355,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); @@ -487,7 +487,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); @@ -519,7 +519,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); @@ -563,10 +563,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); @@ -626,7 +626,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); @@ -711,7 +711,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); @@ -1126,7 +1126,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); @@ -1264,10 +1264,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); @@ -1300,7 +1300,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 dcd1ada4d8be..78342b38b327 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); @@ -953,7 +953,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); @@ -978,7 +978,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); @@ -1006,7 +1006,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); @@ -1032,10 +1032,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; @@ -1047,7 +1047,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); } @@ -1079,7 +1079,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 e9d07c5ba332..995bdb127587 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 @@ -267,7 +267,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); @@ -291,7 +291,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); @@ -316,7 +316,7 @@ public void createNamespace(ConnectorSession session, String namespace, Map