[FLINK-37371] Postgres CDC incremental source fails to handle upper-case table and column names #3929
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem summary
There are two problems in the code:
to_regclass()
isn't quoted, so the upper-case letters get lower-cased.There's also a minor issue with the
quote()
implementation that it doesn't doubles the double quotes. So if the table name or column name contains double quote, it will result in a SQL syntax error.Connector code changes
to_regclass()
, pass the schema name and table name individually. This way, they are interpreted as literals don't don't get automatically lower-cased.pg_class
. Otherwise, the table and schema name would have to be additionally quoted.quote()
per SQL standard.Test changes
I don't think that handling upper-case name should be covered by a special test case. Ideally, it should be tested exhaustively, so I decided to modify an existing test. Prior to that:
TableId
class represents a qualified table name (schema name + table name). ItstoSql()
method generates a valid SQL name that can be used to build queries.PostgresSourceITCase
has been cleaned up to eliminate some warnings (e.g. raw usage of parameterized types or non-closedClosable
).