Class BigQuerySinkBuilder<T>
- Type Parameters:
T- type of the records written by the sink
BigQuerySink.builder().
Required settings: a serializer and a destination. The destination is set through either
table(TableDestination) (fixed table) or destinationResolver(DestinationResolver) (per-record dynamic destinations); the two override
each other and the last call wins.
-
Method Summary
Modifier and TypeMethodDescriptionadditionalFields(AdditionalFields<? super T> additionalFields) Appends physical fields derived from each non-skipped input record.bufferedStreamOptions(BufferedStreamOptions bufferedStreamOptions) Sets the options specific toWriteMethod.STORAGE_API_EXACTLY_ONCE.org.apache.flink.api.connector.sink2.Sink<T>build()Builds the sink for the configuredWriteMethod.cdcOptions(CdcOptions<? super T> cdcOptions) Enables BigQuery change data capture for records appended through the Storage Write API default stream.cdcTableOptions(CdcTableOptions cdcTableOptions) Applies the same desired CDC table contract to every destination.cdcTableOptionsProvider(CdcTableOptionsProvider cdcTableOptionsProvider) Resolves the desired CDC table contract per destination.Sets how the sink handles a CDC destination table that already exists.createDisposition(CreateDisposition createDisposition) Sets the table create disposition.defaultStreamOptions(DefaultStreamOptions defaultStreamOptions) Sets the options specific toWriteMethod.STORAGE_API_AT_LEAST_ONCE.destinationResolver(DestinationResolver<? super T> destinationResolver) Resolves the destination table per record (dynamic destinations).emulatorEndpoint(String emulatorEndpoint) Points the sink's Storage Write API traffic at a BigQuery emulator instead of the production service.emulatorRestEndpoint(String emulatorRestEndpoint) Points the sink's table metadata traffic — table creation underCreateDisposition.CREATE_IF_NEEDED, connector-driven schema updates and the CDC table contract — at a BigQuery emulator instead of the production service.failureHandler(FailureHandler<? super BigQueryFailure> failureHandler) Sets the policy for records that explicitly fail destination resolution or terminally fail after routing (rows rejected by the Storage Write API with per-row error details, rows that fail serialization, and rows exceeding the per-row size limit).fileLoadsOptions(FileLoadsOptions fileLoadsOptions) Sets the options specific toWriteMethod.FILE_LOADS.Sets the BigQuery location (for exampleUSorasia-northeast1) shared by the destination tables.schemaUpdateOptions(SchemaUpdateOptions schemaUpdateOptions) Sets the options gating connector-driven table schema updates.serializer(BigQueryProtoSerializationSchema<? super T> serializer) Sets the record serializer.serviceAccountKeyFile(String serviceAccountKeyFile) Uses the service account in the given JSON key file for every BigQuery client the sink opens and, underWriteMethod.FILE_LOADS, for Cloud Storage staging as well.table(TableDestination table) Writes every record to the given fixed table.tableCreateOptions(TableCreateOptions tableCreateOptions) Applies the same creation options to every table created underCreateDisposition.CREATE_IF_NEEDED.tableCreateOptionsProvider(TableCreateOptionsProvider tableCreateOptionsProvider) Resolves creation options per destination for tables created underCreateDisposition.CREATE_IF_NEEDED.writeMethod(WriteMethod writeMethod) Sets the write method.
-
Method Details
-
writeMethod
Sets the write method. Defaults toWriteMethod.STORAGE_API_AT_LEAST_ONCE.- Parameters:
writeMethod- the write method- Returns:
- this builder
-
table
Writes every record to the given fixed table. Overrides any previously set table or destination resolver.- Parameters:
table- the destination table- Returns:
- this builder
-
destinationResolver
public BigQuerySinkBuilder<T> destinationResolver(DestinationResolver<? super T> destinationResolver) Resolves the destination table per record (dynamic destinations). Overrides any previously set table or destination resolver.- Parameters:
destinationResolver- the resolver- Returns:
- this builder
-
serializer
Sets the record serializer. Required. Besides the row bytes, it supplies each destination's table schema, and returningnullfrom it skips a record rather than failing it.- Parameters:
serializer- the serializer- Returns:
- this builder
-
additionalFields
Appends physical fields derived from each non-skipped input record.The fields are added to protobuf rows and to the physical BigQuery schema used by every write method for table creation and schema reconciliation. When this method is not called, it adds no fields or provider calls. If no other row decorator such as
cdcOptions(CdcOptions)is configured, the sink uses the serializer's schema, descriptor, and row bytes unchanged.- Parameters:
additionalFields- ordered physical fields to append- Returns:
- this builder
-
cdcOptions
Enables BigQuery change data capture for records appended through the Storage Write API default stream.The desired primary key and optional maximum-staleness policy are configured separately through
cdcTableOptions(CdcTableOptions)orcdcTableOptionsProvider(CdcTableOptionsProvider). The sink creates a missing physical schema and primary key through the Tables API only whenCreateDisposition.CREATE_IF_NEEDEDpermits it. Existing-table handling is selected throughcdcTableReconciliationPolicy(CdcTableReconciliationPolicy). CDC pseudocolumns are added to write rows only, never to the physical schema. Rejected forWriteMethod.STORAGE_API_EXACTLY_ONCEandWriteMethod.FILE_LOADS.- Parameters:
cdcOptions- the per-record CDC providers- Returns:
- this builder
-
cdcTableOptions
Applies the same desired CDC table contract to every destination.Primary-key columns are required only when the sink must create a missing table or when
CdcTableReconciliationPolicy.RECONCILEneeds an authoritative key. An existing table underCdcTableReconciliationPolicy.VERIFY_ONLYmay supply its key from BigQuery metadata. Overrides any previously set options or provider.- Parameters:
cdcTableOptions- the desired CDC table contract- Returns:
- this builder
-
cdcTableOptionsProvider
public BigQuerySinkBuilder<T> cdcTableOptionsProvider(CdcTableOptionsProvider cdcTableOptionsProvider) Resolves the desired CDC table contract per destination. Overrides fixed CDC table options.- Parameters:
cdcTableOptionsProvider- the provider- Returns:
- this builder
-
cdcTableReconciliationPolicy
Sets how the sink handles a CDC destination table that already exists. Defaults toCdcTableReconciliationPolicy.VERIFY_ONLY.This policy is independent of
CreateDisposition: reconciliation never authorizes creation underCreateDisposition.CREATE_NEVER.- Parameters:
policy- the existing-table policy- Returns:
- this builder
-
createDisposition
Sets the table create disposition. Defaults toCreateDisposition.CREATE_IF_NEEDED.- Parameters:
createDisposition- the create disposition- Returns:
- this builder
-
tableCreateOptions
Applies the same creation options to every table created underCreateDisposition.CREATE_IF_NEEDED. Overrides any previously set options or provider. Defaults toTableCreateOptions.defaults()(plain tables). CDC primary-key and maximum-staleness properties belong toCdcTableOptionsinstead.- Parameters:
tableCreateOptions- the creation options- Returns:
- this builder
-
tableCreateOptionsProvider
public BigQuerySinkBuilder<T> tableCreateOptionsProvider(TableCreateOptionsProvider tableCreateOptionsProvider) Resolves creation options per destination for tables created underCreateDisposition.CREATE_IF_NEEDED. Overrides any previously set options or provider.- Parameters:
tableCreateOptionsProvider- the provider- Returns:
- this builder
-
schemaUpdateOptions
Sets the options gating connector-driven table schema updates. Defaults toSchemaUpdateOptions.defaults()(updates disabled).Schema changes made externally (for example via DDL) are always picked up without a job restart; these options only control whether the sink may update destination table schemas itself when the serializer's schema evolves past the table's.
- Parameters:
schemaUpdateOptions- the schema update options- Returns:
- this builder
-
failureHandler
public BigQuerySinkBuilder<T> failureHandler(FailureHandler<? super BigQueryFailure> failureHandler) Sets the policy for records that explicitly fail destination resolution or terminally fail after routing (rows rejected by the Storage Write API with per-row error details, rows that fail serialization, and rows exceeding the per-row size limit). Defaults toFailureHandler.failJob().The handler decides per failure: returning normally drops the record, throwing fails the write or checkpoint. Transient append failures are retried without involving the handler, and terminal request failures such as
INVALID_ARGUMENTalways fail the job. The sink drives the handler's lifecycle (open/flush/close) as documented onFailureHandler. The parameter is contravariant, so a cross-connectorFailureHandler<FailedElement>is accepted as-is.- Parameters:
failureHandler- the handler- Returns:
- this builder
-
location
Sets the BigQuery location (for exampleUSorasia-northeast1) shared by the destination tables. Optional; setting it avoids a per-table metadata lookup when opening Storage Write API connections, and underWriteMethod.FILE_LOADSit becomes the location every load job runs in and is looked up under. When unset,FILE_LOADSderives each job's location from its destination dataset's metadata instead — onedatasets.getper dataset per committer, which needs thebigquery.datasets.getpermission there — so a sink routing to datasets in several regions should leave it unset.- Parameters:
location- the BigQuery location- Returns:
- this builder
-
fileLoadsOptions
Sets the options specific toWriteMethod.FILE_LOADS. Required for that write method and rejected for every other one.- Parameters:
fileLoadsOptions- the file-loads options- Returns:
- this builder
-
bufferedStreamOptions
Sets the options specific toWriteMethod.STORAGE_API_EXACTLY_ONCE. Required for that write method (all knobs are defaulted, soBufferedStreamOptions.builder().build()is a valid value) and rejected for every other one.- Parameters:
bufferedStreamOptions- the buffered-stream options- Returns:
- this builder
-
defaultStreamOptions
Sets the options specific toWriteMethod.STORAGE_API_AT_LEAST_ONCE. Optional for that write method — the default write method is chosen by not choosing, so unlike the other write-method option objects nothing forces this one into view, and an unconfigured sink usesDefaultStreamOptions.builder().build()— and rejected for every other one.- Parameters:
defaultStreamOptions- the default-stream options- Returns:
- this builder
-
serviceAccountKeyFile
Uses the service account in the given JSON key file for every BigQuery client the sink opens and, underWriteMethod.FILE_LOADS, for Cloud Storage staging as well. Optional; when unset, clients use application-default credentials.The builder stores only the path in the job graph. Each runtime component reads the file when it first creates a client, so the file must be available at the same path on every Task Manager that runs a writer or committer.
- Parameters:
serviceAccountKeyFile- the service-account JSON key-file path- Returns:
- this builder
-
emulatorEndpoint
Points the sink's Storage Write API traffic at a BigQuery emulator instead of the production service. The write stream opened for each destination connects to the givenhost:portover a plaintext channel with no credentials, so this must only ever be used against an emulator (for example a testcontainersgoccy/bigquery-emulator). Optional; when unset the sink connects to BigQuery with configured credentials or ADC.BigQuery serves its two transports on separate ports — gRPC for the Storage Write API, REST for table metadata — so this endpoint covers the gRPC half only, and a job that also creates tables, evolves their schemas or manages a CDC table needs
emulatorRestEndpoint(String)beside it. That is a deviation from the sibling connectors, each of which needs one transport and so exposes one endpoint.Rejected under
WriteMethod.FILE_LOADS: that write method stages files to Cloud Storage, which no emulator here stands in for, so an endpoint could only be half honored.The value is parsed here, so a malformed
host:portis rejected on the client instead of surfacing as a connection failure once the job has been deployed.- Parameters:
emulatorEndpoint- the emulator's gRPC endpoint ashost:port- Returns:
- this builder
- Throws:
IllegalArgumentException- if the endpoint is nothost:portwith a port in 1..65535
-
emulatorRestEndpoint
Points the sink's table metadata traffic — table creation underCreateDisposition.CREATE_IF_NEEDED, connector-driven schema updates and the CDC table contract — at a BigQuery emulator instead of the production service. The REST client is built againsthttp://host:portwith no credentials, so this must only ever be used against an emulator. Optional; when unset the metadata client uses configured credentials or ADC — so a sink doing any of those three with onlyemulatorEndpoint(String)set still reaches real BigQuery.This is the REST half of
emulatorEndpoint(String); see there for why the two are separate and for theWriteMethod.FILE_LOADSrejection, which applies to both.- Parameters:
emulatorRestEndpoint- the emulator's REST endpoint ashost:port, without a scheme- Returns:
- this builder
- Throws:
IllegalArgumentException- if the endpoint is nothost:portwith a port in 1..65535
-
build
Builds the sink for the configuredWriteMethod.- Returns:
- the sink
-