Class DateTimeBucketAssigner<IN>
- java.lang.Object
-
- org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.DateTimeBucketAssigner<IN>
-
- All Implemented Interfaces:
Serializable
,BucketAssigner<IN,String>
@PublicEvolving public class DateTimeBucketAssigner<IN> extends Object implements BucketAssigner<IN,String>
ABucketAssigner
that assigns to buckets based on current system time.The
DateTimeBucketer
will create directories of the following form:/{basePath}/{dateTimePath}/
. ThebasePath
is the path that was specified as a base path when creating the new bucket. ThedateTimePath
is determined based on the current system time and the user provided format string.DateTimeFormatter
is used to derive a date string from the current system time and the date format string. The default format string is"yyyy-MM-dd--HH"
so the rolling files will have a granularity of hours.Example:
BucketAssigner bucketAssigner = new DateTimeBucketAssigner("yyyy-MM-dd--HH");
This will create for example the following bucket path:
/base/1976-12-31-14/
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner
BucketAssigner.Context
-
-
Constructor Summary
Constructors Constructor Description DateTimeBucketAssigner()
Creates a newDateTimeBucketAssigner
with format string"yyyy-MM-dd--HH"
.DateTimeBucketAssigner(String formatString)
Creates a newDateTimeBucketAssigner
with the given date/time format string.DateTimeBucketAssigner(String formatString, ZoneId zoneId)
Creates a newDateTimeBucketAssigner
with the given date/time format string using the given timezone.DateTimeBucketAssigner(ZoneId zoneId)
Creates a newDateTimeBucketAssigner
with format string"yyyy-MM-dd--HH"
using the given timezone.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getBucketId(IN element, BucketAssigner.Context context)
Returns the identifier of the bucket the provided element should be put into.SimpleVersionedSerializer<String>
getSerializer()
String
toString()
-
-
-
Constructor Detail
-
DateTimeBucketAssigner
public DateTimeBucketAssigner()
Creates a newDateTimeBucketAssigner
with format string"yyyy-MM-dd--HH"
.
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(String formatString)
Creates a newDateTimeBucketAssigner
with the given date/time format string.- Parameters:
formatString
- The format string that will be given toSimpleDateFormat
to determine the bucket id.
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(ZoneId zoneId)
Creates a newDateTimeBucketAssigner
with format string"yyyy-MM-dd--HH"
using the given timezone.- Parameters:
zoneId
- The timezone used to formatDateTimeFormatter
for bucket id.
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(String formatString, ZoneId zoneId)
Creates a newDateTimeBucketAssigner
with the given date/time format string using the given timezone.- Parameters:
formatString
- The format string that will be given toDateTimeFormatter
to determine the bucket path.zoneId
- The timezone used to formatDateTimeFormatter
for bucket id.
-
-
Method Detail
-
getBucketId
public String getBucketId(IN element, BucketAssigner.Context context)
Description copied from interface:BucketAssigner
Returns the identifier of the bucket the provided element should be put into.- Specified by:
getBucketId
in interfaceBucketAssigner<IN,String>
- Parameters:
element
- The current element being processed.context
- The context used by the current bucket assigner.- Returns:
- A string representing the identifier of the bucket the element should be put into.
The actual path to the bucket will result from the concatenation of the returned string
and the
base path
provided during the initialization of the file sink.
-
getSerializer
public SimpleVersionedSerializer<String> getSerializer()
- Specified by:
getSerializer
in interfaceBucketAssigner<IN,String>
- Returns:
- A
SimpleVersionedSerializer
capable of serializing/deserializing the elements of typeBucketID
. That is the type of the objects returned by theBucketAssigner.getBucketId(Object, BucketAssigner.Context)
.
-
-