chore: add namespace for client side statements in PostgreSQL dialect#1737
chore: add namespace for client side statements in PostgreSQL dialect#1737
Conversation
...anner/src/main/java/com/google/cloud/spanner/connection/ConnectionStatementExecutorImpl.java
Show resolved
Hide resolved
...-cloud-spanner/src/main/java/com/google/cloud/spanner/connection/DialectNamespaceHelper.java
Outdated
Show resolved
Hide resolved
...-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json
Outdated
Show resolved
Hide resolved
...-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json
Outdated
Show resolved
Hide resolved
...ud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractConnectionImplTest.java
Outdated
Show resolved
Hide resolved
google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementParserTest.java
Show resolved
Hide resolved
…er into spangres-parser-ga
...-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json
Outdated
Show resolved
Hide resolved
...-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json
Outdated
Show resolved
Hide resolved
...-spanner/src/main/resources/com/google/cloud/spanner/connection/PG_ClientSideStatements.json
Outdated
Show resolved
Hide resolved
| return "postgresql/SetReadOnlyStalenessTest.sql"; | ||
| case GOOGLE_STANDARD_SQL: | ||
| default: | ||
| return "SetReadOnlyStalenessTest.sql"; |
There was a problem hiding this comment.
nit: should we have a googlesql directory? (nevermind if it is too much work)
There was a problem hiding this comment.
I would like to defer that to a separate PR.
google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/StatementParserTest.java
Show resolved
Hide resolved
...rc/test/resources/com/google/cloud/spanner/connection/postgresql/SetStatementTimeoutTest.sql
Outdated
Show resolved
Hide resolved
ansh0l
left a comment
There was a problem hiding this comment.
LGTM. @olavloite : Sorry, got delayed in reviewing. I've added a few minor nits.
| static final ClientSideStatements INSTANCE = importStatements(); | ||
| private static final String PG_STATEMENTS_DEFINITION_FILE = "PG_ClientSideStatements.json"; | ||
| private static final ClientSideStatements INSTANCE = importStatements(); | ||
| private static final ClientSideStatements PG_INSTANCE = pgImportStatements(); |
There was a problem hiding this comment.
Should we call these GSQL_INSTANCE_STATEMENTS and PG_INSTANCE_STATEMENTS?
There was a problem hiding this comment.
Yes, I think that is better to separate them, but I think we can drop the INSTANCE part. So GSQL_STATEMENTS and PG_STATEMENTS.
| private static final ClientSideStatements INSTANCE = importStatements(); | ||
| private static final ClientSideStatements PG_INSTANCE = pgImportStatements(); | ||
|
|
||
| static ClientSideStatements getInstance(Dialect dialect) { |
There was a problem hiding this comment.
Should we call this getInstanceClientSideStatements?
There was a problem hiding this comment.
No, I don't feel that is right. getInstance is a very common method name in Java for getting a singleton instance.
| } | ||
|
|
||
| /** | ||
| * Reads statement definitions from ClientSideStatements.json and parses these as Java objects. |
There was a problem hiding this comment.
Should we rename importStatements to gsqlImportStatements?
There was a problem hiding this comment.
Agree, but I would propose making it more natural for reading, so importPgStatements and importGsqlStatements
| import java.util.concurrent.TimeUnit; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** |
There was a problem hiding this comment.
Just for my understanding, We seem to have made changes to all statementShow* methods here, except statementShowAutocommit. Is that because show variable autocommit would have an same result for both case (gsql/pg)?
| READ_ONLY_TRANSACTION("READ ONLY"), | ||
| READ_WRITE_TRANSACTION("READ WRITE"), | ||
| ISOLATION_LEVEL_DEFAULT("ISOLATION LEVEL DEFAULT"), | ||
| ISOLATION_LEVEL_SERIALIZABLE("ISOLATION LEVEL SERIALIZABLE"); |
There was a problem hiding this comment.
It seems that PG has 4 isolation levels, which one does DEFAULT map to? https://www.postgresql.org/docs/14/transaction-iso.html
There was a problem hiding this comment.
Yes, this is an interesting one:
- The default in PostgreSQL is read committed. That is not supported by Spangres.
- Spangres only supports serializable. So in Spangres we default to that.
| new OutputStreamWriter( | ||
| new FileOutputStream(SCRIPT_FILE, false), StandardCharsets.UTF_8), | ||
| new FileOutputStream( | ||
| "src/test/resources/com/google/cloud/spanner/connection/" |
There was a problem hiding this comment.
Should we have this as SCRIPT_FILE_PATH?
There was a problem hiding this comment.
I personally find it easier to read and see where it's going by having the string literal here, instead of having to look up the constant value somewhere else.
| .setUri(ConnectionImplTest.URI) | ||
| .build()); | ||
| log("SET READONLY=TRUE;"); | ||
| logWithNamespace("SET %sREADONLY=TRUE;"); |
There was a problem hiding this comment.
I'm not able to find more details on logWithNamespace - it seems to have been introduced in this PR. Is it a junit log method? Can you point me to its documentation?
There was a problem hiding this comment.
It's a simple helper method that we added ourselves in the PR here:
Adds PostgreSQL specific client side statements. These are added as a separate JSON file with client side statements to ensure that there are no interference between the statements supported by the two different parsers.
b/223320448