aakashofficial-k01 opened a new issue, #4361:
URL: https://github.com/apache/amoro/issues/4361

   ### What happened?
   
   **What happened?**
   When an Iceberg REST client (PyIceberg, Spark, Trino, Flink) attempts to 
create a table that already exists or commit a staged table creation against an 
existing table, the AMS REST Catalog endpoint returns HTTP 500 
InternalServerError instead of HTTP 409 Conflict.
   
   **Root Cause**
   1. In `RestCatalogService.IcebergRestErrorCode.exceptionToCode()`, only 
`org.apache.iceberg.exceptions.AlreadyExistsException` is mapped to `Conflict` 
(409). However, internal table managers throw 
`org.apache.amoro.exception.AlreadyExistsException`. Because the Amoro class 
does not extend the Iceberg exception, the check evaluates to `false` and falls 
through to HTTP 500.
   2. In `createTable()` and `commitCreateTable()`, table existence is not 
verified upfront before creating physical metadata files on object storage 
(S3/HDFS), causing redundant file creation followed by rollback deletions on 
duplicate requests.
   
   **Expected Behavior**
   - Duplicate table creation requests should return HTTP 409 Conflict per the 
Iceberg REST OpenAPI specification.
   - AMS should check table existence upfront to avoid redundant storage I/O 
and rollbacks.
   
   ### Affects Versions
   
   master,0,.9.0
   
   ### What table formats are you seeing the problem on?
   
   Iceberg
   
   ### What engines are you seeing the problem on?
   
   AMS, Spark, Trino
   
   ### How to reproduce
   
   1. Start AMS with an Iceberg REST catalog enabled (e.g., lakehouse).
   
   2. Send an initial table creation request to create table 
`test_db.test_table`:
   curl -X POST 
http://localhost:1630/api/iceberg/rest/v1/catalogs/lakehouse/namespaces/test_db/tables
 \
     -H "Content-Type: application/json" \
     -d 
'{"name":"test_table","schema":{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"int"}]}}'
   
   Result: HTTP 200 OK (table created successfully).
   
   3. Send the exact same table creation request a second time to attempt 
duplicate creation:
   curl -X POST 
http://localhost:1630/api/iceberg/rest/v1/catalogs/lakehouse/namespaces/test_db/tables
 \
     -H "Content-Type: application/json" \
     -d 
'{"name":"test_table","schema":{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":true,"type":"int"}]}}'
   
   Expected: HTTP 409 Conflict with message indicating table already exists 
(compliant with Iceberg REST OpenAPI specification).
   
   Actual: HTTP 500 InternalServerError with 
org.apache.amoro.exception.AlreadyExistsException.
   
   ### Relevant log output
   
   ```shell
   2026-09-05 09:12:00,123 ERROR [JettyServerThreadPool-31] 
[org.apache.amoro.server.RestCatalogService] - Internal Server Error
   org.apache.amoro.exception.AlreadyExistsException: Table test_table already 
exists
        at 
org.apache.amoro.server.table.DefaultTableManager.createTable(DefaultTableManager.java:142)
        at 
org.apache.amoro.server.RestCatalogService.createTable(RestCatalogService.java:338)
   ```
   
   ### Anything else
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [x] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's Code of Conduct


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to