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>
A
BucketAssigner that assigns to buckets based on current system time.
The DateTimeBucketer will create directories of the following form:
/{basePath}/{dateTimePath}/. The basePath is the path that was specified as a base path
when creating the new bucket. The dateTimePath 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.streaming.api.functions.sink.filesystem.BucketAssigner
BucketAssigner.Context -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptiongetBucketId(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>toString()
-
Constructor Details
-
DateTimeBucketAssigner
public DateTimeBucketAssigner()Creates a newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH". -
DateTimeBucketAssigner
Creates a newDateTimeBucketAssignerwith the given date/time format string.- Parameters:
formatString- The format string that will be given toSimpleDateFormatto determine the bucket id.
-
DateTimeBucketAssigner
Creates a newDateTimeBucketAssignerwith format string"yyyy-MM-dd--HH"using the given timezone.- Parameters:
zoneId- The timezone used to formatDateTimeFormatterfor bucket id.
-
DateTimeBucketAssigner
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 Details
-
getBucketId
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
- 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).
-
toString
-