You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "bowenli86 (via GitHub)" <gi...@apache.org> on 2026/01/13 21:16:45 UTC

[PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

bowenli86 opened a new pull request, #27409:
URL: https://github.com/apache/flink/pull/27409

   ## What is the purpose of the change
   
   create Dynamic Kafka Source for pyflink
   
   ## Brief change log
   
   - create Dynamic Kafka Source and related py classes for pyflink
   - add tests
   
   ## Verifying this change
   
   Please make sure both new and modified tests in this PR follow [the conventions for tests defined in our code quality guide](https://flink.apache.org/how-to-contribute/code-style-and-quality-common/#7-testing).
   
   *(Please pick either of the following options)*
   
   This change is a trivial rework / code cleanup without any test coverage.
   
   *(or)*
   
   This change is already covered by existing tests, such as *(please describe tests)*.
   
   *(or)*
   
   This change added tests and can be verified as follows:
   
   *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (100MB)*
     - *Extended integration test for recovery after master (JobManager) failure*
     - *Added test that validates that TaskInfo is transferred only once across recoveries*
     - *Manually verified the change by running a 4 node cluster with 2 JobManagers and 4 TaskManagers, a stateful streaming program, and killing one JobManager and two TaskManagers during the execution, verifying that recovery happens correctly.*
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): (yes / no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / no)
     - The serializers: (yes / no / don't know)
     - The runtime per-record code paths (performance sensitive): (yes / no / don't know)
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
     - The S3 file system connector: (yes / no / don't know)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "dianfu (via GitHub)" <gi...@apache.org>.
dianfu merged PR #27409:
URL: https://github.com/apache/flink/pull/27409


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "bowenli86 (via GitHub)" <gi...@apache.org>.
bowenli86 commented on code in PR #27409:
URL: https://github.com/apache/flink/pull/27409#discussion_r2691441563


##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [

Review Comment:
   found out dynamic kafka doc has been moved to kafka connector repo https://github.com/apache/flink-connector-kafka/blob/main/docs/content/docs/connectors/datastream/dynamic-kafka.md
   
   created a PR there https://github.com/apache/flink-connector-kafka/pull/211
   
   (btw, the pyflink kafka connector migration to connector repo which has been left half way done for 2 years should really be fixed....)



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "bowenli86 (via GitHub)" <gi...@apache.org>.
bowenli86 commented on code in PR #27409:
URL: https://github.com/apache/flink/pull/27409#discussion_r2691823420


##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [

Review Comment:
   (btw, the pyflink kafka connector migration to connector repo which has been left half way done for 2 years is better to be fixed, otherwise we'll be constantly facing the inconsistency among the 2 repos and jump back and forth for all kinds of issues. Do you have time or anyone in OSS or Alibaba can take on it?)



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "bowenli86 (via GitHub)" <gi...@apache.org>.
bowenli86 commented on code in PR #27409:
URL: https://github.com/apache/flink/pull/27409#discussion_r2691441563


##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [

Review Comment:
   found out dynamic kafka doc has been moved to kafka connector repo https://github.com/apache/flink-connector-kafka/blob/main/docs/content/docs/connectors/datastream/dynamic-kafka.md
   
   created a PR there https://github.com/apache/flink-connector-kafka/pull/211



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "bowenli86 (via GitHub)" <gi...@apache.org>.
bowenli86 commented on code in PR #27409:
URL: https://github.com/apache/flink/pull/27409#discussion_r2691441563


##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [

Review Comment:
   found out dynamic kafka doc has been moved to kafka connector repo https://github.com/apache/flink-connector-kafka/blob/main/docs/content/docs/connectors/datastream/dynamic-kafka.md
   
   i'll submit a PR there
   
   (btw, the pyflink kafka connector migration to connector repo which has been left half way done for 2 years should really be fixed....)



##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [
+    'DynamicKafkaSource',
+    'DynamicKafkaSourceBuilder',
+    'KafkaMetadataService',
+    'KafkaRecordDeserializationSchema',
+    'KafkaStreamSubscriber',
+    'SingleClusterTopicMetadataService'
+]
+
+
+class KafkaMetadataService(object):
+    """
+    Base class for Kafka metadata service wrappers.
+    """
+
+    def __init__(self, j_metadata_service: JavaObject):
+        self._j_metadata_service = j_metadata_service
+
+
+class SingleClusterTopicMetadataService(KafkaMetadataService):
+    """
+    A KafkaMetadataService backed by a single Kafka cluster where stream ids map to topics.
+    """
+
+    def __init__(self, kafka_cluster_id: str, properties: Dict[str, str]):
+        gateway = get_gateway()
+        j_properties = gateway.jvm.java.util.Properties()
+        for key, value in properties.items():
+            j_properties.setProperty(key, value)
+        j_service = gateway.jvm.org.apache.flink.connector.kafka.dynamic.metadata \
+            .SingleClusterTopicMetadataService(kafka_cluster_id, j_properties)
+        super().__init__(j_service)
+
+
+class KafkaStreamSubscriber(object):

Review Comment:
   added



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #27409:
URL: https://github.com/apache/flink/pull/27409#issuecomment-3746641100

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "c21bb0d6286aa8b484725b5c7b23804ca0e20646",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "c21bb0d6286aa8b484725b5c7b23804ca0e20646",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * c21bb0d6286aa8b484725b5c7b23804ca0e20646 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "dianfu (via GitHub)" <gi...@apache.org>.
dianfu commented on code in PR #27409:
URL: https://github.com/apache/flink/pull/27409#discussion_r2689998274


##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [
+    'DynamicKafkaSource',
+    'DynamicKafkaSourceBuilder',
+    'KafkaMetadataService',
+    'KafkaRecordDeserializationSchema',
+    'KafkaStreamSubscriber',
+    'SingleClusterTopicMetadataService'
+]
+
+
+class KafkaMetadataService(object):
+    """
+    Base class for Kafka metadata service wrappers.
+    """
+
+    def __init__(self, j_metadata_service: JavaObject):
+        self._j_metadata_service = j_metadata_service
+
+
+class SingleClusterTopicMetadataService(KafkaMetadataService):
+    """
+    A KafkaMetadataService backed by a single Kafka cluster where stream ids map to topics.
+    """
+
+    def __init__(self, kafka_cluster_id: str, properties: Dict[str, str]):
+        gateway = get_gateway()
+        j_properties = gateway.jvm.java.util.Properties()
+        for key, value in properties.items():
+            j_properties.setProperty(key, value)
+        j_service = gateway.jvm.org.apache.flink.connector.kafka.dynamic.metadata \
+            .SingleClusterTopicMetadataService(kafka_cluster_id, j_properties)
+        super().__init__(j_service)
+
+
+class KafkaStreamSubscriber(object):

Review Comment:
   What about also introducing class `StreamPatternSubscriber` and `KafkaStreamSetSubscriber `?



##########
flink-python/pyflink/datastream/connectors/dynamic_kafka.py:
##########
@@ -0,0 +1,237 @@
+################################################################################
+#  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.
+################################################################################
+from typing import Dict, Set, Union
+
+from py4j.java_gateway import JavaObject
+
+from pyflink.common import DeserializationSchema
+from pyflink.datastream.connectors import Source
+from pyflink.datastream.connectors.kafka import KafkaOffsetsInitializer
+from pyflink.java_gateway import get_gateway
+
+__all__ = [

Review Comment:
   It would be great to also update the documentation here: https://nightlies.apache.org/flink/flink-docs-master/docs/connectors/datastream/dynamic-kafka/



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [FLINK-38530] create Dynamic Kafka Source for pyflink [flink]

Posted by "bowenli86 (via GitHub)" <gi...@apache.org>.
bowenli86 commented on PR #27409:
URL: https://github.com/apache/flink/pull/27409#issuecomment-3747601749

   test failures in core and connect modules are unrelated


-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org