Skip to content

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

Merged
merged 12 commits into from
Mar 15, 2022

Conversation

olavloite
Copy link
Collaborator

@olavloite olavloite commented Mar 8, 2022

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

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/java-spanner API. label Mar 8, 2022
@olavloite olavloite changed the title feat: add namespace for client side statements in PostgreSQL dialect chore: add namespace for client side statements in PostgreSQL dialect Mar 8, 2022
@olavloite olavloite marked this pull request as ready for review March 9, 2022 11:42
@olavloite olavloite requested review from a team as code owners March 9, 2022 11:42
@olavloite olavloite requested review from thiagotnunes and ansh0l March 9, 2022 11:43
@olavloite olavloite requested a review from thiagotnunes March 14, 2022 18:45
return "postgresql/SetReadOnlyStalenessTest.sql";
case GOOGLE_STANDARD_SQL:
default:
return "SetReadOnlyStalenessTest.sql";
Copy link
Contributor

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)

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 like to defer that to a separate PR.

@olavloite olavloite requested a review from thiagotnunes March 15, 2022 06:10
Copy link
Contributor

@thiagotnunes thiagotnunes left a comment

Choose a reason for hiding this comment

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

LGTM

@olavloite olavloite merged commit 12a0acb into main Mar 15, 2022
@olavloite olavloite deleted the spangres-parser-ga branch March 15, 2022 06:36
Copy link
Contributor

@ansh0l ansh0l left a 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();
Copy link
Contributor

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?

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, 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) {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.
Copy link
Contributor

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?

Copy link
Collaborator Author

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;

/**
Copy link
Contributor

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)?

Copy link
Collaborator Author

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");
Copy link
Contributor

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

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, this is an interesting one:

  1. The default in PostgreSQL is read committed. That is not supported by Spangres.
  2. 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/"
Copy link
Contributor

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?

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 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;");
Copy link
Contributor

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?

Copy link
Collaborator Author

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:

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks!

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 API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants