pabloem commented on a change in pull request #14829:
URL: https://github.com/apache/beam/pull/14829#discussion_r635436030
##########
File path:
sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/KafkaSourceConsumerFn.java
##########
@@ -94,7 +95,7 @@ public KafkaSourceConsumerFn(
Class<?> connectorClass, SourceRecordMapper<T> fn, long minutesToRun) {
Review comment:
I think we made a mistake making `KafkaSourceconsumerFn` public. Can you
remove the public keyword here if possible?
##########
File path:
sdks/java/io/debezium/src/main/java/org/apache/beam/io/debezium/Connectors.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.beam.io.debezium;
+
+import io.debezium.connector.db2.Db2Connector;
+import io.debezium.connector.mysql.MySqlConnector;
+import io.debezium.connector.oracle.OracleConnector;
+import io.debezium.connector.postgresql.PostgresConnector;
+import io.debezium.connector.sqlserver.SqlServerConnector;
+import org.apache.kafka.connect.source.SourceConnector;
+
+/** Enumeration of debezium connectors. */
+public enum Connectors {
+ MYSQL("MySQL", MySqlConnector.class),
+ POSTGRES("PostgreSQL", PostgresConnector.class),
+ SQLSERVER("SQLServer", SqlServerConnector.class),
+ ORACLE("Oracle", OracleConnector.class),
+ DB2("DB2", Db2Connector.class),
Review comment:
If the dependencies are optional, then we may also need to make these
classes into strings, so that they will not require the class being in the
classpath.
##########
File path: sdks/java/io/debezium/build.gradle
##########
@@ -54,8 +54,14 @@ dependencies {
permitUnusedDeclared "org.apache.kafka:connect-json:2.5.0" // BEAM-11761
// Debezium dependencies
- compile group: 'io.debezium', name: 'debezium-core', version: '1.3.1.Final'
- testCompile group: 'io.debezium', name: 'debezium-connector-mysql',
version: '1.3.1.Final'
+ def debezium_version = '1.3.1.Final'
+ compile group: 'io.debezium', name: 'debezium-core', version:
debezium_version
+ compile group: 'io.debezium', name: 'debezium-connector-mysql', version:
debezium_version
+ compile group: 'io.debezium', name: 'debezium-connector-postgres',
version: debezium_version
+ compile group: 'io.debezium', name: 'debezium-connector-sqlserver',
version: debezium_version
+ compile group: 'io.debezium', name: 'debezium-connector-oracle', version:
debezium_version
+ compile group: 'io.debezium', name: 'debezium-connector-db2', version:
debezium_version
Review comment:
It would be good to make these dependencies optional, because otherwise
deploying these pipelines may require a lot of artifacts, and could lead to
dependency issues. Do you know if it's possible to specify extra dependencies
optionally with x lang transforms?
cc: @chamikaramj
##########
File path: sdks/python/apache_beam/io/debezium.py
##########
@@ -0,0 +1,159 @@
+#
+# 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.
+#
+
+""" Unbounded source transform for
+ `Debezium <href="https://debezium.io/"/>`_.
+
+ This transform is currently supported by Beam portable
+ Flink, Spark, and Dataflow v2 runners.
+
+ **Setup**
+
+ Transform provided in this module is cross-language transform
+ implemented in the Beam Java SDK. During the pipeline construction, Python
SDK
+ will connect to a Java expansion service to expand this transform.
+ To facilitate this, a small amount of setup is needed before using this
+ transform in a Beam Python pipeline.
+
+ There are several ways to setup cross-language Debezium transform.
+
+ * Option 1: use the default expansion service
+ * Option 2: specify a custom expansion service
+
+ See below for details regarding each of these options.
+
+ *Option 1: Use the default expansion service*
+
+ This is the recommended and easiest setup option for using Python Debezium
+ transform. This option requires following pre-requisites
+ before running the Beam pipeline.
+
+ * Install Java runtime in the computer from where the pipeline is constructed
+ and make sure that 'java' command is available.
+
+ In this option, Python SDK will either download (for released Beam version)
or
+ build (when running from a Beam Git clone) a expansion service jar and use
+ that to expand transforms. Currently Debezium transform use the
+ 'beam-sdks-java-io-expansion-service' jar for this purpose.
+
+ *Option 2: specify a custom expansion service*
+
+ In this option, you startup your own expansion service and provide that as
+ a parameter when using the transform provided in this module.
+
+ This option requires following pre-requisites before running the Beam
+ pipeline.
+
+ * Startup your own expansion service.
+ * Update your pipeline to provide the expansion service address when
+ initiating Debezium transform provided in this module.
+
+ Flink Users can use the built-in Expansion Service of the Flink Runner's
+ Job Server. If you start Flink's Job Server, the expansion service will be
+ started on port 8097. For a different address, please set the
+ expansion_service parameter.
+
+ **More information**
+
+ For more information regarding cross-language transforms see:
+ - https://beam.apache.org/roadmap/portability/
+
+ For more information specific to Flink runner see:
+ - https://beam.apache.org/documentation/runners/flink/
+"""
Review comment:
The documentation looks really good. Thanks!
##########
File path: sdks/python/apache_beam/io/debezium.py
##########
@@ -0,0 +1,159 @@
+#
+# 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.
+#
+
+""" Unbounded source transform for
+ `Debezium <href="https://debezium.io/"/>`_.
+
+ This transform is currently supported by Beam portable
+ Flink, Spark, and Dataflow v2 runners.
+
+ **Setup**
+
+ Transform provided in this module is cross-language transform
+ implemented in the Beam Java SDK. During the pipeline construction, Python
SDK
+ will connect to a Java expansion service to expand this transform.
+ To facilitate this, a small amount of setup is needed before using this
+ transform in a Beam Python pipeline.
+
+ There are several ways to setup cross-language Debezium transform.
+
+ * Option 1: use the default expansion service
+ * Option 2: specify a custom expansion service
+
+ See below for details regarding each of these options.
+
+ *Option 1: Use the default expansion service*
+
+ This is the recommended and easiest setup option for using Python Debezium
+ transform. This option requires following pre-requisites
+ before running the Beam pipeline.
+
+ * Install Java runtime in the computer from where the pipeline is constructed
+ and make sure that 'java' command is available.
+
+ In this option, Python SDK will either download (for released Beam version)
or
+ build (when running from a Beam Git clone) a expansion service jar and use
+ that to expand transforms. Currently Debezium transform use the
+ 'beam-sdks-java-io-expansion-service' jar for this purpose.
+
+ *Option 2: specify a custom expansion service*
+
+ In this option, you startup your own expansion service and provide that as
+ a parameter when using the transform provided in this module.
+
+ This option requires following pre-requisites before running the Beam
+ pipeline.
+
+ * Startup your own expansion service.
+ * Update your pipeline to provide the expansion service address when
+ initiating Debezium transform provided in this module.
+
+ Flink Users can use the built-in Expansion Service of the Flink Runner's
+ Job Server. If you start Flink's Job Server, the expansion service will be
+ started on port 8097. For a different address, please set the
+ expansion_service parameter.
+
+ **More information**
+
+ For more information regarding cross-language transforms see:
+ - https://beam.apache.org/roadmap/portability/
+
+ For more information specific to Flink runner see:
+ - https://beam.apache.org/documentation/runners/flink/
+"""
+
+# pytype: skip-file
+
+from enum import Enum
+from typing import List
+from typing import NamedTuple
+from typing import Optional
+
+from apache_beam.transforms.external import BeamJarExpansionService
+from apache_beam.transforms.external import ExternalTransform
+from apache_beam.transforms.external import NamedTupleBasedPayloadBuilder
+
+__all__ = ['ReadFromDebezium', 'DriverClassName']
+
+
+def default_io_expansion_service():
+ return BeamJarExpansionService('sdks:java:io:expansion-service:shadowJar')
+
+
+class DriverClassName(Enum):
+ MYSQL = 'MySQL'
+ POSTGRESQL = 'PostgreSQL'
+ ORACLE = 'Oracle'
+ DB2 = 'Db2'
+
+
+ReadFromDebeziumSchema = NamedTuple(
+ 'ReadFromDebeziumSchema',
+ [('connector_class', str), ('username', str), ('password', str),
+ ('host', str), ('port', str), ('max_number_of_records', Optional[int]),
+ ('connection_properties', List[str])])
+
+
+class ReadFromDebezium(ExternalTransform):
+ """
+ An external PTransform which reads from Debezium and returns
+ a JSON string for each item in the specified database
Review comment:
For Python it would be good to not return JSON strings - instead we
should parse them and return the dictionaries. Thoughts?
##########
File path: sdks/python/apache_beam/io/external/xlang_debeziumio_it_test.py
##########
@@ -0,0 +1,111 @@
+#
+# 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.
+#
+
+import logging
+import unittest
+
+from apache_beam.io.debezium import DriverClassName
+from apache_beam.io.debezium import ReadFromDebezium
+from apache_beam.options.pipeline_options import StandardOptions
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+# pylint: disable=wrong-import-order, wrong-import-position, ungrouped-imports
+try:
+ from testcontainers.postgres import PostgresContainer
+except ImportError:
+ PostgresContainer = None
+
+NUM_RECORDS = 1
+
+
[email protected](
+ PostgresContainer is None, 'testcontainers package is not installed')
[email protected](
+ TestPipeline().get_pipeline_options().view_as(StandardOptions).runner is
+ None,
+ 'Do not run this test on precommit suites.')
+class CrossLanguageDebeziumIOTest(unittest.TestCase):
+ def setUp(self):
+ self.username = 'debezium'
+ self.password = 'dbz'
+ self.database = 'inventory'
+ self.start_db_container(retries=1)
+ self.host = self.db.get_container_host_ip()
+ self.port = self.db.get_exposed_port(5432)
+ self.connector_class = DriverClassName.POSTGRESQL
+ self.connection_properties = [
+ "database.dbname=inventory",
+ "database.server.name=dbserver1",
+ "database.include.list=inventory",
+ "include.schema.changes=false"
+ ]
+
+ def tearDown(self):
+ # Sometimes stopping the container raises ReadTimeout. We can ignore it
+ # here to avoid the test failure.
+ try:
+ self.db.stop()
+ except: # pylint: disable=bare-except
+ logging.error('Could not stop the DB container.')
+
+ def test_xlang_debezium_read(self):
Review comment:
you can add `@attr('IT')` to this test method so that it will be picked
up for postcommits and not for precommits.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]