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>
ABucketAssignerthat assigns to buckets based on current system time.The
DateTimeBucketerwill create directories of the following form:/{basePath}/{dateTimePath}/. ThebasePathis the path that was specified as a base path when creating the new bucket. ThedateTimePathis determined based on the current system time and the user provided format string.DateTimeFormatteris 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 newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH".DateTimeBucketAssigner(String formatString)Creates a newDateTimeBucketAssignerwith the given date/time format string.DateTimeBucketAssigner(String formatString, ZoneId zoneId)Creates a newDateTimeBucketAssignerwith the given date/time format string using the given timezone.DateTimeBucketAssigner(ZoneId zoneId)Creates a newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH"using the given timezone.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetBucketId(IN element, BucketAssigner.Context context)Returns the identifier of the bucket the provided element should be put into.org.apache.flink.core.io.SimpleVersionedSerializer<String>getSerializer()StringtoString()
-
-
-
Constructor Detail
-
DateTimeBucketAssigner
public DateTimeBucketAssigner()
Creates a newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH".
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(String formatString)
Creates a newDateTimeBucketAssignerwith the given date/time format string.- Parameters:
formatString- The format string that will be given toSimpleDateFormatto determine the bucket id.
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(ZoneId zoneId)
Creates a newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH"using the given timezone.- Parameters:
zoneId- The timezone used to formatDateTimeFormatterfor bucket id.
-
DateTimeBucketAssigner
public DateTimeBucketAssigner(String formatString, ZoneId zoneId)
Creates a newDateTimeBucketAssignerwith the given date/time format string using the given timezone.- Parameters:
formatString- The format string that will be given toDateTimeFormatterto determine the bucket path.zoneId- The timezone used to formatDateTimeFormatterfor bucket id.
-
-
Method Detail
-
getBucketId
public String getBucketId(IN element, BucketAssigner.Context context)
Description copied from interface:BucketAssignerReturns the identifier of the bucket the provided element should be put into.- Specified by:
getBucketIdin 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 pathprovided during the initialization of the file sink.
-
getSerializer
public org.apache.flink.core.io.SimpleVersionedSerializer<String> getSerializer()
- Specified by:
getSerializerin interfaceBucketAssigner<IN,String>- Returns:
- A
SimpleVersionedSerializercapable of serializing/deserializing the elements of typeBucketID. That is the type of the objects returned by theBucketAssigner.getBucketId(Object, BucketAssigner.Context).
-
-