Skip to content
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

fix(pgcdc): fix uppercase-identifier of pgcdc #17754

Merged
merged 9 commits into from
Jul 23, 2024

Conversation

KeXiangWang
Copy link
Contributor

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

fix #17752
Change the sql from using ::regclass to using schemaName and tableName

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

@github-actions github-actions bot added the type/fix Bug fix label Jul 19, 2024
@KeXiangWang KeXiangWang requested a review from yuhao-su July 19, 2024 02:28
@@ -180,7 +180,8 @@ private void validateTableSchema() throws SQLException {
// check primary key
// reference: https://wiki.postgresql.org/wiki/Retrieve_primary_key_columns
try (var stmt = jdbcConnection.prepareStatement(ValidatorUtils.getSql("postgres.pk"))) {
stmt.setString(1, this.schemaName + "." + this.tableName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just quote the object name?
String.format("\"%s\".\"%s\"", this.schemaName, this.tableName)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be another choice. I noticed that other sql statements use schemaName and tableName, so I think we should keep them consistent. Do you prefer "\"%s\".\"%s\""?

Copy link
Contributor

Choose a reason for hiding this comment

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

The change to the validate sql needs to join two more system tables, I think it can be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

Copy link
Contributor

@xiangjinwu xiangjinwu Jul 19, 2024

Choose a reason for hiding this comment

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

Slightly prefer to keep consistent with other places, unless the cost of join is high.

Strictly speaking the manual quoting above is wrong, but I do believe no one would challenge this in practice:

test=# create table "my_test""table" ("Foo" int); -- two quotes required
CREATE TABLE
test=# select relname, quote_ident(relname) from pg_class where relname ^@ 'my_te';
    relname    |   quote_ident    
---------------+------------------
 my_test"table | "my_test""table"
(1 row)

(pgdoc)

Embedded quotes are properly doubled

@yuhao-su yuhao-su requested a review from xiangjinwu July 19, 2024 02:52
@yuhao-su
Copy link
Contributor

I thought the name should only be quoted by " when used as an identifier. cc @xiangjinwu to confirm

@StrikeW
Copy link
Contributor

StrikeW commented Jul 19, 2024

I thought the name should only be quoted by " when used as an identifier. cc @xiangjinwu to confirm

I think so, IIRC. any concern?

Copy link
Contributor

@StrikeW StrikeW left a comment

Choose a reason for hiding this comment

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

LGTM

@yuhao-su
Copy link
Contributor

any concern?

All good. Never mind.

port = '${PGPORT:5432}',
username = '${PGUSER:$USER}',
password = '${PGPASSWORD:}',
database.name = '${PGDATABASE:postgres}',
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, we better to test whether uppercase in database.name can work.

Copy link
Contributor Author

@KeXiangWang KeXiangWang Jul 22, 2024

Choose a reason for hiding this comment

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

Tested. It works. But I also found a weird bug #17754 (comment). After some attempts, it's sometimes not reproduciable: only several special tables can trigger this bug. I'm still not aware of the exact condition. To merge this PR, I temporarily delete the tests about database.name. Will create an issue later to track and fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, we didn't get bug report from our users yet. Agree to create a issue to track it.

Copy link

gitguardian bot commented Jul 19, 2024

⚠️ GitGuardian has uncovered 8 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9425213 Triggered Generic Password 0670570 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 0670570 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 0670570 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 7cf41c9 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 7cf41c9 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 938f610 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 938f610 ci/scripts/e2e-source-test.sh View secret
9425213 Triggered Generic Password 938f610 ci/scripts/e2e-source-test.sh View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@KeXiangWang KeXiangWang force-pushed the wkx/fix-pgcdc-uppercase-identifier branch 2 times, most recently from cd1a646 to d1c95b2 Compare July 19, 2024 04:12
@KeXiangWang KeXiangWang force-pushed the wkx/fix-pgcdc-uppercase-identifier branch from d1c95b2 to 0670570 Compare July 19, 2024 04:18
Copy link
Contributor

@tabVersion tabVersion left a comment

Choose a reason for hiding this comment

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

either approach lgtm

@KeXiangWang
Copy link
Contributor Author

KeXiangWang commented Jul 20, 2024

Accidentally find a bug: if there's a new db is created in the upstream pg after RW setup a cdc connector, RW will crash. Investigating.

@KeXiangWang KeXiangWang force-pushed the wkx/fix-pgcdc-uppercase-identifier branch 2 times, most recently from 9d92915 to 7374402 Compare July 23, 2024 01:09
@KeXiangWang KeXiangWang force-pushed the wkx/fix-pgcdc-uppercase-identifier branch from 7374402 to 8aa28b0 Compare July 23, 2024 01:25
@KeXiangWang KeXiangWang added this pull request to the merge queue Jul 23, 2024
Merged via the queue into main with commit 5bd3e3e Jul 23, 2024
28 of 30 checks passed
@KeXiangWang KeXiangWang deleted the wkx/fix-pgcdc-uppercase-identifier branch July 23, 2024 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

quote postgres object name (identifier) with " when interact with postgres source
5 participants