-
Notifications
You must be signed in to change notification settings - Fork 205
[hotfix][Connector/JDBC] Support PostgreSQL uuid type #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[hotfix][Connector/JDBC] Support PostgreSQL uuid type #182
Conversation
|
Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html) |
|
@alpinegizmo Currently, our system fails to connect to PostgreSQL tables containing an uuid column because the type is unsupported. This PR resolves the issue by adding proper support for the uuid type, which is widely used in many tables. |
RocMarshal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| case CHAR: | ||
| case VARCHAR: | ||
| return val -> StringData.fromString((String) val); | ||
| return val -> StringData.fromString(val.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do it as follows due to the column with UUID type(or other types are mapping to varchar(x)) may be nullable ?
return val -> StringData.fromString(val == null ? null: val.toString());
And if the comment is acceptable, we'd better add the corresponding test lines for testing the null value in the column.
Pls correct me if I'm wrong in the understood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review. :)
You are right; that code would cause a null pointer exception.
I will add a test case for null data and then request your review again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RocMarshal
Could you please review it again when you have a moment?
I would appreciate your help!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| import java.lang.reflect.Array; | ||
|
|
||
| import java.util.UUID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this import statement is redundant, as it is not used subsequently.
RocMarshal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update 👍
...ain/java/org/apache/flink/connector/jdbc/core/database/dialect/AbstractDialectConverter.java
Outdated
Show resolved
Hide resolved
...java/org/apache/flink/connector/jdbc/postgres/database/dialect/PostgresDialectConverter.java
Show resolved
Hide resolved
...st/java/org/apache/flink/connector/jdbc/postgres/database/catalog/PostgresCatalogITCase.java
Outdated
Show resolved
Hide resolved
Thank you for the review! I've incorporated your feedback into the latest commit. Could you please take another look when you get a chance? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @och5351 for the update.
LGTM on the whole besides the code style & commits message.
- A: For code style:
- Would you mind running
mvn spotless:applyin the repo path locally?
- Would you mind running
- B: For commits message
- After A: Could you help squish the commits into one with detail commit message like
[hotfix][Connector/JDBC] Support PostgreSQL uuid type?
- After A: Could you help squish the commits into one with detail commit message like
|
Thanks for your guidance on the next steps, @RocMarshal .
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cccb7b9 to
57d21ce
Compare
I have changed the PR title and squashed the commits. |
RocMarshal
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Thanks @och5351 for the contribution, and @RocMarshal for the review! I have 3 comments for this PR, please take a look when you are available, thanks
|
That sounds good to me~ 👍 |
|
Hi, @1996fanrui!
cc. @RocMarshal |






First, thank you for your great work on adding PostgreSQL uuid support in PR #176 .
This is a follow-up PR that builds upon your implementation by adding the necessary test cases to ensure the feature's correctness and prevent future regressions.
Specifically, I've added:
I believe these additions make the feature more robust and complete. Thanks again for getting it started!
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:
Schema-level Mapping (PostgresTypeMapper.java):
Mapped the PostgreSQL
uuidtype to Flink'sDataTypes.VARCHAR(36). This is the most appropriate mapping as the standard string representation of a UUID is 36 characters long.Runtime Data Conversion (AbstractDialectConverter.java):
Resolved a fundamental
ClassCastExceptionthat occurred during runtime. The PostgreSQL JDBC driver returns ajava.util.UUIDobject foruuidcolumns, but the existing converter logic tried to cast it directly to ajava.lang.String.The deserialization logic for
CHARandVARCHARtypes has been updated from(String) valto the more robustval.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.Test Environment Setup (PostgresMetadata.java):
Added the
stringtype=unspecifiedoption to the test-only JDBC URL inPostgresMetadata.java. This change is critical for the verification process. When populating test data, the test framework attempts to insert a JavaStringinto auuiddatabase column. Without this option, the JDBC driver specifies the type asvarchar, causing aPSQLExceptionfrom the PostgreSQL server. Withstringtype=unspecified, the driver does not specify the type, allowing the server to correctly perform an implicit cast from the string literal to the uuid type. This change is confined to the test scope and does not affect the main production code.3. Test Case Description (Verification)
Comprehensive tests have been added to verify the correctness of this feature and ensure no regressions were introduced:
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.
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.
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.