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

@Public public class SpannerSinkBuilder<T> extends Object
Builder for the Spanner sink; created through SpannerSink.builder().

database(DatabaseDestination) and serializer(SpannerMutationSerializationSchema) are required; everything else is defaulted.

  • Method Details

    • database

      public SpannerSinkBuilder<T> database(DatabaseDestination database)
      Sets the database to write to. Required.
      Parameters:
      database - the database
      Returns:
      this builder
    • serializer

      public SpannerSinkBuilder<T> serializer(SpannerMutationSerializationSchema<? super T> serializer)
      Sets the schema turning records into mutations. Required.
      Parameters:
      serializer - the serialization schema
      Returns:
      this builder
    • writerOptions

      public SpannerSinkBuilder<T> writerOptions(SpannerWriterOptions writerOptions)
      Sets the writer's tuning options. Optional; defaults to SpannerWriterOptions.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 to FailureHandler.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 — a NULL in a NOT NULL column, an over-long value, a CHECK or foreign-key constraint. Optional; defaults to ConstraintViolationPolicy.FAIL_JOB.

      Under ConstraintViolationPolicy.ROUTE_TO_FAILURE_HANDLER such a mutation reaches failedMutationHandler(FailureHandler), so that handler decides whether it fails the job, is dropped or is dead-lettered.

      Parameters:
      constraintViolationPolicy - the policy
      Returns:
      this builder
    • serviceAccountKeyFile

      public SpannerSinkBuilder<T> serviceAccountKeyFile(String 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

      public SpannerSinkBuilder<T> emulatorEndpoint(String 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 as host:port
      Returns:
      this builder
      Throws:
      IllegalArgumentException - if the endpoint is not host:port with a port in 1..65535
    • build

      public org.apache.flink.api.connector.sink2.Sink<T> build()
      Builds the sink.
      Returns:
      the sink
      Throws:
      IllegalStateException - if a required option is missing