-
Notifications
You must be signed in to change notification settings - Fork 132
feat: Add support for Explain feature #1852
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
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
1ea42dd
Added the code for handling the explain
gauravsnj 8c7a5b0
Update ConnectionStatementExecutorImpl.java
gauravsnj 177f07f
Added tests
gauravsnj 242e351
Update PG_ClientSideStatements.json
gauravsnj 053dd92
resolved the comments
gauravsnj 0677368
Update google-cloud-spanner/src/main/resources/com/google/cloud/spann…
gauravsnj 87069ed
Update ConnectionStatementExecutorTest.java
gauravsnj 436775b
Merge remote-tracking branch 'origin/explain-feature' into explain-fe…
gauravsnj 5047608
Update PG_ClientSideStatements.json
gauravsnj f09c6e3
Update PG_ClientSideStatements.json
gauravsnj 411ca77
Formatted the files for ci lint
gauravsnj f663865
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
gauravsnj 4b7127d
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
gauravsnj e3614be
resolved some comments
gauravsnj e125c42
formatted the code
gauravsnj af79b7b
added some code
gauravsnj 7a1937a
added support for "explain (format ) foo" kind of statements
gauravsnj d0c6abf
resolved some comments
gauravsnj 9f084ba
Update ConnectionStatementExecutorImpl.java
gauravsnj 0f76847
fixed a small bug
gauravsnj daddd3e
Added the code for formatting query plan for export
gauravsnj e38e917
Update ConnectionStatementExecutorImpl.java
gauravsnj 60ad94e
Update ConnectionStatementExecutorImpl.java
gauravsnj e2813ab
Update ConnectionStatementExecutorImpl.java
gauravsnj 32fc9de
Update ConnectionStatementExecutorImpl.java
gauravsnj e57da64
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
gauravsnj b4101ad
Changed assertThat to assertEquals
gauravsnj c59e964
Merge remote-tracking branch 'origin/explain-feature' into explain-fe…
gauravsnj a767158
removed unnecessary lines
gauravsnj 1a8fd85
Update google-cloud-spanner/src/main/java/com/google/cloud/spanner/co…
gauravsnj 50808f1
Changed assertThat to assertEquals
gauravsnj 1f4aa32
Update ConnectionStatementExecutorImpl.java
gauravsnj 0610cae
Update ConnectionStatementExecutorImpl.java
gauravsnj faaa7cd
Added tests
gauravsnj dc9dab2
format
gauravsnj 4177cdd
Update PartitionedDmlTransaction.java
gauravsnj 105d8a5
generated sql script
gauravsnj 6162363
resolved comments
gauravsnj d58acc0
resolved comments
gauravsnj 638ae76
Update PG_ClientSideStatements.json
gauravsnj 07e521c
Merge branch 'main' into explain-feature
gauravsnj dd9e83e
Update PG_ClientSideStatements.json
gauravsnj 55f1736
Update PG_ClientSideStatements.json
gauravsnj 2d7649f
Create ITExplainTest.java
gauravsnj 40b3f89
added Integration tests
gauravsnj c272165
reformatted
gauravsnj 10f06e8
changed region
gauravsnj 8695453
Revert "changed region"
gauravsnj 0b66c53
Update ITExplainTest.java
gauravsnj a08c293
Update ITExplainTest.java
gauravsnj 9996f1c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update ConnectionStatementExecutorImpl.java
- Loading branch information
commit 8c7a5b07237c5f52c054140a8b393610965ddf10
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,10 +59,12 @@ | |
import com.google.cloud.spanner.CommitResponse; | ||
import com.google.cloud.spanner.CommitStats; | ||
import com.google.cloud.spanner.Dialect; | ||
import com.google.cloud.spanner.ErrorCode; | ||
import com.google.cloud.spanner.Options.RpcPriority; | ||
import com.google.cloud.spanner.ReadContext.QueryAnalyzeMode; | ||
import com.google.cloud.spanner.ResultSet; | ||
import com.google.cloud.spanner.ResultSets; | ||
import com.google.cloud.spanner.SpannerExceptionFactory; | ||
import com.google.cloud.spanner.Statement; | ||
import com.google.cloud.spanner.Struct; | ||
import com.google.cloud.spanner.TimestampBound; | ||
|
@@ -72,19 +74,26 @@ | |
import com.google.common.base.MoreObjects; | ||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.protobuf.Duration; | ||
import com.google.spanner.v1.RequestOptions; | ||
import com.google.spanner.v1.RequestOptions.Priority; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.annotation.Nullable; | ||
|
||
|
||
/** | ||
* The methods in this class are called by the different {@link ClientSideStatement}s. These method | ||
* calls are then forwarded into a {@link Connection}. | ||
*/ | ||
class ConnectionStatementExecutorImpl implements ConnectionStatementExecutor { | ||
|
||
|
||
private final Set<String> explainOptions = ImmutableSet.of("VERBOSE", "COSTS", "SETTINGS", "BUFFERS", "WAL", "TIMING", "SUMMARY", "FORMAT"); | ||
|
||
static final class StatementTimeoutGetter implements DurationValueGetter { | ||
private final Connection connection; | ||
|
||
|
@@ -447,18 +456,23 @@ public StatementResult statementShowTransactionIsolationLevel() { | |
|
||
@Override | ||
public ResultSet statementExplain(String sql){ | ||
|
||
sql = sql.trim(); | ||
String firstWord = sql.split(" ")[0]; | ||
String firstString = sql.split(" ")[0].toLowerCase(); | ||
|
||
if(explainOptions.contains(firstString)){ | ||
throw SpannerExceptionFactory.newSpannerException( | ||
ErrorCode.UNIMPLEMENTED, String.format("%s is not implemented yet", firstString)); | ||
} | ||
|
||
if(firstWord.equalsIgnoreCase("analyze")) { | ||
if(firstString.equals("analyze") || firstString.equals("analyse")) { | ||
sql = sql.split(" ",2)[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here also use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
Statement statement = Statement.newBuilder(sql).build(); | ||
return getConnection().analyzeQuery(statement, QueryAnalyzeMode.PROFILE); | ||
} | ||
else{ | ||
Statement statement = Statement.newBuilder(sql).build(); | ||
return getConnection().analyzeQuery(statement, QueryAnalyzeMode.PLAN); | ||
|
||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are a couple of improvements that can be added to
sql.split(..)
here:split
invocation to prevent the entire string from being analyzed. Also; as we need the second keyword further below, it would be better to callsplit
only once to get the two first keywords instead of callingsplit
twice.split("\\s+")
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 for suggesting these improvements. I've added them in the code