MartijnVisser commented on code in PR #349:
URL:
https://github.com/apache/flink-connector-kafka/pull/349#discussion_r4687157847
##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/KafkaPropertiesUtil.java:
##########
@@ -72,10 +83,39 @@ public static OffsetResetStrategy getResetStrategy(@Nonnull
String offsetResetCo
"%s can not be set to %s.
Valid values: [%s]",
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
offsetResetConfig,
-
Arrays.stream(OffsetResetStrategy.values())
- .map(Enum::name)
-
.map(String::toLowerCase)
-
.collect(Collectors.joining(",")))));
+ VALID_RESET_STRATEGIES)));
+ }
+
+ /**
+ * Returns whether the configured reset strategy is a KIP-1106 duration
based strategy, i.e.
+ * {@code by_duration:<ISO-8601 duration>}. It cannot be mapped to {@link
OffsetResetStrategy}.
+ */
+ public static boolean isDurationBasedReset(@Nonnull String
offsetResetConfig) {
+ return offsetResetConfig.regionMatches(
+ true, 0, BY_DURATION_PREFIX, 0, BY_DURATION_PREFIX.length());
+ }
+
+ /**
+ * Validates a duration based reset strategy and returns it with a
canonical prefix. The
+ * duration itself is kept verbatim because lower-casing the whole value,
or writing back a
+ * value derived from Kafka's parsed strategy, would drop or corrupt the
ISO-8601 duration.
+ */
+ public static String normalizeDurationBasedReset(@Nonnull String
offsetResetConfig) {
+ String normalized =
+ BY_DURATION_PREFIX +
offsetResetConfig.substring(BY_DURATION_PREFIX.length());
+ try {
+ Duration.parse(normalized.substring(BY_DURATION_PREFIX.length()));
Review Comment:
Kafka also rejects negative durations, so `by_duration:-PT1H` passes
`build()` and then fails the job when the reader creates its consumer. Using
the consumer's own validator would keep the two in line.
##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/KafkaDynamicSource.java:
##########
@@ -489,8 +489,12 @@ private OffsetsInitializer getStartingOffsetsInitializer()
{
properties.getProperty(
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
OffsetResetStrategy.NONE.name());
+ // by_duration (KIP-1106) has no OffsetResetStrategy constant;
the property stays
+ // in the consumer config, so keep the initializer's default
strategy.
OffsetResetStrategy offsetResetStrategy =
-
KafkaPropertiesUtil.getResetStrategy(offsetResetConfig);
+
KafkaPropertiesUtil.isDurationBasedReset(offsetResetConfig)
Review Comment:
This is never reached: `validateAndNormalizeAutoOffsetResetStrategy` in
`createKafkaSource` rejects by_duration first, so group-offsets with
by_duration still fails at planning.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]