MCPcopy Index your code
hub / github.com/GoogleCloudDataproc/spark-bigquery-connector

github.com/GoogleCloudDataproc/spark-bigquery-connector @0.44.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.44.2 ↗ · + Follow
2,869 symbols 11,069 edges 420 files 129 documented · 4% updated 8d ago0.44.2 · 2026-05-21★ 42342 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Apache Spark SQL connector for Google BigQuery

The connector supports reading Google BigQuery tables into Spark's DataFrames, and writing DataFrames back into BigQuery. This is done by using the Spark SQL Data Source API to communicate with BigQuery.

Unreleased Changes

This Readme may include documentation for changes that haven't been released yet. The latest release's documentation and source code are found here.

https://github.com/GoogleCloudDataproc/spark-bigquery-connector/blob/master/README.md

BigQuery Storage API

The Storage API streams data in parallel directly from BigQuery via gRPC without using Google Cloud Storage as an intermediary.

It has a number of advantages over using the previous export-based read flow that should generally lead to better read performance:

Direct Streaming

It does not leave any temporary files in Google Cloud Storage. Rows are read directly from BigQuery servers using the Arrow or Avro wire formats.

Filtering

The new API allows column and predicate filtering to only read the data you are interested in.

Column Filtering

Since BigQuery is backed by a columnar datastore, it can efficiently stream data without reading all columns.

Predicate Filtering

The Storage API supports arbitrary pushdown of predicate filters. Connector version 0.8.0-beta and above support pushdown of arbitrary filters to Bigquery.

There is a known issue in Spark that does not allow pushdown of filters on nested fields. For example - filters like address.city = "Sunnyvale" will not get pushdown to Bigquery.

Dynamic Sharding

The API rebalances records between readers until they all complete. This means that all Map phases will finish nearly concurrently. See this blog article on how dynamic sharding is similarly used in Google Cloud Dataflow.

See Configuring Partitioning for more details.

Requirements

Enable the BigQuery Storage API

Follow these instructions.

Create a Google Cloud Dataproc cluster (Optional)

If you do not have an Apache Spark environment you can create a Cloud Dataproc cluster with pre-configured auth. The following examples assume you are using Cloud Dataproc, but you can use spark-submit on any cluster.

Any Dataproc cluster using the API needs the 'bigquery' or 'cloud-platform' scopes. Dataproc clusters have the 'bigquery' scope by default, so most clusters in enabled projects should work by default e.g.

MY_CLUSTER=...
gcloud dataproc clusters create "$MY_CLUSTER"

Downloading and Using the Connector

The latest version of the connector is publicly available in the following links:

version Link
Spark 4.1 gs://spark-lib/bigquery/spark-4.1-bigquery-${next-release-tag}-preview.jar(HTTP link)
Spark 4.0 gs://spark-lib/bigquery/spark-4.0-bigquery-${next-release-tag}.jar(HTTP link)
Spark 3.5 gs://spark-lib/bigquery/spark-3.5-bigquery-${next-release-tag}.jar(HTTP link)
Spark 3.4 gs://spark-lib/bigquery/spark-3.4-bigquery-${next-release-tag}.jar(HTTP link)
Spark 3.3 gs://spark-lib/bigquery/spark-3.3-bigquery-${next-release-tag}.jar(HTTP link)
Spark 3.2 gs://spark-lib/bigquery/spark-3.2-bigquery-${next-release-tag}.jar(HTTP link)
Spark 3.1 gs://spark-lib/bigquery/spark-3.1-bigquery-${next-release-tag}.jar(HTTP link)
Spark 2.4 gs://spark-lib/bigquery/spark-2.4-bigquery-0.37.0.jar(HTTP link)
Scala 2.13 gs://spark-lib/bigquery/spark-bigquery-with-dependencies_2.13-${next-release-tag}.jar (HTTP link)
Scala 2.12 gs://spark-lib/bigquery/spark-bigquery-with-dependencies_2.12-${next-release-tag}.jar (HTTP link)
Scala 2.11 gs://spark-lib/bigquery/spark-bigquery-with-dependencies_2.11-0.29.0.jar (HTTP link)

The first six versions are Java based connectors targeting Spark 2.4/3.1/3.2/3.3/3.4/3.5 of all Scala versions built on the new Data Source APIs (Data Source API v2) of Spark.

The final two connectors are Scala based connectors, please use the jar relevant to your Spark installation as outlined below.

Connector to Spark Compatibility Matrix

Connector \ Spark 2.3 2.4 3.0 3.1 3.2 3.3 3.4 3.5
spark-3.5-bigquery
spark-3.4-bigquery
spark-3.3-bigquery
spark-3.2-bigquery
spark-3.1-bigquery
spark-2.4-bigquery
spark-bigquery-with-dependencies_2.13
spark-bigquery-with-dependencies_2.12
spark-bigquery-with-dependencies_2.11

Connector to Dataproc Image Compatibility Matrix

| Connector \ Dataproc Image | 1.3 | 1.4 | 1.5 | 2.0 | 2.1 | 2.2 | Serverless

Image 1.0 | Serverless

Image 2.0 | Serverless

Image 2.1 | Serverless

Image 2.2 | |---------------------------------------|---------|---------|---------|---------|---------|---------|-------------------------|-------------------------|-------------------------|-------------------------| | spark-3.5-bigquery | | | | | | ✓ | | | | ✓ | | spark-3.4-bigquery | | | | | | ✓ | | | ✓ | ✓ | | spark-3.3-bigquery | | | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | spark-3.2-bigquery | | | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | spark-3.1-bigquery | | | | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | | spark-2.4-bigquery | | ✓ | ✓ | | | | | | | | | spark-bigquery-with-dependencies_2.13 | | | | | | | | ✓ | ✓ | ✓ | | spark-bigquery-with-dependencies_2.12 | | | ✓ | ✓ | ✓ | ✓ | ✓ | | | | | spark-bigquery-with-dependencies_2.11 | ✓ | ✓ | | | | | | | | |

Maven / Ivy Package Usage

The connector is also available from the Maven Central repository. It can be used using the --packages option or the spark.jars.packages configuration property. Use the following value

version Connector Artifact
Spark 4.1 com.google.cloud.spark:spark-4.1-bigquery:${next-release-tag}-preview
Spark 4.0 com.google.cloud.spark:spark-4.0-bigquery:${next-release-tag}
Spark 3.5 com.google.cloud.spark:spark-3.5-bigquery:${next-release-tag}
Spark 3.4 com.google.cloud.spark:spark-3.4-bigquery:${next-release-tag}
Spark 3.3 com.google.cloud.spark:spark-3.3-bigquery:${next-release-tag}
Spark 3.2 com.google.cloud.spark:spark-3.2-bigquery:${next-release-tag}
Spark 3.1 com.google.cloud.spark:spark-3.1-bigquery:${next-release-tag}
Spark 2.4 com.google.cloud.spark:spark-2.4-bigquery:0.37.0
Scala 2.13 com.google.cloud.spark:spark-bigquery-with-dependencies_2.13:${next-release-tag}
Scala 2.12 com.google.cloud.spark:spark-bigquery-with-dependencies_2.12:${next-release-tag}
Scala 2.11 com.google.cloud.spark:spark-bigquery-with-dependencies_2.11:0.29.0

Specifying the Spark BigQuery connector version in a Dataproc cluster

Dataproc clusters created using image 2.1 and above, or batches using the Dataproc serverless service come with built-in Spark BigQuery connector. Using the standard --jars or --packages (or alternatively, the spark.jars/spark.jars.packages configuration) won't help in this case as the built-in connector takes precedence.

To use another version than the built-in one, please do one of the following:

  • For Dataproc clusters, using image 2.1 and above, add the following flag on cluster creation to upgrade the version --metadata SPARK_BQ_CONNECTOR_VERSION=${next-release-tag}, or --metadata SPARK_BQ_CONNECTOR_URL=gs://spark-lib/bigquery/spark-3.3-bigquery-${next-release-tag}.jar to create the cluster with a different jar. The URL can point to any valid connector JAR for the cluster's Spark version.
  • For Dataproc serverless batches, add the following property on batch creation to upgrade the version: --properties dataproc.sparkBqConnector.version=${next-release-tag}, or --properties dataproc.sparkBqConnector.uri=gs://spark-lib/bigquery/spark-3.3-bigquery-${next-release-tag}.jar to create the batch with a different jar. The URL can point to any valid connector JAR for the runtime's Spark version.

Hello World Example

You can run a simple PySpark wordcount against the API without compilation by running

Dataproc image 1.5 and above

gcloud dataproc jobs submit pyspark --cluster "$MY_CLUSTER" \
  --jars gs://spark-lib/bigquery/spark-bigquery-with-dependencies_2.12-${next-release-tag}.jar \
  examples/python/shakespeare.py

Dataproc image 1.4 and below

gcloud dataproc jobs submit pyspark --cluster "$MY_CLUSTER" \
  --jars gs://spark-lib/bigquery/spark-bigquery-with-dependencies_2.11-0.29.0.jar \
  examples/python/shakespeare.py

Example Codelab

https://codelabs.developers.google.com/codelabs/pyspark-bigquery

Usage

The connector uses the cross language Spark SQL Data Source API:

Reading data from a BigQuery table

``` df = spark.read \ .format(

Extension points exported contracts — how you extend this code

DataWriterContext (Interface)
An internal version to Spark DataSource DataWriter interface @param [6 implementers]
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/write/context/DataWriterContext.java
BigQueryProxyConfig (Interface)
Config interface to provide proxy parameters. The concrete class implementing this interface should implement methods to [3 …
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryProxyConfig.java
BigQueryTableCreator (Interface)
(no doc) [3 implementers]
spark-bigquery-dsv2/spark-3.1-bigquery-lib/src/main/java/com/google/cloud/spark/bigquery/v2/BigQueryTableCreator.java
InputPartitionReaderContext (Interface)
(no doc) [3 implementers]
spark-bigquery-dsv2/spark-bigquery-dsv2-common/src/main/java/com/google/cloud/spark/bigquery/v2/context/InputPartitionReaderContext.java
IntermediateRecordWriter (Interface)
(no doc) [8 implementers]
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/write/context/IntermediateRecordWriter.java
AccessTokenProvider (Interface)
(no doc) [5 implementers]
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/AccessTokenProvider.java
InputPartitionContext (Interface)
(no doc) [3 implementers]
spark-bigquery-dsv2/spark-bigquery-dsv2-common/src/main/java/com/google/cloud/spark/bigquery/v2/context/InputPartitionContext.java
DataFrameToRDDConverter (Interface)
(no doc) [4 implementers]
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/DataFrameToRDDConverter.java

Core symbols most depended-on inside this repo

of
called by 782
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryClient.java
empty
called by 700
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryConfigurationUtil.java
get
called by 392
spark-bigquery-dsv2/spark-bigquery-dsv2-common/src/main/java/com/google/cloud/spark/bigquery/v2/context/InputPartitionReaderContext.java
format
called by 307
spark-bigquery-dsv2/spark-3.5-bigquery-lib/src/main/java/com/google/cloud/spark/bigquery/BigQueryCatalog.java
build
called by 186
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/ReadSessionCreatorConfigBuilder.java
build
called by 177
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/InjectorBuilder.java
create
called by 130
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/write/context/DataSourceWriterContext.java
load
called by 114
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/ProtobufUtils.java

Shape

Method 2,429
Class 399
Interface 30
Enum 9
Function 2

Languages

Java100%
Python1%

Modules by API surface

spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/integration/WriteIntegrationTestBase.java129 symbols
bigquery-connector-common/src/test/java/com/google/cloud/bigquery/connector/common/BigQueryUtilTest.java117 symbols
spark-bigquery-connector-common/src/main/java/com/google/cloud/spark/bigquery/SparkBigQueryConfig.java107 symbols
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryClient.java86 symbols
spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/SparkBigQueryConfigTest.java60 symbols
bigquery-connector-common/src/test/java/com/google/cloud/bigquery/connector/common/BigQueryClientFactoryTest.java53 symbols
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryUtil.java52 symbols
spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/integration/ReadIntegrationTestBase.java46 symbols
spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/SchemaConverterTest.java37 symbols
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryClientFactoryConfig.java35 symbols
bigquery-connector-common/src/main/java/com/google/cloud/bigquery/connector/common/BigQueryConfig.java34 symbols
spark-bigquery-connector-common/src/test/java/com/google/cloud/spark/bigquery/integration/CatalogIntegrationTestBase.java30 symbols

For agents

$ claude mcp add spark-bigquery-connector \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page