Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@olavloite
Copy link

Adds the client side statement parser for statements that are interpreted and executed by the client instead of being sent to Cloud Spanner. Note:

  • The changes to ClientSideStatements.json are not directly related to this change, but the ClientSideStatementValueConverter implementations were moved from one file to another by one of the previous changes, and I forgot to change that in the .json file.
  • There are more tests for parsing and executing the client side statements, but these rely on the class ConnectionImpl that has not yet been added.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 24, 2019
@olavloite olavloite requested a review from kolea2 July 24, 2019 06:38
}

private Mode parseMode(String name) {
for (Mode mode : Mode.values()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we make this a Set lookup instead?

Copy link
Author

Choose a reason for hiding this comment

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

Changed to a case-insensitive map.


@Override
public AutocommitDmlMode convert(String value) {
for (AutocommitDmlMode mode : AutocommitDmlMode.values()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

same question for this and the below for loops

Copy link
Author

Choose a reason for hiding this comment

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

Changed to a case-insensitive map.

String[] tokens = sql.split("\\s+", 2);
if (tokens.length > 0) {
for (String check : checkStatements) {
if (tokens[0].equalsIgnoreCase(check)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be simplified to sql.startsWith(check) (handling upper and lower case)?

Copy link
Author

Choose a reason for hiding this comment

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

Not really (at least not with the goal of simplifying). The problems with that is that we need a regular expression check for all types of spaces (space, tab, enter, ...), as any type of space character is allowed as a separator between for example CREATE and TABLE. The nice thing with the String#split(String, int) method is that it stops searching after finding the requested matches. String.startsWith(String) does not support regular expressions.

@olavloite olavloite requested a review from kolea2 July 24, 2019 20:08
}

/** The name of this statement. Used in error and info messages. */
private String name;
Copy link
Contributor

Choose a reason for hiding this comment

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

minor - can address later - we should clean up the whitespace here between variable declarations and javadoc

@olavloite olavloite force-pushed the spanner-jdbc-06-statement-parser branch from 34ac7a9 to aa123e1 Compare July 25, 2019 14:53
Copy link
Contributor

@kolea2 kolea2 left a comment

Choose a reason for hiding this comment

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

Please rebase

@olavloite
Copy link
Author

Please rebase

I think your request crossed with my actual rebase :-)

}
}

private final List<String> ddlStatements = Arrays.asList("CREATE", "DROP", "ALTER");
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, can address later - I would change these to sets

@olavloite olavloite merged commit c149d8f into googleapis:spanner-jdbc Jul 25, 2019
olavloite added a commit to olavloite/google-cloud-java that referenced this pull request Aug 5, 2019
* add client side statement parser

* changed loops to a map lookup

* fixed spacing between variables and javadoc

* merge with spanner-jdbc

* changed lists to sets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants