och5351 opened a new pull request, #182: URL: https://github.com/apache/flink-connector-jdbc/pull/182
Before PR : https://github.com/apache/flink-connector-jdbc/pull/176 ## 1. The Reason for This Change (Motivation) Currently, the Flink JDBC Connector for PostgreSQL does not recognize the native uuid data type. When a user attempts to read a table containing a uuid column through the PostgresCatalog, it fails with an UnsupportedOperationException: Doesn't support Postgres type 'uuid' yet. The uuid type is a widely used and important data type in PostgreSQL for storing unique identifiers. Adding support for it significantly improves the usability and completeness of the PostgreSQL connector. ## 2. The Solution (Changes) This PR introduces support for the PostgreSQL uuid type by making the following changes: 1. Schema-level Mapping (PostgresTypeMapper.java): Mapped the PostgreSQL uuid type to Flink's DataTypes.VARCHAR(36). This is the most appropriate mapping as the standard string representation of a UUID is 36 characters long. 2. Runtime Data Conversion (AbstractDialectConverter.java): Resolved a fundamental ClassCastException that occurred during runtime. The PostgreSQL JDBC driver returns a java.util.UUID object for uuid columns, but the existing converter logic tried to cast it directly to a java.lang.String. The deserialization logic for CHAR and VARCHAR types has been updated from (String) val to the more robust val.toString(). This not only fixes the issue for UUID but also improves the connector's resilience by correctly handling any object that has a valid string representation. 3. Test Environment Setup: PostgresCatalogTestBase.java: Added logic to create a test table (t_uuid_type) with a uuid column and insert test data before tests run. PostgresMetadata.java: Added the stringtype=unspecified option to the test JDBC URL. This was crucial for the test setup, as it allows the PostgreSQL server to correctly infer the type when inserting a String value into a uuid column during the test data population phase, preventing a PSQLException. ## 3. Test Case Description (Verification) Comprehensive tests have been added to verify the correctness of this feature and ensure no regressions were introduced: 1. PostgresCatalogTest.java: A new test testUuidDataTypes() was added. It verifies that the PostgresCatalog correctly infers the schema of a table with a uuid column as VARCHAR(36). The existing testListTables() test was updated to correctly expect the newly added uuid_table. 2. PostgresCatalogITCase.java: A new end-to-end test testUuidTypes() was added. This test executes a Flink SQL SELECT query on the uuid_table and asserts that the data is read correctly, confirming that the runtime data conversion works as expected. 3. PostgresDynamicTableSourceITCase.java: The existing integration test was modified to include a uuid column. This verifies that the changes work correctly within the dynamic table source framework. All newly added and existing tests pass locally. -- 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]
