Savonitar commented on code in PR #267:
URL: 
https://github.com/apache/flink-connector-kafka/pull/267#discussion_r3682735782


##########
flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/table/KafkaConnectorOptionsUtil.java:
##########
@@ -115,6 +119,28 @@ public static void validateTableSinkOptions(ReadableConfig 
tableOptions) {
         validateSinkPartitioner(tableOptions);
     }
 
+    static void validateAutoOffsetResetStrategy(Properties properties) {
+        String resetStrategy = 
properties.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG);
+        if (resetStrategy == null) {
+            return;
+        }
+
+        boolean valid =
+                Arrays.stream(OffsetResetStrategy.values())
+                        .anyMatch(strategy -> 
strategy.name().equalsIgnoreCase(resetStrategy));

Review Comment:
   > equalsIgnoreCase
   
   Here we accept values case insensitive. However, Kafka's own 
auto.offset.reset validator is case-sensitive, so 
   ```
   'properties.auto.offset.reset' = 'EARLIEST' 
   ```
   passes plan-time validation and then every source subtask dies on the 
TaskManager:
   ```
   Invalid value EARLIEST for configuration auto.offset.reset: ... must be 
either 'earliest', 'latest', 'none'
   ```
   
   This looks like a regression, because on main today, scan.startup.mode = 
'group-offsets' + 'properties.auto.offset.reset' = 'EARLIEST' works, because 
the old getResetStrategy compared via toUpperCase(Locale.ROOT) and the builder 
then overwrote the property with the lower-cased enum name 
https://github.com/apache/flink-connector-kafka/blob/aa6be4bac8aeab15b471820f037fcf3cecca044c/flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/KafkaSourceBuilder.java#L471
 (override flag was **true**)
   
   After this PR the uppercase string survives to the consumer.
   
   I see 2 options:
   1. Normalise with toLowerCase
   OR
   2. Make the validator case-sensitive so at least the failure surfases at 
plan time with the clear message.
   



##########
flink-connector-kafka/src/test/java/org/apache/flink/connector/kafka/dynamic/source/DynamicKafkaSourceBuilderTest.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.connector.kafka.dynamic.source;
+
+import org.apache.flink.connector.kafka.dynamic.metadata.KafkaMetadataService;
+import org.apache.flink.connector.kafka.dynamic.metadata.KafkaStream;
+import 
org.apache.flink.connector.kafka.source.enumerator.initializer.OffsetsInitializer;
+import 
org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema;
+
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.IntegerDeserializer;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/** Tests for {@link DynamicKafkaSourceBuilder}. */
+class DynamicKafkaSourceBuilderTest {
+
+    @Test
+    void testAutoOffsetResetIsNotMaterializedWhenAbsent() throws Exception {
+        assertThat(
+                        extractProperties(baseBuilder().build())
+                                
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+                .isNull();
+    }
+
+    @Test
+    void testAutoOffsetResetUsesExplicitProperty() throws Exception {
+        assertThat(
+                        extractProperties(
+                                        baseBuilder()
+                                                .setProperty(
+                                                        
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
+                                                        "none")
+                                                .build())
+                                
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+                .isEqualTo("none");
+    }
+
+    @Test
+    void testAutoOffsetResetExplicitPropertyOverridesInitializerStrategy() 
throws Exception {
+        assertThat(
+                        extractProperties(
+                                        baseBuilder()
+                                                
.setStartingOffsets(OffsetsInitializer.latest())
+                                                .setProperty(
+                                                        
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
+                                                        "none")
+                                                .build())
+                                
.getProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG))
+                .isEqualTo("none");
+    }
+
+    private DynamicKafkaSourceBuilder<Integer> baseBuilder() {
+        return DynamicKafkaSource.<Integer>builder()
+                .setStreamIds(Collections.singleton("stream-1"))
+                .setKafkaMetadataService(NoOpKafkaMetadataService.INSTANCE)
+                .setDeserializer(
+                        
KafkaRecordDeserializationSchema.valueOnly(IntegerDeserializer.class));
+    }
+
+    private static Properties extractProperties(DynamicKafkaSource<?> source) 
throws Exception {
+        Field field = DynamicKafkaSource.class.getDeclaredField("properties");

Review Comment:
   Could you please clarify, why do we use reflection here ? I checked and 
looks like only this place (and DynamicKafkaSourceReaderTest) use reflection in 
tests.
   Why can't we reuse existing approach: package private accessor, for example?



##########
flink-connector-kafka/src/main/java/org/apache/flink/connector/kafka/source/KafkaPropertiesUtil.java:
##########
@@ -36,6 +39,25 @@ public static void copyProperties(@Nonnull Properties from, 
@Nonnull Properties
         }
     }
 
+    /** Resolves an explicit global or cluster reset strategy before the 
initializer default. */

Review Comment:
   According to the PR description, is my understanding correct, that an 
explicit global auto.offset.reset intentionally wins over a per-cluster value 
supplied via KafkaMetadataService ( the **opposite** of how cluster properties 
override global ones for **every other key**)?



-- 
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]

Reply via email to