# Interface QuerySplitter (3.1.0)

3.1.0 (latest) 2.40.0 2.37.0 2.36.0 2.34.0 2.33.3 2.32.3 2.31.4 2.30.0 2.29.1 2.28.2 2.27.1 2.26.4 2.25.2 2.24.3 2.23.0 2.22.0 2.21.3 2.20.2 2.19.2 2.18.5 2.17.6

    public interface QuerySplitter

Provides the ability to split a query into multiple shards.

## Methods

### getSplits(Query query, PartitionId partition, int numSplits, Datastore datastore)

    public abstract List<Query> getSplits(Query query, PartitionId partition, int numSplits, Datastore datastore)

Returns a list of sharded [Query](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query)s for the given query.

This will create up to the desired number of splits, however it may return less splits if
the desired number of splits is unavailable. This will happen if the number of split points
provided by the underlying Datastore is less than the desired number, which will occur if the
number of results for the query is too small.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query` the query to split. |
| `partition` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.PartitionId` the partition the query is running in. |
| `numSplits` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` the desired number of splits. |
| `datastore` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.client.Datastore` the datastore to run on. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.client.DatastoreException` | if there was a datastore error while generating query splits. |

### getSplits(Query query, PartitionId partition, int numSplits, Datastore datastore, Timestamp readTime)

    public default List<Query> getSplits(Query query, PartitionId partition, int numSplits, Datastore datastore, Timestamp readTime)

> [!WARNING]
> **Beta**
>
> This feature is covered by the [Pre-GA Offerings Terms](https://docs.cloud.google.com/terms/service-terms#1) of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see the launch stage descriptions.

Same as [#getSplits(Query, PartitionId, int, Datastore)](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.client.QuerySplitter#com_google_datastore_v1_client_QuerySplitter_getSplits_com_google_datastore_v1_Query_com_google_datastore_v1_PartitionId_int_com_google_datastore_v1_client_Datastore_) but the splits are based on
`readTime`, and the returned sharded [Query](https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query)s should also be executed with `
readTime`. Reading from a timestamp is currently a private preview feature in Datastore.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `query` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query` |
| `partition` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.PartitionId` |
| `numSplits` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |
| `datastore` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.client.Datastore` |
| `readTime` | `https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.Timestamp.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.Query>` |   |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.datastore.v1.client.DatastoreException` |   |