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

feat: support default schema and catalog for PostgreSQL databases #1375

Merged
merged 5 commits into from Oct 11, 2023

Conversation

olavloite
Copy link
Collaborator

The JDBC driver would return the empty string as the current catalog and schema for PostgreSQL databases. This is incorrect, as the default catalog and schema for PostgreSQL is the database name and the 'public' schema.

The JDBC driver would return the empty string as the current catalog and
schema for PostgreSQL databases. This is incorrect, as the default
catalog and schema for PostgreSQL is the database name and the 'public'
schema.
@olavloite olavloite requested a review from a team as a code owner September 28, 2023 09:05
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner-jdbc API. labels Sep 28, 2023
return database == null ? "" : database;
case GOOGLE_STANDARD_SQL:
default:
return "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are returning empty string at multiple places, would it be better to use a 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.

I would say no for a couple of reasons:

  1. The JVM is internally creating a constant for this anyways, so there's no performance gain to be gotten.
  2. Using a constant means that you have to navigate to that constant to see what the value actually is (although good naming would help clarify that a lot in this case)
  3. Someone might be tempted to use the constant in tests as well to verify the value that is being returned. That again means that if someone changes the constant value, the test will still succeed. But real code that depends on this behavior might change.

}

void checkValidSchema(String schema) throws SQLException {
String defaultSchema = getDefaultCatalog();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be getDefaultSchema? Also should we skip the variable assignment here?
Also since this didn't get caught, are we missing the test to check schema value for POSTGRESQL?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, good catch. The same copy-paste error is actually also in the corresponding test case, which is why it was not caught. But I agree that we also need some more testing, so I've added a couple of assertions and test cases to the integration tests as well, to ensure that this works end-to-end.

}

void checkValidCatalog(String catalog) throws SQLException {
String defaultCatalog = getDefaultCatalog();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need the variable here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We use it twice on the next line... So we don't need it, but otherwise we would have to call the method twice on the next line, which also does not feel great.

@olavloite olavloite requested a review from manu2 October 11, 2023 09:51
@olavloite olavloite merged commit 2737ece into main Oct 11, 2023
24 checks passed
@olavloite olavloite deleted the support-pg-schema-and-catalog branch October 11, 2023 12:26
gcf-merge-on-green bot pushed a commit that referenced this pull request Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/java-spanner-jdbc API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants