markhoerth opened a new issue, #14426:
URL: https://github.com/apache/gravitino/issues/14426

   ### Version
   main branch, commit bb634defdc5663a8124be5fca1c8d9e52ac096ac (2.0.0-SNAPSHOT)
   
   ### Describe what's wrong
   A user renames column `id` of a Lance table to `name`, which already exists. 
The user expects a 400 saying the column name is taken. Instead, both the Lance 
REST service (`POST /v1/table/{id}/alter_columns`) and the Gravitino REST API 
(`PUT .../tables/{table}` with `renameColumn`) return 500. The dataset and the 
metadata stay unchanged.
   
   The error comes from the upstream Lance library: `Dataset.alterColumns` 
raises a plain `RuntimeException` "LanceError(Schema): Duplicate field name". 
Gravitino does not check for the conflict first and does not translate the 
error. In 
`catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/lance/LanceTableOperations.java`,
 `validateLanceTableChanges` (`:916-950`) only checks that a rename targets a 
top-level column (`:943-950`), not that the new name is free. 
`handleLanceTableChange` then calls `dataset.alterColumns` (`:899-904`) and 
rethrows the `RuntimeException` unchanged (`:908-909`). The Gravitino API's 
generic handler and `LanceExceptionMapper` 
(`lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/LanceExceptionMapper.java:121-123`)
 both map it to 500.
   
   ### Error message and/or stacktrace
   ```
   POST /lance/v1/table/cat$s$t/alter_columns  
{"alterations":[{"path":"id","rename":"name"}]}
   500 {"error":"Internal server 
error","code":18,"detail":"","instance":"cat$s$t"}
   
   PUT /api/metalakes/lml/catalogs/cat/schemas/s/tables/t  
{"updates":[{"@type":"renameColumn","oldFieldName":["id"],"newFieldName":"name"}]}
   500 {"code":1002,"type":"RuntimeException","message":"Failed to operate 
object [t] operation [ALTER] under [s], reason [LanceError(Schema): Duplicate 
field name \"name\" in schema: ..."}
     at org.lance.Dataset.nativeAlterColumns(Native Method)
     at org.lance.Dataset.alterColumns(Dataset.java:694)
     at 
org.apache.gravitino.catalog.lakehouse.lance.LanceTableOperations.handleLanceTableChange(LanceTableOperations.java:904)
     at 
org.apache.gravitino.catalog.lakehouse.lance.LanceTableOperations.alterTable(LanceTableOperations.java:292)
   ```
   
   ### How to reproduce
   1. Set up the Lance REST service, catalog `cat` and namespace `cat$s` as in 
steps 1-2 of #14425.
   2. Create a Lance table `cat$s$t` with columns `id` (int64) and `name` 
(utf8), for example with the Lance Python client `create_table` against 
`http://127.0.0.1:9101/lance`, or by posting an Arrow IPC schema stream to 
`POST /v1/table/cat$s$t/create` with `Content-Type: 
application/vnd.apache.arrow.stream`.
   3. Rename `id` to `name`:
      ```
      curl -u admin:x -H 'Content-Type: application/json' -X POST 
'http://127.0.0.1:9101/lance/v1/table/cat$s$t/alter_columns' -d 
'{"alterations":[{"path":"id","rename":"name"}]}'
      ```
      The response is 500.
   
   ### Additional context
   The 2.0 OSS test suite check `test_rename_onto_existing_column_is_400` found 
it. The duplicate-name error originates in the upstream Lance library; the 
missing conflict check and error translation are in Gravitino's Lance catalog.


-- 
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