Efrat19 commented on code in PR #347:
URL:
https://github.com/apache/flink-connector-kafka/pull/347#discussion_r4774453044
##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/KafkaPropertiesUtil.java:
##########
@@ -43,57 +45,95 @@ public static void copyProperties(@Nonnull Properties from,
@Nonnull Properties
}
}
- /** Resolves an explicit cluster or global reset strategy before the
initializer default. */
- public static OffsetResetStrategy resolveAutoOffsetResetStrategy(
+ /**
+ * Resolves an explicit cluster or global {@code auto.offset.reset} before
the initializer
+ * default, and returns it in the form {@link
#normalizeAutoOffsetReset(String)} produces.
+ */
+ public static String resolveAutoOffsetReset(
@Nonnull Properties globalProperties,
@Nonnull Properties clusterProperties,
@Nonnull OffsetsInitializer startingOffsetsInitializer) {
- return getResetStrategy(
+ return normalizeAutoOffsetReset(
clusterProperties.getProperty(
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
globalProperties.getProperty(
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
startingOffsetsInitializer.getAutoOffsetResetStrategy().name())));
}
- /** Parses the configured auto offset reset strategy. */
- public static OffsetResetStrategy getResetStrategy(@Nonnull String
offsetResetConfig) {
+ /**
+ * Validates a configured {@code auto.offset.reset} and returns the value
to pass to the
+ * consumer.
+ *
+ * <p>Leading and trailing whitespace is removed first, as the consumer
does. {@code earliest},
+ * {@code latest} and {@code none} are accepted in any case and returned
in lower case. Any
+ * other value, such as {@code by_duration:PT1H}, is checked by the
validator of the {@code
+ * kafka-clients} version on the classpath and returned otherwise
unchanged, so the connector
+ * accepts exactly the strategies the consumer accepts.
+ *
+ * @throws IllegalArgumentException if the consumer would reject the value
+ */
+ public static String normalizeAutoOffsetReset(@Nonnull String
offsetResetConfig) {
+ String trimmed = offsetResetConfig.trim();
+ Optional<OffsetResetStrategy> strategy =
parseOffsetResetStrategy(trimmed);
Review Comment:
```suggestion
Optional<OffsetResetStrategy> strategy =
parseOffsetResetStrategy(offsetResetConfig);
```
Nit: Already trimmed inside `parseOffsetResetStrategy`
--
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]