Camel Components

Google BigQuery Standard SQL

Since Camel 2.23

Only producer is supported

The Google BigQuery SQL component provides access to Cloud BigQuery Infrastructure via the Google Client Services API.

The current implementation supports only standard SQL DML queries.

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-google-bigquery</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.x.x</version>
</dependency>

Authentication Configuration

Google BigQuery component authentication is targeted for use with the GCP Service Accounts. For more information please refer to Google Cloud Platform Auth Guide

Google security credentials can be set explicitly by providing the path to the GCP credentials file location.

Or they are set implicitly, where the connection factory falls back on Application Default Credentials.

When you have the service account key you can provide authentication credentials to your application code. Google security credentials can be set through the component endpoint:

Java-only: endpoint URI as Java string variable
String endpoint = "google-bigquery-sql://project-id:query?serviceAccountKey=/home/user/Downloads/my-key.json";

You can also use the base64 encoded content of the authentication credentials file if you don’t want to set a file system path.

Java-only: endpoint URI as Java string variable
String endpoint = "google-bigquery-sql://project-id:query?serviceAccountKey=base64:<base64 encoded>";

Or by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS :

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"

URI Format

google-bigquery-sql://project-id:query?[options]

Examples:

google-bigquery-sql://project-17248459:delete * from test.table where id=@myId

google-bigquery-sql://project-17248459:delete * from ${datasetId}.${tableId} where id=@myId

The query can contain two kinds of placeholder, @name and ${name}. They are not interchangeable: see Query Placeholders below.

You can externalize your SQL queries to files in the classpath or file system as shown:

google-bigquery-sql://project-17248459::classpath:delete.sql

Configuring Options

Camel components are configured on two separate levels:

  • component level

  • endpoint level

Configuring Component Options

At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.

For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.

Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.

You can configure components using:

  • the Component DSL.

  • in a configuration file (application.properties, *.yaml files, etc).

  • directly in the Java code.

Configuring Endpoint Options

You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.

Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.

A good practice when configuring options is to use Property Placeholders.

Property placeholders provide a few benefits:

  • They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.

  • They allow externalizing the configuration from the code.

  • They help the code to become more flexible and reusable.

The following two sections list all the options, firstly for the component followed by the endpoint.

Component Options

The Google BigQuery Standard SQL component supports the following options which are listed below.

Name Description Default Type

connectionFactory (producer)

Autowired The org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory that provides the BigQuery client for the endpoints that do not set their own connectionFactory.

GoogleBigQueryConnectionFactory

lazyStartProducer (producer)

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

projectId (producer)

The ID of a Google Cloud project. Not used: an endpoint takes the project ID from its URI.

String

autowiredEnabled (advanced)

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

boolean

Endpoint Options

The Google BigQuery Standard SQL endpoint is configured using URI syntax:

google-bigquery-sql:projectId:queryString

With the following path and query parameters:

Path Parameters

Name Description Default Type

projectId (common)

Required The ID of the Google Cloud project that runs the query jobs. The endpoint also sets it as the project of the BigQuery client that it creates.

String

queryString (common)

Required The GoogleSQL (standard SQL) query or statement to run, or a resource with the query, such as classpath:query.sql, loaded when the producer starts. A named query parameter takes its value from the entry of that name of a Map body, else from the header of that name, and a ${name} placeholder is replaced by the text of the header or exchange property of that name.

String

Query Parameters

Name Description Default Type

connectionFactory (producer)

Autowired The org.apache.camel.component.google.bigquery.GoogleBigQueryConnectionFactory that provides the BigQuery client. If not set, the connectionFactory of the component is used, and if that is not set either, the endpoint creates one from the serviceAccountKey and projectId options.

GoogleBigQueryConnectionFactory

outputType (producer)

How the producer returns the rows of a SELECT. SELECT_LIST returns one page as a List of Maps, with the CamelGoogleBigQueryNextPageToken and CamelGoogleBigQueryJobId headers. STREAM_LIST returns an Iterator of Maps that fetches all the pages while it is read, and sets no header.

Enum values:

  • SELECT_LIST

  • STREAM_LIST

SELECT_LIST

OutputType

pageSize (producer)

The maximum number of rows in a page of SELECT results. With 0 or less, BigQuery chooses the page size.

0

long

pageToken (producer)

The token of the page of SELECT results to return, from the CamelGoogleBigQueryNextPageToken header of a previous call. If not set, the first page is returned. The CamelGoogleBigQueryPageToken header replaces it.

String

lazyStartProducer (producer (advanced))

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

boolean

serviceAccountKey (security)

The location of the JSON key file of the service account to authenticate with Google Cloud, such as a classpath:, file: or https: resource, or base64: followed by the Base64 encoded content of the file. If not set, Application Default Credentials are used. It is not used when a connectionFactory is set.

String

Message Headers

The Google BigQuery Standard SQL component supports the following message header(s), which is/are listed below:

Name Description Default Type

CamelGoogleBigQueryTranslatedQuery (producer)

Constant: TRANSLATED_QUERY

The query that the producer sends to BigQuery, after it has replaced the ${name} placeholders. The producer sets it.

String

CamelGoogleBigQueryJobId (producer)

Constant: JOB_ID

The ID of a query job. When set, the producer does not run the query but waits for this job and returns its result, for example to read the next page with the CamelGoogleBigQueryPageToken header. The producer sets it after a SELECT with the SELECT_LIST output type.

JobId

CamelGoogleBigQueryPageToken (producer)

Constant: PAGE_TOKEN

The token of the page of SELECT results to return, from the CamelGoogleBigQueryNextPageToken header of a previous call. It replaces the pageToken option. Send it with the CamelGoogleBigQueryJobId header of that call, so the page is read from the same job.

String

CamelGoogleBigQueryNextPageToken (producer)

Constant: NEXT_PAGE_TOKEN

The token of the next page of SELECT results, or null for the last page. The producer sets it with the SELECT_LIST output type. Send it in the CamelGoogleBigQueryPageToken header to read the next page.

String

Message Body

The message body at each side of the Google BigQuery Standard SQL component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.

Side Body Description

Producer input

any

The query is set on the endpoint. A Map body gives the values of the @name parameters, before the headers of the same name; any other body is ignored.

Producer output

list, value or null

For a SELECT the rows of the page, a Map per row whose scalar values are the text BigQuery returns, with the next page token and the job id in headers; with outputType=STREAM_LIST an Iterator of those Maps over all pages. For a DML statement the number of affected rows as a Long, and no body for another statement, such as DDL (CREATE TABLE), which has no such number.

  • With outputType=STREAM_LIST: iterator, value or null

The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.

Producer Endpoints

Google BigQuery SQL endpoint expects the payload to be either empty or a map of query parameters.

The value of an @name parameter comes from the header of that name, or from the map in the body. The following route deletes the row whose id is in the message body:

- route:
    from:
      uri: direct:deleteRow
      steps:
        - setHeader:
            name: myId
            expression:
              simple:
                expression: "${body}"
        - to:
            uri: "google-bigquery-sql:project-17248459:delete from test.table where id=@myId"
        - log:
            message: "Deleted ${body} rows"

Query Placeholders

A query may contain two kinds of placeholder. They cover different positions in a SQL statement and are not interchangeable.

Form Substitutes Mechanism

@name

Values

Sent to BigQuery as a named query parameter, separately from the query text.

${name}

Identifiers, such as dataset and table names

Spliced into the query text as literal characters before the query is sent.

@name - query parameters

Use @name for every value.

Parameters in the form @name are taken from the message body when it is a Map, otherwise from the message headers, and are bound as BigQuery named query parameters. The com.google.cloud.bigquery.StandardSQLTypeName of the parameter is detected from the Java type of the value using <T> QueryParameterValue<T>.of(T value, Class<T> type).

Because the value is sent to BigQuery separately from the query text, it cannot alter the structure of the query. It is always treated as data.

${name} - literal identifier substitution

Parameters in the form ${name} are replaced with the String value of the matching message header, or of the exchange property when no such header exists, before the query is sent. If neither is present, the exchange fails with a RuntimeExchangeException.

The substitution is a literal text splice: the value is inserted into the query exactly as it appears, with no quoting or escaping applied. This form exists because BigQuery named query parameters can bind values but cannot bind identifiers, so a dataset or table name cannot be supplied through @name:

google-bigquery-sql://project-17248459:delete * from ${datasetId}.${tableId} where id=@myId
${name} is not parameter binding. Use it only for identifiers such as dataset and table names, and only with values that your route controls. A value containing SQL syntax changes the structure of the executed query instead of being treated as data, so a ${name} placeholder must never be populated from message content supplied by an untrusted sender. Use @name for values.

Query Types

The component supports both SELECT and DML (INSERT, UPDATE, DELETE) queries:

  • SELECT queries - Return data based on configured outputType (SELECT_LIST or STREAM_LIST)

  • DML queries - Return the number of affected rows as Long

  • Other statements, such as DDL (CREATE TABLE, DROP TABLE) - Return no body (null), as BigQuery gives no number of affected rows for them

Output Types

The component supports two output types for SELECT queries, configured using the outputType parameter

SELECT_LIST (default)

Returns all query results as a List<Map<String, Object>> loaded into memory.

Characteristics:

  • All rows from current page loaded into memory

  • Message body: List<Map<String, Object>>

  • Manual pagination via pageSize and pageToken parameters

  • Sets CamelGoogleBigQueryNextPageToken header for next page

  • Sets CamelGoogleBigQueryJobId header for continued pagination with same job

  • Results can be accessed multiple times

STREAM_LIST

Returns an Iterator<Map<String, Object>> for memory-efficient streaming of large result sets. Rows are loaded lazily as the iterator is consumed.

Characteristics:

  • Message body: Iterator<Map<String, Object>>

  • Pagination handled automatically by BigQuery SDK using pageSize for internal page fetching

  • Does NOT set CamelGoogleBigQueryNextPageToken or CamelGoogleBigQueryJobId headers

  • Does NOT support manual pageToken control

  • Memory-efficient - only current page in memory

  • Iterator can only be consumed once

Note: The .streaming() modifier on Split EIP is required to prevent loading all rows into memory before splitting.

When to use STREAM_LIST:

  • Result sets with millions of rows

  • Memory-constrained environments

  • One-time sequential processing of rows

  • When using Split EIP in streaming mode

Data Type Mapping

BigQuery result types are mapped to Java types. The values of the scalar types are the text BigQuery returns for them, as a String: convert them where you need a number or a boolean.

BigQuery Type Java Type Notes

INT64

String

For example "42"

FLOAT64

String

For example "1.5"

NUMERIC, BIGNUMERIC

String

STRING

String

BOOL

String

"true" or "false"

BYTES

String

Base64 encoded

DATE, DATETIME, TIME

String

ISO 8601 format

TIMESTAMP

String

The text BigQuery returns, such as the seconds since the epoch

STRUCT (RECORD)

Map<String, Object>

Recursively converted to nested maps

ARRAY (REPEATED)

List<Object>

Elements recursively converted based on their type

RANGE

Map<String, String>

Map with range start and end values

NULL

null