akune opened a new issue, #14601:
URL: https://github.com/apache/iceberg/issues/14601

   ### Apache Iceberg version
   
   1.10.0 (latest release)
   
   ### Query engine
   
   Spark
   
   ### Please describe the bug 🐞
   
   **Given** 
   Database tables for JDBC catalog (V1) have been created (using Liquibase) in 
a DB2 or Oracle database.
   JDBC catalog is configured like this: 
   ```
   spark.sql.defaultCatalog=ice
   spark.sql.catalog.ice.type=jdbc
   spark.sql.catalog.ice.uri=[jdbc-url]
   spark.sql.catalog.ice.jdbc.user=[username]
   spark.sql.catalog.ice.jdbc.password=[password]
   spark.sql.catalog.ice.jdbc.init-catalog-tables=false
   ```
    
   **When**
   Performing any operation that initializes the JDBC catalog. 
   
   **Expected**
   The JDBC catalog initializes and the operation performs successfully.
   
   **Actual**
   The JDBC catalog initialization fails with the following error, ultimately 
leading a failure of the initiating operation: 
   [DB2]
   ```
   org.apache.iceberg.jdbc.UncheckedSQLException: Cannot check and eventually 
update SQL schema
   Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: 
SQLCODE=-612, SQLSTATE=42711, SQLERRMC=ICEBERG_TYPE, DRIVER=4.35.11
   ```
   [Oracle]
   ```
   org.apache.iceberg.jdbc.UncheckedSQLException: Cannot check and eventually 
update SQL schema
   Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: : invalid identifier
   https://docs.oracle.com/error-help/db/ora-00904/
   Caused by: Error : 904, Position : 31, SQL = ALTER TABLE iceberg_tables ADD 
COLUMN iceberg_type VARCHAR(5), Original SQL = ALTER TABLE iceberg_tables ADD 
COLUMN iceberg_type VARCHAR(5), Error Message = ORA-00904: : invalid identifier
   ```
   
   **Root Cause Analysis**
   The error stems from the JdbcCatalog class's attempt to check if the JDBC 
catalog tables are already available in the correct version. 
   For that JdbcCatalog runs the method `updateSchemaIfRequired` which checks 
for the existence of specific tables using `DatabaseMetaData`. Unfortunately 
that approach does not currently work with DB2 and Oracle databases due to 
their handling of the upper case vs. lower case spelling of table and column 
names. 
   
   **Proposed Fix**
   In the long run the schema check in JdbcCatalog needs to be reworked so that 
it supports checking and migrating the schema independent of the upper or lower 
case spelling of table and column names. 
   However, this is not required for my scenario in which I am supplying the 
schema with Liquibase. 
   Instead I propose a way to prevent the (erroneous) check in 
`JdbcCatalog#updateSchemaIfRequired` to be run in the first place. 
   This could be achieved by skipping the check if the property 
`jdbc.init-catalog-tables` is set to false. 
   
   ### Willingness to contribute
   
   - [x] I can contribute a fix for this bug independently
   - [ ] I would be willing to contribute a fix for this bug with guidance from 
the Iceberg community
   - [ ] I cannot contribute a fix for this bug at this time


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to