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

Try to make one query to DB to retrieve primary keys #2514

Merged
merged 2 commits into from
Mar 19, 2021

Conversation

ChristopheDuong
Copy link
Contributor

@ChristopheDuong ChristopheDuong commented Mar 18, 2021

What

Follow-up on #2488 after comments: #2488 (comment)

@auto-assign auto-assign bot requested review from cgardens and jrhizor March 18, 2021 14:54
@ChristopheDuong ChristopheDuong changed the title Try to make a single query to DB to retrieve primary keys Try to make one query to DB to retrieve primary keys Mar 18, 2021
* If @param tableName is not specified, this function may fail on some databases (for example
* MySql) but works on others (for instance Postgres)
*/
private Map<String, List<String>> discoverPrimaryKeys(JdbcDatabase database,
Copy link
Contributor

Choose a reason for hiding this comment

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

got it. i'd suggest 1 of 3 options here:

  1. have this return an optional if the query doesn't work
  2. have this method always succeed by hiding this logic internally. So it always takes the table names. If it doesn't need them it doesn't use them, but if it does it has them.
    e.g. discoverPrimaryKeys(JdbcDatabase database, Optional<String> databaseOptional, Optional<String> schemaOptional, String tableName) => discoverPrimaryKeys(JdbcDatabase database, Optional<String> databaseOptional, Optional<String> schemaOptional, List<String> tableNames)
  3. just always query one table at a time.

i think 2 or 3 are equally good options and are clearer than 1. with the weird quirk you discovered that you can't always use null for getPrimaryKeys it's not the end of the world if we just do a query per table.

@cgardens
Copy link
Contributor

Thanks for following up on this. I think you can make the contract on one method a little clearer. Otherwise good.

Copy link
Contributor

@cgardens cgardens left a comment

Choose a reason for hiding this comment

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

lgtm

@ChristopheDuong ChristopheDuong merged commit 6c9b519 into master Mar 19, 2021
@ChristopheDuong ChristopheDuong deleted the chris/source-primary-key branch March 19, 2021 08:41
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