Method: projects.instances.databases.sessions.partitionQuery

Creates a set of partition tokens that can be used to execute a query operation in parallel. Each of the returned partition tokens can be used by sessions.executeStreamingSql to specify a subset of the query result to read. The same session and read-only transaction must be used by the PartitionQueryRequest used to create the partition tokens and the ExecuteSqlRequests that use the partition tokens. Partition tokens become invalid when the session used to create them is deleted or begins a new transaction.

HTTP request

POST https://spanner.googleapis.com/v1/{session=projects/*/instances/*/databases/*/sessions/*}:partitionQuery

The URL uses Google API HTTP annotation syntax.

Path parameters

Parameters
session

string

Required. The session used to create the partitions.

Authorization requires the following Google IAM permission on the specified resource session:

  • spanner.databases.partitionQuery

Request body

The request body contains data with the following structure:

JSON representation
{
  "transaction": {
    object(TransactionSelector)
  },
  "sql": string,
  "params": {
    object
  },
  "paramTypes": {
    string: {
      object(Type)
    },
    ...
  },
  "partitionOptions": {
    object(PartitionOptions)
  },
}
Fields
transaction

object(TransactionSelector)

sessions.read only snapshot transactions are supported, read/write and single use transactions are not.

sql

string

The query request to generate partitions for. The request will fail if the query is not root partitionable. The query plan of a root partitionable query has a single distributed union operator. A distributed union operator conceptually divides one or more tables into multiple splits, remotely evaluates a subquery independently on each split, and then unions all results.

params

object (Struct format)

The SQL query string can contain parameter placeholders. A parameter placeholder consists of '@' followed by the parameter name. Parameter names consist of any combination of letters, numbers, and underscores.

Parameters can appear anywhere that a literal value is expected. The same parameter name can be used more than once, for example: "WHERE id > @msg_id AND id < @msg_id + 100"

It is an error to execute an SQL query with unbound parameters.

Parameter values are specified using params, which is a JSON object whose keys are parameter names, and whose values are the corresponding parameter values.

paramTypes

map (key: string, value: object(Type))

It is not always possible for Cloud Spanner to infer the right SQL type from a JSON value. For example, values of type BYTES and values of type STRING both appear in params as JSON strings.

In these cases, paramTypes can be used to specify the exact SQL type for some or all of the SQL query parameters. See the definition of Type for more information about SQL types.

An object containing a list of "key": value pairs. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.

partitionOptions

object(PartitionOptions)

Additional options that affect how many partitions are created.

Response body

If successful, the response body contains an instance of PartitionResponse.

Authorization Scopes

Requires one of the following OAuth scopes:

  • https://www.googleapis.com/auth/spanner.data
  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Auth Guide.

Try it!

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Spanner Documentation