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

Postgres schema name fix #5432

Merged
merged 4 commits into from
Feb 14, 2025

Conversation

oeyh
Copy link
Collaborator

@oeyh oeyh commented Feb 12, 2025

Description

Postgres tables are specified as database.schema.table, while MySQL tables are specified as database.table. This PR fixes an issue that the metadata in Postgres export and stream are not consistent.

In summary, we use databaseName, schemaName and tableName across the rds source plugin. schemaName is specific for Postgres, but for MySQL, we also fill this field with the same value as databaseName.

Also refactors TableMetadata to use builder pattern. A lot of its usages in test code were updated.

Issues Resolved

Contributes to #5309

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have made this change in my PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove all the changes associated with this pattern in other files

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to add schemaName in this class.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Merged your other PR. Will resolve the conflicts here.

Signed-off-by: Hai Yan <oeyh@amazon.com>
@oeyh oeyh force-pushed the rds/handle-postgres-schema-name branch from 3e4208a to 3fbd0ad Compare February 12, 2025 21:24
@oeyh
Copy link
Collaborator Author

oeyh commented Feb 12, 2025

There was some overlap with #5410. Now that #5410 is merged, I resolved the conflicts in this PR.

Signed-off-by: Hai Yan <oeyh@amazon.com>
Signed-off-by: Hai Yan <oeyh@amazon.com>
@@ -25,9 +27,12 @@ public class DataFileProgressState {
private String sourceDatabase;

/**
* For MySQL, sourceTable is in the format of tableName
* For Postgres, sourceTable is in the format of schemaName.tableName
* For PostgreSQL engine type, schema is the schema name.
Copy link
Member

Choose a reason for hiding this comment

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

nit: sourceSchema is the schema name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

*/
@JsonProperty("sourceSchema")
private String sourceSchema;
Copy link
Member

Choose a reason for hiding this comment

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

How do plan to use this field for MySQL ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This field will not be used when the source is MySQL database.

StreamProgressState progressState = streamPartition.getProgressState().get();

return progressState.getPrimaryKeyMap().get(databaseName + "." + schemaName + "." + tableName);
}

private String getDatabaseName(List<String> tableNames) {
return tableNames.get(0).split("\\.")[0];
Copy link
Member

Choose a reason for hiding this comment

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

nit: move the split delimiter to constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Signed-off-by: Hai Yan <oeyh@amazon.com>
@oeyh oeyh merged commit 85127bc into opensearch-project:main Feb 14, 2025
46 of 47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants