public final class DefaultFilenamePolicy extends FileBasedSink.FilenamePolicy
FileBasedSink.FilenamePolicy
for windowed and unwindowed files. This policy is constructed
using three parameters that together define the output name of a sharded file, in conjunction
with the number of shards, index of the particular file, current window and pane information,
using constructName(org.apache.beam.sdk.io.fs.ResourceId, java.lang.String, java.lang.String, int, int, java.lang.String, java.lang.String)
.
Most users will use this DefaultFilenamePolicy
. For more advanced uses in generating
different files for each window and other sharding controls, see the WriteOneFilePerWindow
example pipeline.
Modifier and Type | Class and Description |
---|---|
static class |
DefaultFilenamePolicy.Params
Encapsulates constructor parameters to
DefaultFilenamePolicy . |
static class |
DefaultFilenamePolicy.ParamsCoder
A Coder for
DefaultFilenamePolicy.Params . |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_UNWINDOWED_SHARD_TEMPLATE
The default sharding name template.
|
static java.lang.String |
DEFAULT_WINDOWED_SHARD_TEMPLATE
The default windowed sharding name template used when writing windowed files.
|
Modifier and Type | Method and Description |
---|---|
static DefaultFilenamePolicy |
fromParams(DefaultFilenamePolicy.Params params)
Construct a
DefaultFilenamePolicy from a DefaultFilenamePolicy.Params object. |
static DefaultFilenamePolicy |
fromStandardParameters(ValueProvider<ResourceId> baseFilename,
@Nullable java.lang.String shardTemplate,
@Nullable java.lang.String filenameSuffix,
boolean windowedWrites)
Construct a
DefaultFilenamePolicy . |
void |
populateDisplayData(DisplayData.Builder builder)
Populates the display data.
|
@Nullable ResourceId |
unwindowedFilename(int shardNumber,
int numShards,
FileBasedSink.OutputFileHints outputFileHints)
When a sink has not requested windowed or triggered output, this method will be invoked to
return the file
resource to be created given the base output directory and
a FileBasedSink.OutputFileHints containing information about the file, including a suggested (e.g. |
ResourceId |
windowedFilename(int shardNumber,
int numShards,
BoundedWindow window,
PaneInfo paneInfo,
FileBasedSink.OutputFileHints outputFileHints)
When a sink has requested windowed or triggered output, this method will be invoked to return
the file
resource to be created given the base output directory and a
FileBasedSink.OutputFileHints containing information about the file, including a suggested
extension (e.g. |
public static final java.lang.String DEFAULT_UNWINDOWED_SHARD_TEMPLATE
public static final java.lang.String DEFAULT_WINDOWED_SHARD_TEMPLATE
public static DefaultFilenamePolicy fromStandardParameters(ValueProvider<ResourceId> baseFilename, @Nullable java.lang.String shardTemplate, @Nullable java.lang.String filenameSuffix, boolean windowedWrites)
DefaultFilenamePolicy
.
This is a shortcut for:
DefaultFilenamePolicy.fromParams(new Params()
.withBaseFilename(baseFilename)
.withShardTemplate(shardTemplate)
.withSuffix(filenameSuffix)
.withWindowedWrites())
Where the respective with
methods are invoked only if the value is non-null or true.
public static DefaultFilenamePolicy fromParams(DefaultFilenamePolicy.Params params)
DefaultFilenamePolicy
from a DefaultFilenamePolicy.Params
object.public @Nullable ResourceId unwindowedFilename(int shardNumber, int numShards, FileBasedSink.OutputFileHints outputFileHints)
FileBasedSink.FilenamePolicy
resource
to be created given the base output directory and
a FileBasedSink.OutputFileHints
containing information about the file, including a suggested (e.g.
coming from Compression
).
The shardNumber and numShards parameters, should be used by the policy to generate unique and consistent filenames.
unwindowedFilename
in class FileBasedSink.FilenamePolicy
public ResourceId windowedFilename(int shardNumber, int numShards, BoundedWindow window, PaneInfo paneInfo, FileBasedSink.OutputFileHints outputFileHints)
FileBasedSink.FilenamePolicy
resource
to be created given the base output directory and a
FileBasedSink.OutputFileHints
containing information about the file, including a suggested
extension (e.g. coming from Compression
).
The policy must return unique and consistent filenames for different windows and panes.
windowedFilename
in class FileBasedSink.FilenamePolicy
public void populateDisplayData(DisplayData.Builder builder)
FileBasedSink.FilenamePolicy
populateDisplayData
in class FileBasedSink.FilenamePolicy