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(cdc): fix enum to varchar in postgres-cdc #16423

Merged
merged 7 commits into from
Apr 23, 2024
Merged

Conversation

KeXiangWang
Copy link
Contributor

@KeXiangWang KeXiangWang commented Apr 20, 2024

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

What's changed and what's your intention?

fix #16392

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.

@KeXiangWang KeXiangWang requested a review from a team as a code owner April 20, 2024 21:47
Copy link

gitguardian bot commented Apr 20, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 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.

Our GitHub checks need improvements? Share your feedbacks!

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.

Rest lgtm

src/connector/src/parser/postgres.rs Outdated Show resolved Hide resolved
src/connector/src/parser/postgres.rs Show resolved Hide resolved
src/connector/src/parser/postgres.rs Show resolved Hide resolved
src/connector/src/parser/postgres.rs Show resolved Hide resolved
src/connector/src/parser/postgres.rs Show resolved Hide resolved

#[ignore]
#[test]
fn enum_parser_integration_test() {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to do some unit test instead of integration test here? I guess e2e test has already played the integration role? Should have automated test here.

Copy link
Contributor Author

@KeXiangWang KeXiangWang Apr 23, 2024

Choose a reason for hiding this comment

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

In this test, I want to make sure two things:

  1. EnumParser correctly understood the data queried from pg.
  2. The data transformed from EnumParser can be correctly understood by pg.

So the test cannot run without pg. Here, as I have marked as #[ignore], I just want to provide a simple tool to test EnumParser. e2e test can already verify its correctness.

src/connector/src/parser/postgres.rs Outdated Show resolved Hide resolved
Copy link
Member

@stdrc stdrc left a comment

Choose a reason for hiding this comment

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

LGTM

_ty: &Type,
raw: &'a [u8],
) -> Result<Self, Box<dyn std::error::Error + 'static + Sync + Send>> {
Ok(EnumString(String::from_utf8_lossy(raw).into_owned()))
Copy link
Contributor

@StrikeW StrikeW Apr 23, 2024

Choose a reason for hiding this comment

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

I realized that our native postgres parser cannot fallback upstream data types that we don't support to varchar.
Besides Enum, for example if user want to map INET to varchar, we cannot make it.
Is it possible to apply this implementation, blindly store as a string, to other postgres data types? @KeXiangWang

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on whether the type is serialized directly as utf8 string. We need to test different types to verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#16455
Just created an issue to track

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another choice is that, when backfilling, instead of querying PG with SELECT {} FROM {} here and converting in RW, we can directly convert the data to varchar in pg.

For example, if we find an enum column E is to be converted to varchar, we can directly run SELECT E::varchar FROM, so that we don't need to handle it in our codes.

if let Kind::Array(item_type) = row.columns()[i].type_().kind()
&& let Kind::Enum(_) = item_type.kind()
{
let res = row.try_get::<_, Option<Vec<EnumString>>>(i);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe affect other cases as well: have we tested null inside an array? Maybe we need Option<Vec<Option<T>>>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just tested. Yes, we need Option<Vec<Option<T>>>. I'll create a new PR to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done #16457

@KeXiangWang KeXiangWang added this pull request to the merge queue Apr 23, 2024
Merged via the queue into main with commit d476283 Apr 23, 2024
28 of 29 checks passed
@KeXiangWang KeXiangWang deleted the wkx/enum-in-cdc branch April 23, 2024 15:32
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.

Postgres-cdc: postgres enum data type cannot ingest into RW as varchar
5 participants