You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by jr...@apache.org on 2024/03/04 18:16:43 UTC

(beam) branch master updated: Add test code to overwrite SQL in Beam Python JDBC (#30417)

This is an automated email from the ASF dual-hosted git repository.

jrmccluskey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b8a737ebd0 Add test code to overwrite SQL in Beam Python JDBC (#30417)
2b8a737ebd0 is described below

commit 2b8a737ebd0942da69f0988180e3c9160b267ba2
Author: case-k <40...@users.noreply.github.com>
AuthorDate: Tue Mar 5 03:16:36 2024 +0900

    Add test code to overwrite SQL in Beam Python JDBC (#30417)
    
    * Add python jdbc test with override query
    
    * fix jdbcio it test lint
---
 .../io/external/xlang_jdbcio_it_test.py            | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/sdks/python/apache_beam/io/external/xlang_jdbcio_it_test.py b/sdks/python/apache_beam/io/external/xlang_jdbcio_it_test.py
index 54a473d1b52..9d8b8f92795 100644
--- a/sdks/python/apache_beam/io/external/xlang_jdbcio_it_test.py
+++ b/sdks/python/apache_beam/io/external/xlang_jdbcio_it_test.py
@@ -29,6 +29,8 @@ from typing import Union
 from parameterized import parameterized
 
 import apache_beam as beam
+from apache_beam import DoFn
+from apache_beam import ParDo
 from apache_beam import coders
 from apache_beam.io.jdbc import ReadFromJdbc
 from apache_beam.io.jdbc import WriteToJdbc
@@ -197,8 +199,6 @@ class CrossLanguageJdbcIOTest(unittest.TestCase):
       p.not_use_test_runner_api = True
       result = (
           p
-          # TODO(https://github.com/apache/beam/issues/20446) Add test with
-          # overridden read_query
           | 'Read from jdbc' >> ReadFromJdbc(
               table_name=table_name,
               driver_class_name=self.driver_class_name,
@@ -209,6 +209,26 @@ class CrossLanguageJdbcIOTest(unittest.TestCase):
 
       assert_that(result, equal_to(expected_row))
 
+    with TestPipeline() as p:
+      p.not_use_test_runner_api = True
+
+      class ExtractCount(DoFn):
+        def process(self, element):
+          yield element[0]
+
+      result = (
+          p
+          | 'Read from jdbc override query' >> ReadFromJdbc(
+              table_name=table_name,
+              query=f'select count(*) from {table_name}',
+              driver_class_name=self.driver_class_name,
+              jdbc_url=self.jdbc_url,
+              username=self.username,
+              password=self.password,
+              classpath=classpath)
+          | 'ExtractCount' >> ParDo(ExtractCount()))
+      assert_that(result, equal_to([ROW_COUNT]))
+
     # Try the same read using the partitioned reader code path.
     # Outputs should be the same.
     with TestPipeline() as p: