twalthr commented on code in PR #21808:
URL: https://github.com/apache/flink/pull/21808#discussion_r1091834613
##########
docs/content.zh/docs/connectors/table/kafka.md:
##########
@@ -309,6 +309,31 @@ CREATE TABLE KafkaTable (
<td>Long</td>
<td>在使用 <code>'timestamp'</code> 启动模式时指定启动的时间戳(单位毫秒)。</td>
</tr>
+ <tr>
+ <td><h5>scan.bounded.mode</h5></td>
+ <td>optional</td>
+ <td style="word-wrap: break-word;">unbounded</td>
+ <td>String</td>
Review Comment:
I guess this is not an enum because we still don't support `-` in names?
##########
docs/content.zh/docs/connectors/table/kafka.md:
##########
@@ -485,6 +510,22 @@ ROW<`version` INT, `behavior` STRING>
如果使用了 `specific-offsets`,必须使用另外一个配置项 `scan.startup.specific-offsets` 来为每个
partition 指定起始偏移量,
例如,选项值 `partition:0,offset:42;partition:1,offset:300` 表示 partition `0` 从偏移量
`42` 开始,partition `1` 从偏移量 `300` 开始。
+### Bounded Ending Position
+
+The config option `scan.bounded.mode` specifies the bounded mode for Kafka
consumer. The valid enumerations are:
+<ul>
+<li><span markdown="span">`group-offsets`</span>: bounded from committed
offsets in ZK / Kafka brokers of a specific consumer group.</li>
+<li><span markdown="span">`latest-offset`</span>: bounded from the latest
offset.</li>
+<li><span markdown="span">`timestamp`</span>: bounded from user-supplied
timestamp for each partition.</li>
+<li><span markdown="span">`specific-offsets`</span>: bounded from
user-supplied specific offsets for each partition.</li>
+</ul>
+
+If config option value `scan.bounded.mode` is not set the default is an
unbounded data stream.
Review Comment:
`unbounded data stream` -> `unbounded table`
##########
flink-connectors/flink-connector-kafka/src/main/java/org/apache/flink/streaming/connectors/kafka/config/BoundedMode.java:
##########
@@ -0,0 +1,47 @@
+/*
+ * 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.streaming.connectors.kafka.config;
+
+import org.apache.flink.annotation.Internal;
+
+/** End modes for the Kafka Consumer. */
+@Internal
+public enum BoundedMode {
+
+ /** Do not end consuming */
+ UNBOUNDED,
+
+ /** End from committed offsets in ZK / Kafka brokers of a specific
consumer group (default). */
+ GROUP_OFFSETS,
+
+ /** End from the latest offset. */
Review Comment:
What does that mean in reality? Is the latest offset or group offsets
fetched at the beginning of the execution? Maybe we can improve the docs a bit.
##########
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaTableITCase.java:
##########
@@ -179,6 +180,66 @@ public void testKafkaSourceSink() throws Exception {
deleteTestTopic(topic);
}
+ @Test
+ public void testKafkaSourceSinkWithBoundedSpecificOffsets() throws
Exception {
+ // we always use a different topic name for each parameterized topic,
+ // in order to make sure the topic can be created.
+ final String topic = "bounded_" + format + "_" + UUID.randomUUID();
+ createTestTopic(topic, 1, 1);
+
+ // ---------- Produce an event time stream into Kafka
-------------------
+ String groupId = getStandardProps().getProperty("group.id");
+ String bootstraps = getBootstrapServers();
+
+ final String createTable =
+ String.format(
+ "CREATE TABLE kafka (\n"
+ + " `user_id` INT,\n"
+ + " `item_id` INT,\n"
+ + " `behavior` STRING\n"
+ + ") WITH (\n"
+ + " 'connector' = '%s',\n"
+ + " 'topic' = '%s',\n"
+ + " 'properties.bootstrap.servers' = '%s',\n"
+ + " 'properties.group.id' = '%s',\n"
+ + " 'scan.startup.mode' =
'earliest-offset',\n"
+ + " 'scan.bounded.mode' =
'specific-offsets',\n"
+ + " 'scan.bounded.specific-offsets' =
'partition:0,offset:2',\n"
Review Comment:
Another item for the documentation and potentially tests: What happens if I
don't specify an end offset for all partitions? Will the source still be
bounded?
##########
docs/content.zh/docs/connectors/table/kafka.md:
##########
@@ -485,6 +510,22 @@ ROW<`version` INT, `behavior` STRING>
如果使用了 `specific-offsets`,必须使用另外一个配置项 `scan.startup.specific-offsets` 来为每个
partition 指定起始偏移量,
例如,选项值 `partition:0,offset:42;partition:1,offset:300` 表示 partition `0` 从偏移量
`42` 开始,partition `1` 从偏移量 `300` 开始。
+### Bounded Ending Position
+
+The config option `scan.bounded.mode` specifies the bounded mode for Kafka
consumer. The valid enumerations are:
+<ul>
+<li><span markdown="span">`group-offsets`</span>: bounded from committed
offsets in ZK / Kafka brokers of a specific consumer group.</li>
+<li><span markdown="span">`latest-offset`</span>: bounded from the latest
offset.</li>
+<li><span markdown="span">`timestamp`</span>: bounded from user-supplied
timestamp for each partition.</li>
+<li><span markdown="span">`specific-offsets`</span>: bounded from
user-supplied specific offsets for each partition.</li>
+</ul>
+
+If config option value `scan.bounded.mode` is not set the default is an
unbounded data stream.
+
+If `timestamp` is specified, another config option
`scan.bounded.timestamp-millis` is required to specify a specific bounded
timestamp in milliseconds since January 1, 1970 00:00:00.000 GMT.
Review Comment:
nit: `GMT` -> `UTC`
##########
flink-connectors/flink-connector-kafka/src/test/java/org/apache/flink/streaming/connectors/kafka/table/KafkaTableITCase.java:
##########
@@ -179,6 +180,66 @@ public void testKafkaSourceSink() throws Exception {
deleteTestTopic(topic);
}
+ @Test
+ public void testKafkaSourceSinkWithBoundedSpecificOffsets() throws
Exception {
Review Comment:
Can we also add a test for timestamps?
--
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]