Class SpannerIO.Write

All Implemented Interfaces:
Serializable, HasDisplayData
Enclosing class:
SpannerIO

public abstract static class SpannerIO.Write extends PTransform<PCollection<Mutation>,SpannerWriteResult>
A PTransform that writes Mutation objects to Google Cloud Spanner.
See Also:
  • Constructor Details

    • Write

      public Write()
  • Method Details

    • withSpannerConfig

      public SpannerIO.Write withSpannerConfig(SpannerConfig spannerConfig)
      Specifies the Cloud Spanner configuration.
    • withProjectId

      public SpannerIO.Write withProjectId(String projectId)
      Specifies the Cloud Spanner project.
    • withProjectId

      public SpannerIO.Write withProjectId(ValueProvider<String> projectId)
      Specifies the Cloud Spanner project.
    • withInstanceId

      public SpannerIO.Write withInstanceId(String instanceId)
      Specifies the Cloud Spanner instance.
    • withInstanceId

      public SpannerIO.Write withInstanceId(ValueProvider<String> instanceId)
      Specifies the Cloud Spanner instance.
    • withDatabaseId

      public SpannerIO.Write withDatabaseId(String databaseId)
      Specifies the Cloud Spanner database.
    • withDatabaseId

      public SpannerIO.Write withDatabaseId(ValueProvider<String> databaseId)
      Specifies the Cloud Spanner database.
    • withHost

      public SpannerIO.Write withHost(ValueProvider<String> host)
      Specifies the Cloud Spanner host.
    • withHost

      public SpannerIO.Write withHost(String host)
      Specifies the Cloud Spanner host.
    • withEmulatorHost

      public SpannerIO.Write withEmulatorHost(ValueProvider<String> emulatorHost)
      Specifies the Cloud Spanner emulator host.
    • withEmulatorHost

      public SpannerIO.Write withEmulatorHost(String emulatorHost)
    • withDialectView

      public SpannerIO.Write withDialectView(PCollectionView<Dialect> dialect)
    • withCommitDeadline

      public SpannerIO.Write withCommitDeadline(Duration commitDeadline)
      Specifies the deadline for the Commit API call. Default is 15 secs. DEADLINE_EXCEEDED errors will prompt a backoff/retry until the value of withMaxCumulativeBackoff(Duration) is reached. DEADLINE_EXCEEDED errors are reported with logging and counters.
    • withMaxCommitDelay

      public SpannerIO.Write withMaxCommitDelay(long millis)
      Specifies max commit delay for the Commit API call for throughput optimized writes. If not set, Spanner might set a small delay if it thinks that will amortize the cost of the writes. For more information about the feature, see documentation
    • withMaxCumulativeBackoff

      public SpannerIO.Write withMaxCumulativeBackoff(Duration maxCumulativeBackoff)
      Specifies the maximum cumulative backoff time when retrying after DEADLINE_EXCEEDED errors. Default is 15 mins.

      If the mutations still have not been written after this time, they are treated as a failure, and handled according to the setting of withFailureMode(FailureMode).

    • grouped

      public SpannerIO.WriteGrouped grouped()
      Same transform but can be applied to PCollection of MutationGroup.
    • withBatchSizeBytes

      public SpannerIO.Write withBatchSizeBytes(long batchSizeBytes)
      Specifies the batch size limit (max number of bytes mutated per batch). Default value is 1MB
    • withFailureMode

      public SpannerIO.Write withFailureMode(SpannerIO.FailureMode failureMode)
      Specifies failure mode. SpannerIO.FailureMode.FAIL_FAST mode is selected by default.
    • withMaxNumMutations

      public SpannerIO.Write withMaxNumMutations(long maxNumMutations)
      Specifies the cell mutation limit (maximum number of mutated cells per batch). Default value is 5000
    • withMaxNumRows

      public SpannerIO.Write withMaxNumRows(long maxNumRows)
      Specifies the row mutation limit (maximum number of mutated rows per batch). Default value is 1000
    • withSchemaReadySignal

      public SpannerIO.Write withSchemaReadySignal(PCollection<?> signal)
      Specifies an optional input PCollection that can be used as the signal for Wait.OnSignal to indicate when the database schema is ready to be read.

      To be used when the database schema is created by another section of the pipeline, this causes this transform to wait until the signal PCollection has been closed before reading the schema from the database.

      See Also:
    • withGroupingFactor

      public SpannerIO.Write withGroupingFactor(int groupingFactor)
      Specifies the multiple of max mutation (in terms of both bytes per batch and cells per batch) that is used to select a set of mutations to sort by key for batching. This sort uses local memory on the workers, so using large values can cause out of memory errors. Default value is 1000.
    • withLowPriority

      public SpannerIO.Write withLowPriority()
    • withHighPriority

      public SpannerIO.Write withHighPriority()
    • expand

      public SpannerWriteResult expand(PCollection<Mutation> input)
      Description copied from class: PTransform
      Override this method to specify how this PTransform should be expanded on the given InputT.

      NOTE: This method should not be called directly. Instead apply the PTransform should be applied to the InputT using the apply method.

      Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).

      Specified by:
      expand in class PTransform<PCollection<Mutation>,SpannerWriteResult>
    • populateDisplayData

      public void populateDisplayData(DisplayData.Builder builder)
      Description copied from class: PTransform
      Register display data for the given transform or component.

      populateDisplayData(DisplayData.Builder) is invoked by Pipeline runners to collect display data via DisplayData.from(HasDisplayData). Implementations may call super.populateDisplayData(builder) in order to register display data in the current namespace, but should otherwise use subcomponent.populateDisplayData(builder) to use the namespace of the subcomponent.

      By default, does not register any display data. Implementors may override this method to provide their own display data.

      Specified by:
      populateDisplayData in interface HasDisplayData
      Overrides:
      populateDisplayData in class PTransform<PCollection<Mutation>,SpannerWriteResult>
      Parameters:
      builder - The builder to populate with display data.
      See Also: