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

   ### Version
   main branch, commit bb634defdc5663a8124be5fca1c8d9e52ac096ac (2.0.0-SNAPSHOT)
   
   ### Describe what's wrong
   A client calls `POST .../tables/{table}/plan` on a table that has data, with 
a filter that cannot bind to the schema: an unknown column, a literal of the 
wrong type (`"not-a-number"` for a `long`), or a column name in the wrong case 
with `case-sensitive: true`. The client expects a 400 that names the problem, 
since the request is malformed. Instead the service returns 500 
`RuntimeException` "Scan planning failed for table ...". On an empty table (no 
snapshot) the same filter returns 200, because nothing is bound.
   
   The cause is in 
`iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java:491-501`.
 The Iceberg library raises `org.apache.iceberg.exceptions.ValidationException` 
when it binds the filter. The method only rethrows `IllegalArgumentException` 
and `NoSuchTableException` as they are; every other exception, including 
`ValidationException`, is wrapped in a plain `RuntimeException` at `:497-500`. 
`IcebergExceptionMapper` maps `ValidationException` to 400 
(`iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergExceptionMapper.java:64`),
 but it never sees it, so the wrapped exception becomes a 500. The test suite 
also saw the same wrapper for a `timestamptz` literal without a zone and a 
binary literal that is not hex.
   
   ### Error message and/or stacktrace
   ```
   POST /iceberg/v1/namespaces/ns/tables/t/plan  
{"filter":{"type":"eq","term":"no_such_col","value":1}}
   500 {"error":{"message":"Scan planning failed for table ns.t: Cannot find 
field 'no_such_col' in struct: struct<1: id: optional 
long>","type":"RuntimeException","code":500,...
     Caused by: org.apache.iceberg.exceptions.ValidationException: Cannot find 
field 'no_such_col' in struct: struct<1: id: optional long>
       at 
org.apache.iceberg.expressions.NamedReference.bind(NamedReference.java:45)
   
   POST .../plan  {"filter":{"type":"eq","term":"id","value":"not-a-number"}}
   500 "Scan planning failed for table ns.t: Invalid value for conversion to 
type long: not-a-number (java.lang.String)"
     Caused by: org.apache.iceberg.exceptions.ValidationException: Invalid 
value for conversion to type long: not-a-number (java.lang.String)
   
   POST .../plan  
{"filter":{"type":"eq","term":"ID","value":5},"case-sensitive":true}
   500 "Scan planning failed for table ns.t: Cannot find field 'ID' in struct: 
struct<1: id: optional long>"
   ```
   
   ### How to reproduce
   1. Create a namespace and a table through the Iceberg REST service:
      ```
      curl -u admin:x -H 'Content-Type: application/json' -X POST 
http://127.0.0.1:9001/iceberg/v1/namespaces -d '{"namespace":["ns"]}'
      curl -u admin:x -H 'Content-Type: application/json' -X POST 
http://127.0.0.1:9001/iceberg/v1/namespaces/ns/tables -d 
'{"name":"t","schema":{"type":"struct","schema-id":0,"fields":[{"id":1,"name":"id","required":false,"type":"long"}]}}'
      ```
   2. Append at least one data file with any engine connected to the Iceberg 
REST catalog, for example in Spark: `INSERT INTO rest.ns.t VALUES (1)`.
   3. Plan with a filter on a column that does not exist:
      ```
      curl -u admin:x -H 'Content-Type: application/json' -X POST 
http://127.0.0.1:9001/iceberg/v1/namespaces/ns/tables/t/plan -d 
'{"filter":{"type":"eq","term":"no_such_col","value":1}}'
      ```
      The response is the 500 above.
   
   ### Additional context
   Related: #14302 (other Iceberg exceptions mapped to 500; different cause). 
The 2.0 OSS test suite check `test_plan_bad_filter_is_400` found it. The 
Iceberg library raises the correct `ValidationException`; Gravitino's wrapper 
hides it from the exception mapper.


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