-
Notifications
You must be signed in to change notification settings - Fork 1.1k
spanner-jdbc: Step 06 - Client side statement parser #5814
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
spanner-jdbc: Step 06 - Client side statement parser #5814
Conversation
| } | ||
|
|
||
| private Mode parseMode(String name) { | ||
| for (Mode mode : Mode.values()) { |
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.
can we make this a Set lookup instead?
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.
Changed to a case-insensitive map.
|
|
||
| @Override | ||
| public AutocommitDmlMode convert(String value) { | ||
| for (AutocommitDmlMode mode : AutocommitDmlMode.values()) { |
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.
same question for this and the below for loops
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.
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)) { |
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.
can this be simplified to sql.startsWith(check) (handling upper and lower case)?
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.
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.
| } | ||
|
|
||
| /** The name of this statement. Used in error and info messages. */ | ||
| private String name; |
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.
minor - can address later - we should clean up the whitespace here between variable declarations and javadoc
34ac7a9 to
aa123e1
Compare
kolea2
left a comment
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.
Please rebase
I think your request crossed with my actual rebase :-) |
| } | ||
| } | ||
|
|
||
| private final List<String> ddlStatements = Arrays.asList("CREATE", "DROP", "ALTER"); |
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.
minor, can address later - I would change these to sets
* 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
Adds the client side statement parser for statements that are interpreted and executed by the client instead of being sent to Cloud Spanner. Note:
ClientSideStatements.jsonare not directly related to this change, but theClientSideStatementValueConverterimplementations were moved from one file to another by one of the previous changes, and I forgot to change that in the .json file.ConnectionImplthat has not yet been added.