-
Notifications
You must be signed in to change notification settings - Fork 131
chore: add namespace for client side statements in PostgreSQL dialect #1737
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
Conversation
…er into spangres-parser-ga
...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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we have a googlesql
directory? (nevermind if it is too much work)
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 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
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
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. @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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call these GSQL_INSTANCE_STATEMENTS
and PG_INSTANCE_STATEMENTS
?
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, 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we call this getInstanceClientSideStatements
?
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, I don't feel that is right. getInstance
is a very common method name in Java for getting a singleton instance.
throw SpannerExceptionFactory.newSpannerException( | ||
ErrorCode.INVALID_ARGUMENT, "Unknown or unsupported dialect: " + dialect); | ||
} | ||
} | ||
|
||
/** | ||
* Reads statement definitions from ClientSideStatements.json and parses these as Java objects. |
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.
Should we rename importStatements
to gsqlImportStatements
?
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.
Agree, but I would propose making it more natural for reading, so importPgStatements
and importGsqlStatements
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
|
||
/** |
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 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)?
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.
Correct
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
try { | ||
writer = | ||
new PrintWriter( | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this as SCRIPT_FILE_PATH
?
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 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.
@@ -43,7 +43,7 @@ Connection getConnection() { | |||
.setCredentials(NoCredentials.getInstance()) | |||
.setUri(ConnectionImplTest.URI) | |||
.build()); | |||
log("SET READONLY=TRUE;"); | |||
logWithNamespace("SET %sREADONLY=TRUE;"); |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a simple helper method that we added ourselves in the PR here:
Line 144 in 4a341a2
void logWithNamespace(String statement) { |
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!
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