Class AvroIO.TypedWrite<UserT,DestinationT,OutputT>
- All Implemented Interfaces:
Serializable,HasDisplayData
- Enclosing class:
AvroIO
AvroIO.write(java.lang.Class<T>).- See Also:
-
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexpand(PCollection<UserT> input) Override this method to specify how thisPTransformshould be expanded on the givenInputT.voidpopulateDisplayData(DisplayData.Builder builder) Register display data for the given transform or component.Writes to file(s) with the given output prefix.<NewDestinationT>
AvroIO.TypedWrite<UserT, NewDestinationT, OutputT> to(DynamicAvroDestinations<UserT, NewDestinationT, OutputT> dynamicDestinations) Deprecated.to(FileBasedSink.FilenamePolicy filenamePolicy) Writes to files named according to the givenFileBasedSink.FilenamePolicy.to(ResourceId outputPrefix) Writes to file(s) with the given output prefix.to(ValueProvider<String> outputPrefix) Liketo(String).toResource(ValueProvider<ResourceId> outputPrefix) Liketo(ResourceId).withBadRecordErrorHandler(ErrorHandler<BadRecord, ?> errorHandler) SeeFileIO.Write.withBadRecordErrorHandler(ErrorHandler)for details on usage.withCodec(CodecFactory codec) Writes to Avro file(s) compressed using specified codec.withDatumWriterFactory(AvroSink.DatumWriterFactory<OutputT> datumWriterFactory) Specifies aAvroSink.DatumWriterFactoryto use for creatingDatumWriterinstances.withFormatFunction(@Nullable SerializableFunction<UserT, OutputT> formatFunction) Specifies a format function to convertAvroIO.TypedWriteto the output type.withMaxNumWritersPerBundle(@Nullable Integer maxNumWritersPerBundle) See.invalid reference
WriteFiles#withMaxNumWritersPerBundle()withMetadata(Map<String, Object> metadata) Writes to Avro file(s) with the specified metadata.withNumShards(int numShards) Configures the number of output shards produced overall (when using unwindowed writes) or per-window (when using windowed writes).Forces a single file as output and empty shard name template.withSchema(Schema schema) Sets the output schema.withShardNameTemplate(String shardTemplate) Uses the givenShardNameTemplatefor naming output files.withSuffix(String filenameSuffix) Configures the filename suffix for written files.withSyncInterval(int syncInterval) Sets the approximate number of uncompressed bytes to write in each block for the AVRO container format.withTempDirectory(ResourceId tempDirectory) Set the base directory used to generate temporary files.withTempDirectory(ValueProvider<ResourceId> tempDirectory) Set the base directory used to generate temporary files.Preserves windowing of input elements and writes them to files based on the element's window.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, setDisplayData, setResourceHints, toString, validate, validate
-
Constructor Details
-
TypedWrite
public TypedWrite()
-
-
Method Details
-
to
Writes to file(s) with the given output prefix. SeeFileSystemsfor information on supported file systems.The name of the output files will be determined by the
FileBasedSink.FilenamePolicyused.By default, a
DefaultFilenamePolicywill build output filenames using the specified prefix, a shard name template (seewithShardNameTemplate(String), and a common suffix (if supplied usingwithSuffix(String)). This default can be overridden usingto(FilenamePolicy). -
to
Writes to file(s) with the given output prefix. SeeFileSystemsfor information on supported file systems. This prefix is used by theDefaultFilenamePolicyto generate filenames.By default, a
DefaultFilenamePolicywill build output filenames using the specified prefix, a shard name template (seewithShardNameTemplate(String), and a common suffix (if supplied usingwithSuffix(String)). This default can be overridden usingto(FilenamePolicy).This default policy can be overridden using
to(FilenamePolicy), in which casewithShardNameTemplate(String)andwithSuffix(String)should not be set. Custom filename policies do not automatically see this prefix - you should explicitly pass the prefix into yourFileBasedSink.FilenamePolicyobject if you need this.If
withTempDirectory(org.apache.beam.sdk.options.ValueProvider<org.apache.beam.sdk.io.fs.ResourceId>)has not been called, this filename prefix will be used to infer a directory for temporary files. -
to
Liketo(String). -
toResource
public AvroIO.TypedWrite<UserT,DestinationT, toResourceOutputT> (ValueProvider<ResourceId> outputPrefix) Liketo(ResourceId). -
to
public AvroIO.TypedWrite<UserT,DestinationT, toOutputT> (FileBasedSink.FilenamePolicy filenamePolicy) Writes to files named according to the givenFileBasedSink.FilenamePolicy. A directory for temporary files must be specified usingwithTempDirectory(org.apache.beam.sdk.options.ValueProvider<org.apache.beam.sdk.io.fs.ResourceId>). -
to
@Deprecated public <NewDestinationT> AvroIO.TypedWrite<UserT,NewDestinationT, toOutputT> (DynamicAvroDestinations<UserT, NewDestinationT, OutputT> dynamicDestinations) Deprecated.UseFileIO.write()orFileIO.writeDynamic()instead.Use aDynamicAvroDestinationsobject to vendFileBasedSink.FilenamePolicyobjects. These objects can examine the input record when creating aFileBasedSink.FilenamePolicy. A directory for temporary files must be specified usingwithTempDirectory(org.apache.beam.sdk.options.ValueProvider<org.apache.beam.sdk.io.fs.ResourceId>). -
withSyncInterval
Sets the approximate number of uncompressed bytes to write in each block for the AVRO container format. -
withSchema
Sets the output schema. Can only be used when the output type isGenericRecordand when not usingto(DynamicAvroDestinations). -
withFormatFunction
public AvroIO.TypedWrite<UserT,DestinationT, withFormatFunctionOutputT> (@Nullable SerializableFunction<UserT, OutputT> formatFunction) Specifies a format function to convertAvroIO.TypedWriteto the output type. Ifto(DynamicAvroDestinations)is used,FileBasedSink.DynamicDestinations.formatRecord(UserT)must be used instead. -
withTempDirectory
public AvroIO.TypedWrite<UserT,DestinationT, withTempDirectoryOutputT> (ValueProvider<ResourceId> tempDirectory) Set the base directory used to generate temporary files. -
withTempDirectory
Set the base directory used to generate temporary files. -
withShardNameTemplate
Uses the givenShardNameTemplatefor naming output files. This option may only be used when using one of the default filename-prefix to() overrides.See
DefaultFilenamePolicyfor how the prefix, shard name template, and suffix are used. -
withSuffix
Configures the filename suffix for written files. This option may only be used when using one of the default filename-prefix to() overrides.See
DefaultFilenamePolicyfor how the prefix, shard name template, and suffix are used. -
withNumShards
Configures the number of output shards produced overall (when using unwindowed writes) or per-window (when using windowed writes).For unwindowed writes, constraining the number of shards is likely to reduce the performance of a pipeline. Setting this value is not recommended unless you require a specific number of output files.
- Parameters:
numShards- the number of shards to use, or 0 to let the system decide.
-
withoutSharding
Forces a single file as output and empty shard name template. This option is only compatible with unwindowed writes.For unwindowed writes, constraining the number of shards is likely to reduce the performance of a pipeline. Setting this value is not recommended unless you require a specific number of output files.
This is equivalent to
.withNumShards(1).withShardNameTemplate("") -
withWindowedWrites
Preserves windowing of input elements and writes them to files based on the element's window.If using
to(FilenamePolicy). Filenames will be generated usingFileBasedSink.FilenamePolicy.windowedFilename(int, int, org.apache.beam.sdk.transforms.windowing.BoundedWindow, org.apache.beam.sdk.transforms.windowing.PaneInfo, org.apache.beam.sdk.io.FileBasedSink.OutputFileHints). See alsoWriteFiles.withWindowedWrites(). -
withNoSpilling
-
withMaxNumWritersPerBundle
public AvroIO.TypedWrite<UserT,DestinationT, withMaxNumWritersPerBundleOutputT> (@Nullable Integer maxNumWritersPerBundle) See.invalid reference
WriteFiles#withMaxNumWritersPerBundle() -
withCodec
Writes to Avro file(s) compressed using specified codec. -
withDatumWriterFactory
public AvroIO.TypedWrite<UserT,DestinationT, withDatumWriterFactoryOutputT> (AvroSink.DatumWriterFactory<OutputT> datumWriterFactory) Specifies aAvroSink.DatumWriterFactoryto use for creatingDatumWriterinstances. -
withMetadata
Writes to Avro file(s) with the specified metadata.Supported value types are String, Long, and byte[].
-
withBadRecordErrorHandler
public AvroIO.TypedWrite<UserT,DestinationT, withBadRecordErrorHandlerOutputT> (ErrorHandler<BadRecord, ?> errorHandler) SeeFileIO.Write.withBadRecordErrorHandler(ErrorHandler)for details on usage. -
expand
Description copied from class:PTransformOverride this method to specify how thisPTransformshould be expanded on the givenInputT.NOTE: This method should not be called directly. Instead apply the
PTransformshould be applied to theInputTusing theapplymethod.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:
expandin classPTransform<PCollection<UserT>,WriteFilesResult<DestinationT>>
-
populateDisplayData
Description copied from class:PTransformRegister display data for the given transform or component.populateDisplayData(DisplayData.Builder)is invoked by Pipeline runners to collect display data viaDisplayData.from(HasDisplayData). Implementations may callsuper.populateDisplayData(builder)in order to register display data in the current namespace, but should otherwise usesubcomponent.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:
populateDisplayDatain interfaceHasDisplayData- Overrides:
populateDisplayDatain classPTransform<PCollection<UserT>,WriteFilesResult<DestinationT>> - Parameters:
builder- The builder to populate with display data.- See Also:
-
FileIO.write()orFileIO.writeDynamic()instead.