Skip to content

Conversation

@och5351
Copy link

@och5351 och5351 commented Dec 2, 2025

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:

  • Unit/Integration tests in PostgresCatalogTest to verify the schema mapping.
  • End-to-end tests in PostgresCatalogITCase to confirm that data is read correctly via Flink SQL.

I believe these additions make the feature more robust and complete. Thanks again for getting it started!


(Note: I am currently waiting for my Jira account registration to be approved, so I am unable to create a ticket for this issue at the moment. I will update the title with the Jira ticket number as soon as I gain access. If someone else would like to create it, that would also be great.)


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 (PostgresMetadata.java):

    Added the stringtype=unspecified option to the test-only JDBC URL in PostgresMetadata.java. This change is critical for the verification process. When populating test data, the test framework attempts to insert a Java String into a uuid database column. Without this option, the JDBC driver specifies the type as varchar, causing a PSQLException from the PostgreSQL server. With stringtype=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:

  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.


image image image

@boring-cyborg
Copy link

boring-cyborg bot commented Dec 2, 2025

Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)

@och5351 och5351 marked this pull request as draft December 2, 2025 02:17
@och5351 och5351 marked this pull request as ready for review December 2, 2025 02:18
@och5351
Copy link
Author

och5351 commented Dec 4, 2025

@alpinegizmo
Hi, could you please review this PR?

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.

Copy link
Contributor

@RocMarshal RocMarshal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kcolford for adding uuid type in PG and @och5351 for adding the corresponding test cases.

Since there hasn't been new communication progress on the PR[1] for a while, it might be a good approach to directly review based on current PR.

[1] #176

case CHAR:
case VARCHAR:
return val -> StringData.fromString((String) val);
return val -> StringData.fromString(val.toString());
Copy link
Contributor

@RocMarshal RocMarshal Dec 8, 2025

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.

Copy link
Author

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.

Copy link
Author

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!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


import java.lang.reflect.Array;

import java.util.UUID;
Copy link
Contributor

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.

@och5351 och5351 requested a review from RocMarshal December 8, 2025 05:16
Copy link
Contributor

@RocMarshal RocMarshal left a 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 👍

@och5351
Copy link
Author

och5351 commented Dec 8, 2025

Thanks for the update 👍

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? :)

@och5351 och5351 requested a review from RocMarshal December 8, 2025 22:48
Copy link
Contributor

@RocMarshal RocMarshal left a 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:apply in the repo path locally?
  • 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 ?

@och5351
Copy link
Author

och5351 commented Dec 9, 2025

Thanks for your guidance on the next steps, @RocMarshal .

  • A: For the code style:
    • You asked me to run mvn spotless:apply locally in the repo path.

--> I have run mvn spotless:apply and committed the changes.
image

  • B: For the commit message:
    • You requested to squash the commits into one with a detailed commit message like [hotfix][Connector/JDBC] Support PostgreSQL uuid type.

--> I have updated the commit message accordingly. Please kindly check my latest commit.

@och5351 och5351 requested a review from RocMarshal December 9, 2025 06:04
Copy link
Contributor

@RocMarshal RocMarshal left a 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.

image

Would you mind helping do the change mentioned above? thx

@och5351 och5351 changed the title [hotfix] postgresql uuid type support [hotfix][Connector/JDBC] postgresql uuid type support Dec 9, 2025
@och5351 och5351 changed the title [hotfix][Connector/JDBC] postgresql uuid type support [hotfix][Connector/JDBC] Support PostgreSQL uuid type Dec 9, 2025
@och5351 och5351 force-pushed the feature/postgresql-catalog-uuid-type-support branch from cccb7b9 to 57d21ce Compare December 9, 2025 08:29
@och5351 och5351 requested a review from RocMarshal December 9, 2025 08:46
@och5351
Copy link
Author

och5351 commented Dec 9, 2025

Thanks @och5351 for the update.

image Would you mind helping do the change mentioned above? thx

I have changed the PR title and squashed the commits.
Thank you!

Copy link
Contributor

@RocMarshal RocMarshal left a 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 hard work.

LGTM +1.

CC @1996fanrui

@1996fanrui
Copy link
Member

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

  • It looks more like a feature or improvement instead of hotfix, is not it? If yes, it is better to have a separate jira.
  • I do not think [Connector/JDBC] is required in commit message as this is a separate repo for jdbc connector. Of course, including [Connector/JDBC] is also fine.
  • CI is failed, please take a look

@1996fanrui 1996fanrui self-assigned this Dec 11, 2025
@RocMarshal
Copy link
Contributor

  • It looks more like a feature or improvement instead of hotfix, is not it? If yes, it is better to have a separate jira.
  • I do not think [Connector/JDBC] is required in commit message as this is a separate repo for jdbc connector. Of course, including [Connector/JDBC] is also fine.

That sounds good to me~ 👍

@och5351
Copy link
Author

och5351 commented Dec 11, 2025

Hi, @1996fanrui!

  1. It looks more like a feature or improvement instead of hotfix, is not it? If yes, it is better to have a separate jira.
  • Slightly off-topic, but I have a question about JIRA registration.
    I requested to join the Flink JIRA some time ago with the email, but I haven't received a confirmation yet.
    Do you know where I could follow up on this request?

    I would like to create a ticket as soon as my account is approved.

I left a message in Flink slack channel!

  1. I do not think [Connector/JDBC] is required in commit message as this is a separate repo for jdbc connector. Of course, including [Connector/JDBC] is also fine.
  • Your right! I will edit title. On second thought, if I change the title, the commit message and the title might differ a bit. Is that okay?
  1. CI is failed, please take a look
  • The test passed successfully on my local environment.
    Is there anything else I should check or look into?
    Below is the content I just tested.
image image

cc. @RocMarshal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants