GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add support for PostgreSQL dialect by olavloite · Pull Request #739 · googleapis/java-spanner-jdbc

This repository was archived by the owner on Sep 30, 2026. It is now read-only.

Conversation

@olavloite

@olavloite olavloite commented Feb 8, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Adds support for PostgreSQL dialect databases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@olavloite
feat: add support for PostgreSQL dialect
298877f
@olavloite olavloite added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 8, 2022
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/java-spanner-jdbc API. label Feb 8, 2022
@olavloite
olavloite marked this pull request as ready for review February 8, 2022 19:32
@olavloite
olavloite requested review from a team, ansh0l and thiagotnunes February 8, 2022 19:32
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcPgNumericTest.java
final String positiveBigNumeric =
String.join("", Collections.nCopies(131072, "1"))
+ "."
+ String.join("", Collections.nCopies(16383, "2"));

@ansh0l ansh0l Feb 12, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Just for understanding: Do the numbers 131072 and 16383 hold any special significance ?
String.join("",` Collections.nCopies(131072, "1")) + "." + String.join("", Collections.nCopies(16383, "2"));

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, they represent the maximum number of digits before/after the decimal point in a PostgreSQL numeric: https://www.postgresql.org/docs/current/datatype-numeric.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ansh0l reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/main/resources/com/google/cloud/spanner/jdbc/DatabaseMetaData_GetCrossReferences.sql
@@ -1,3 +1,4 @@
/*GSQL*/
/*
* Copyright 2019 Google LLC

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Question: Usually I've observed Copyright comments to be the first line / comment in code bases. Is it ok to have the /*GSQL*/ as the first line instead, given its trivial nature?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, there is no requirement that the copyright header is the outright first part of a source file (although it is common practice). See also https://opensource.google/documentation/reference/copyright

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ansh0l ansh0l Feb 15, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, this is helpful.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/ITAbstractJdbcTest.java
}
if (EmulatorSpannerHelper.isUsingEmulator()) {
scriptFile = "CreateMusicTables_Emulator.sql";
} else {

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We've removed the else block for scriptFile. Wouldn't this be needed for the regular getDialect() == Dialect. GOOGLE_STANDARD_SQL case?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No, because we are now initializing it on the line above to the default value (i.e. non-emulator value).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ansh0l reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataWithMockedServerTest.java
.setMetadata(RESULTSET_METADATA)
.build();

private static final String GSQL_STATEMENT = "/*GSQL*/";

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We seem to be relying on the first line starting with /*GSQL*/. Are there any other possible approaches for differentiating? Example: different directory structure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

No, this is actually used by the backend to determine which query engine to use for the query, so we mimic it here. The metadata queries are defined only once, and they are all defined in standard dialect. The backend will also look for this header, and if found, use the Google standard dialect for the query even if the database is in PG dialect.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ansh0l reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/JdbcDatabaseMetaDataWithMockedServerTest.java Outdated
}

@Test
public void verifyGoogleSql() throws SQLException {

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

method name is verifyGoogleSql(), but we seem to be validating the true assertions in the case dialect == Dialect.POSTGRESQL. Should the method name be different?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, the method name is a little confusing. What we are verifying here is that the /*GSQL*/ header is kept in the SQL statement without comments if the dialect is PostgreSQL, and that it is removed if the dialect is Google_Standard_Sql.
I've added a comment to the test and updated the test name to verifyGoogleSqlHeaderIsCorrectlyParsed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ansh0l reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/JdbcPreparedStatementTest.java

@Test
public void testInvalidSql() {
String sql = "SELECT * FROM Singers WHERE SingerId='";

@ansh0l ansh0l Feb 12, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: I think there is a missing ' character around the end of String sql = "SELECT * FROM Singers WHERE SingerId='";

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That is intentional. This is testing the behavior when an invalid SQL string is used.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ansh0l reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
ansh0l
ansh0l reviewed Feb 12, 2022
View reviewed changes
Comment thread src/test/java/com/google/cloud/spanner/jdbc/PgNumericResultSetTest.java
.build();
private static final String QUERY = "SELECT " + COLUMN_NAME + " FROM Table WHERE Id = 0";
private static final int MAX_PG_NUMERIC_SCALE = 131_072;
private static final int MAX_PG_NUMERIC_PRECISION = 16_383;

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

131_072 or 16_383 do not look like int, can you explain the above 2 lines.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Java actually allows underscores in int literals for better readability: https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ansh0l ansh0l Feb 15, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, that is helpful.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/com/google/cloud/spanner/jdbc/PgNumericResultSetTest.java Outdated
final String underflow =
BigDecimal.valueOf(Short.MIN_VALUE).subtract(BigDecimal.ONE).toString();
final String maxValue = Short.MAX_VALUE + "";
final String overflow = BigDecimal.valueOf(Short.MAX_VALUE).add(BigDecimal.ONE).toString();

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm curious, why do we use BigDecimal instead of int/long for calculating overflow and underflow of Short?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Seems like a typical case of copy-paste from the test method for longs. I've updated them to use long and/or int where possible.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcReadOnlyTest.java Outdated
final Map<String, String> googleStandardSqlScripts =
ImmutableMap.of("TEST_READ_ONLY", "ITReadOnlySpannerTest.sql");
final Map<String, String> postgresScripts =
ImmutableMap.of("TEST_READ_ONLY", "ITPgReadOnlySpannerTest.sql");

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

regarding ITPgReadOnlySpannerTest.sql and ITPg*.sql files: Should we consider moving them to a separate folder with more verbose name of the folder?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@olavloite olavloite Feb 15, 2022

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think that's a good idea. I've moved the PG script files to a separate PostgreSQL folder.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/test/java/com/google/cloud/spanner/jdbc/it/ITJdbcSqlScriptTest.java
@@ -1,282 +0,0 @@
/*

@ansh0l ansh0l Feb 12, 2022

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Note to other reviwers: this file ITJdbcSqlScriptTest.java seems to have been generalized as ITJdbcScriptTest.java and github is not able to detect the diff.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@olavloite
fix: address review comments
7eb2bd5
ansh0l
ansh0l approved these changes Feb 15, 2022
View reviewed changes

@ansh0l ansh0l left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Adding LGTM. This depends on other changes being merged and released, so the Do Not Release tag is already applied on it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
thiagotnunes
thiagotnunes approved these changes Feb 16, 2022
View reviewed changes

@thiagotnunes thiagotnunes left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
olavloite added 2 commits February 19, 2022 10:19
@olavloite
Merge branch 'main' into postgresql
18ba450
@olavloite
deps: bump java-spanner to 6.19.1
0c31be6
@olavloite olavloite removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 19, 2022
olavloite added 4 commits February 19, 2022 11:12
@olavloite
feat: support automatic dialect detection
7d1943f
@olavloite
deps: remove threeten + add gax
a4292be
@olavloite
build: use owned instance for integration tests
704855c
@olavloite
build: use same instance as the client library
2df341d
@olavloite
olavloite merged commit f9daa19 into main Feb 19, 2022
@olavloite
olavloite deleted the postgresql branch February 19, 2022 11:20
@release-please release-please Bot mentioned this pull request Feb 19, 2022
chore(main): release 2.6.0 #753
Merged
gcf-merge-on-green Bot pushed a commit that referenced this pull request Feb 24, 2022
@release-please
chore(main): release 2.6.0 (#753)
07bf15d
🤖 I have created a release *beep* *boop*
---


## [2.6.0](v2.5.11...v2.6.0) (2022-02-24)


### Features

* add support for PostgreSQL dialect ([#739](#739)) ([f9daa19](f9daa19))


### Bug Fixes

* create specific metadata queries for PG ([#759](#759)) ([caffda0](caffda0))


### Dependencies

* update dependency com.google.cloud:google-cloud-spanner-bom to v6.20.0 ([#758](#758)) ([311d1ca](311d1ca))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
suztomo pushed a commit to suztomo/google-cloud-java that referenced this pull request Mar 23, 2026
@release-please
chore(main): release 2.6.0 (googleapis#753)
b05b329
🤖 I have created a release *beep* *boop*
---


## [2.6.0](googleapis/java-spanner-jdbc@v2.5.11...v2.6.0) (2022-02-24)


### Features

* add support for PostgreSQL dialect ([googleapis#739](googleapis/java-spanner-jdbc#739)) ([c6b2e91](googleapis/java-spanner-jdbc@c6b2e91))


### Bug Fixes

* create specific metadata queries for PG ([googleapis#759](googleapis/java-spanner-jdbc#759)) ([92e05d0](googleapis/java-spanner-jdbc@92e05d0))


### Dependencies

* update dependency com.google.cloud:google-cloud-spanner-bom to v6.20.0 ([googleapis#758](googleapis/java-spanner-jdbc#758)) ([6bcf53b](googleapis/java-spanner-jdbc@6bcf53b))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

2 more reviewers
@thiagotnunes thiagotnunes thiagotnunes approved these changes
@ansh0l ansh0l ansh0l approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: spanner Issues related to the googleapis/java-spanner-jdbc API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@olavloite @thiagotnunes @ansh0l
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.