Skip to content
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

feat: Support query hints for DML statements #1030

Merged
merged 3 commits into from Apr 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,6 +24,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
import java.util.Collections;
import java.util.Objects;
Expand Down Expand Up @@ -457,17 +458,15 @@ static String removeStatementHint(String sql) {
// searching for the first occurrence of a keyword that should be preceded by a closing curly
// brace at the end of the statement hint.
int startStatementHintIndex = sql.indexOf('{');
// Statement hints are only allowed for queries.
// Statement hints are allowed for both queries and DML statements.
int startQueryIndex = -1;
String upperCaseSql = sql.toUpperCase();
for (String keyword : selectStatements) {
Set<String> selectAndDmlStatements =
Sets.union(selectStatements, dmlStatements).immutableCopy();

Choose a reason for hiding this comment

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

if style allows, consider moving the declaration and assignment on a single line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The line was split by the formatter so I guess this is what is needed to be style-conformant.

for (String keyword : selectAndDmlStatements) {
startQueryIndex = upperCaseSql.indexOf(keyword);
if (startQueryIndex > -1) break;
}
if (startQueryIndex <= -1) {
for (String keyword : dmlStatements) {
startQueryIndex = upperCaseSql.indexOf(keyword);
if (startQueryIndex > -1) break;
if (startQueryIndex > -1) {
break;
}
}
if (startQueryIndex > -1) {
Expand Down