use of org.apache.flink.table.sources.tsextractors.ExistingField in project flink by apache.
the class RowtimeValidator method getRowtimeComponents.
// utilities
public static Optional<Tuple2<TimestampExtractor, WatermarkStrategy>> getRowtimeComponents(DescriptorProperties properties, String prefix) {
// create timestamp extractor
TimestampExtractor extractor;
Optional<String> t = properties.getOptionalString(prefix + ROWTIME_TIMESTAMPS_TYPE);
if (!t.isPresent()) {
return Optional.empty();
}
switch(t.get()) {
case ROWTIME_TIMESTAMPS_TYPE_VALUE_FROM_FIELD:
String field = properties.getString(prefix + ROWTIME_TIMESTAMPS_FROM);
extractor = new ExistingField(field);
break;
case ROWTIME_TIMESTAMPS_TYPE_VALUE_FROM_SOURCE:
extractor = StreamRecordTimestamp.INSTANCE;
break;
case ROWTIME_TIMESTAMPS_TYPE_VALUE_CUSTOM:
Class<TimestampExtractor> clazz = properties.getClass(prefix + ROWTIME_TIMESTAMPS_CLASS, TimestampExtractor.class);
extractor = EncodingUtils.decodeStringToObject(properties.getString(prefix + ROWTIME_TIMESTAMPS_SERIALIZED), clazz);
break;
default:
throw new ValidationException("Unsupported rowtime timestamps type: " + t.get());
}
// create watermark strategy
WatermarkStrategy strategy;
String s = properties.getString(prefix + ROWTIME_WATERMARKS_TYPE);
switch(s) {
case ROWTIME_WATERMARKS_TYPE_VALUE_PERIODIC_ASCENDING:
strategy = new AscendingTimestamps();
break;
case ROWTIME_WATERMARKS_TYPE_VALUE_PERIODIC_BOUNDED:
long delay = properties.getLong(prefix + ROWTIME_WATERMARKS_DELAY);
strategy = new BoundedOutOfOrderTimestamps(delay);
break;
case ROWTIME_WATERMARKS_TYPE_VALUE_FROM_SOURCE:
strategy = PreserveWatermarks.INSTANCE;
break;
case ROWTIME_WATERMARKS_TYPE_VALUE_CUSTOM:
Class<WatermarkStrategy> clazz = properties.getClass(prefix + ROWTIME_WATERMARKS_CLASS, WatermarkStrategy.class);
strategy = EncodingUtils.decodeStringToObject(properties.getString(prefix + ROWTIME_WATERMARKS_SERIALIZED), clazz);
break;
default:
throw new RuntimeException("Unsupported rowtime timestamps type: " + s);
}
return Optional.of(new Tuple2<>(extractor, strategy));
}
Aggregations