-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support partitioned queries (#1300)
Adds support for partitioned queries to the JDBC driver. Partitioned queries can be executed either using SQL statements or specific Cloud Spanner methods that are exposed by the specific Cloud Spanner JDBC interfaces.
- Loading branch information
Showing
12 changed files
with
964 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcPartitionedQueryResultSet.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.spanner.jdbc; | ||
|
||
import com.google.cloud.spanner.Options.QueryOption; | ||
import com.google.cloud.spanner.PartitionOptions; | ||
import java.sql.ResultSet; | ||
|
||
/** | ||
* Result set that is returned for partitioned queries, e.g. for 'run partitioned query select ...' | ||
* or for {@link CloudSpannerJdbcPreparedStatement#runPartitionedQuery(PartitionOptions, | ||
* QueryOption...)}. | ||
*/ | ||
public interface CloudSpannerJdbcPartitionedQueryResultSet extends ResultSet { | ||
/** Returns the number of partitions that this result set contains. */ | ||
int getNumPartitions(); | ||
|
||
/** Returns the degree of parallelism that this result set uses. */ | ||
int getParallelism(); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcPreparedStatement.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner.jdbc; | ||
|
||
import com.google.cloud.spanner.Options.QueryOption; | ||
import com.google.cloud.spanner.PartitionOptions; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* This interface is implemented by {@link PreparedStatement}s that are created on Cloud Spanner | ||
* JDBC connections. | ||
*/ | ||
public interface CloudSpannerJdbcPreparedStatement extends PreparedStatement { | ||
|
||
/** | ||
* Partitions this query, so it can be executed in parallel. This method returns a {@link | ||
* ResultSet} with a string-representation of the partitions that were created. These strings can | ||
* be used to execute a partition either on this connection or an any other connection (on this | ||
* host or an any other host) by calling the method {@link #runPartition()}. This method will | ||
* automatically enable data boost for the query if {@link | ||
* CloudSpannerJdbcConnection#isDataBoostEnabled()} returns true. | ||
*/ | ||
ResultSet partitionQuery(PartitionOptions partitionOptions, QueryOption... options) | ||
throws SQLException; | ||
|
||
/** | ||
* Executes the given partition of a query. The partition that should be executed must be set as a | ||
* string parameter on this {@link PreparedStatement} using {@link #setString(int, String)}. The | ||
* value should be a string that was returned by {@link #partitionQuery(PartitionOptions, | ||
* QueryOption...)}. | ||
*/ | ||
ResultSet runPartition() throws SQLException; | ||
|
||
/** | ||
* Executes the given query as a partitioned query. The query will first be partitioned using the | ||
* {@link #partitionQuery(PartitionOptions, QueryOption...)} method. Each of the partitions will | ||
* then be executed in the background, and the results will be merged into a single result set. | ||
* | ||
* <p>This method will use {@link CloudSpannerJdbcConnection#getMaxPartitionedParallelism()} | ||
* threads to execute the partitioned query. Set this variable to a higher/lower value to | ||
* increase/decrease the degree of parallelism used for execution. | ||
*/ | ||
CloudSpannerJdbcPartitionedQueryResultSet runPartitionedQuery( | ||
PartitionOptions partitionOptions, QueryOption... options) throws SQLException; | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/google/cloud/spanner/jdbc/CloudSpannerJdbcStatement.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner.jdbc; | ||
|
||
import com.google.cloud.spanner.Options.QueryOption; | ||
import com.google.cloud.spanner.PartitionOptions; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Statement; | ||
|
||
/** | ||
* This interface is implemented by {@link Statement}s that are created on Cloud Spanner JDBC | ||
* connections. | ||
*/ | ||
public interface CloudSpannerJdbcStatement extends Statement { | ||
|
||
/** | ||
* Partitions the given query, so it can be executed in parallel. This method returns a {@link | ||
* ResultSet} with a string-representation of the partitions that were created. These strings can | ||
* be used to execute a partition either on this connection or an any other connection (on this | ||
* host or an any other host) by calling the method {@link #runPartition(String)}. This method | ||
* will automatically enable data boost for the query if {@link | ||
* CloudSpannerJdbcConnection#isDataBoostEnabled()} returns true. | ||
*/ | ||
ResultSet partitionQuery(String query, PartitionOptions partitionOptions, QueryOption... options) | ||
throws SQLException; | ||
|
||
/** | ||
* Executes the given partition of a query. The encodedPartitionId should be a string that was | ||
* returned by {@link #partitionQuery(String, PartitionOptions, QueryOption...)}. | ||
*/ | ||
ResultSet runPartition(String encodedPartitionId) throws SQLException; | ||
|
||
/** | ||
* Executes the given query as a partitioned query. The query will first be partitioned using the | ||
* {@link #partitionQuery(String, PartitionOptions, QueryOption...)} method. Each of the | ||
* partitions will then be executed in the background, and the results will be merged into a | ||
* single result set. | ||
* | ||
* <p>This method will use {@link CloudSpannerJdbcConnection#getMaxPartitionedParallelism()} | ||
* threads to execute the partitioned query. Set this variable to a higher/lower value to | ||
* increase/decrease the degree of parallelism used for execution. | ||
*/ | ||
CloudSpannerJdbcPartitionedQueryResultSet runPartitionedQuery( | ||
String query, PartitionOptions partitionOptions, QueryOption... options) throws SQLException; | ||
} |
Oops, something went wrong.