Class SpannerSinkBuilder<T>
java.lang.Object
io.github.flink.gcp.connector.spanner.sink.SpannerSinkBuilder<T>
- Type Parameters:
T- type of the records written by the sink
Builder for the Spanner sink; created through
SpannerSink.builder().
database(DatabaseDestination) and serializer(SpannerMutationSerializationSchema) are required; everything else is defaulted.
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.flink.api.connector.sink2.Sink<T>build()Builds the sink.constraintViolationPolicy(ConstraintViolationPolicy constraintViolationPolicy) Sets what happens to a mutation Spanner refuses for violating a constraint — aNULLin aNOT NULLcolumn, an over-long value, aCHECKor foreign-key constraint.database(DatabaseDestination database) Sets the database to write to.emulatorEndpoint(String emulatorEndpoint) Points the sink at a Spanner emulator instead of the real service.failedMutationHandler(FailureHandler<? super FailedMutation> failedMutationHandler) Sets what happens to a mutation the service terminally refused.serializer(SpannerMutationSerializationSchema<? super T> serializer) Sets the schema turning records into mutations.serviceAccountKeyFile(String serviceAccountKeyFile) Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials.writerOptions(SpannerWriterOptions writerOptions) Sets the writer's tuning options.
-
Method Details
-
database
Sets the database to write to. Required.- Parameters:
database- the database- Returns:
- this builder
-
serializer
Sets the schema turning records into mutations. Required.- Parameters:
serializer- the serialization schema- Returns:
- this builder
-
writerOptions
Sets the writer's tuning options. Optional; defaults toSpannerWriterOptions.defaults().- Parameters:
writerOptions- the writer options- Returns:
- this builder
-
failedMutationHandler
public SpannerSinkBuilder<T> failedMutationHandler(FailureHandler<? super FailedMutation> failedMutationHandler) Sets what happens to a mutation the service terminally refused. Optional; defaults toFailureHandler.failJob().- Parameters:
failedMutationHandler- the failure handler- Returns:
- this builder
-
constraintViolationPolicy
public SpannerSinkBuilder<T> constraintViolationPolicy(ConstraintViolationPolicy constraintViolationPolicy) Sets what happens to a mutation Spanner refuses for violating a constraint — aNULLin aNOT NULLcolumn, an over-long value, aCHECKor foreign-key constraint. Optional; defaults toConstraintViolationPolicy.FAIL_JOB.Under
ConstraintViolationPolicy.ROUTE_TO_FAILURE_HANDLERsuch a mutation reachesfailedMutationHandler(FailureHandler), so that handler decides whether it fails the job, is dropped or is dead-lettered.- Parameters:
constraintViolationPolicy- the policy- Returns:
- this builder
-
serviceAccountKeyFile
Authenticates the sink with the service-account JSON key at the given path instead of application-default credentials. The file is read on each TaskManager when its writer is created, so every TaskManager that can run the sink must see the same path. Optional; when unset the real-service path uses application-default credentials.Service-account keys are long-lived secrets. Prefer an attached service account or Workload Identity where the deployment supports one. This setting cannot be combined with
emulatorEndpoint(String), whose plaintext channel carries no credentials.- Parameters:
serviceAccountKeyFile- the service-account JSON key-file path- Returns:
- this builder
-
emulatorEndpoint
Points the sink at a Spanner emulator instead of the real service. Optional; for tests.The emulator needs no credentials, so setting this also stops the client from looking for any.
- 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
-
build
Builds the sink.- Returns:
- the sink
- Throws:
IllegalStateException- if a required option is missing
-