Skip to content

Commit 6e1e92d

Browse files
committed
Fix test schema inference.
1 parent 6373509 commit 6e1e92d

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

sdks/python/apache_beam/io/external/xlang_jdbcio_it_test.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,9 +399,9 @@ def test_xlang_jdbc_custom_statements(self, database):
399399
classpath=config['classpath'],
400400
statement=write_statement))
401401

402-
read_query = f"SELECT id, name, value FROM {table_name} WHERE value > \
403-
25.0 ORDER BY id"
404-
402+
# Schema inference fails when there is a WHERE clause, so we pass explicit
403+
# schema.
404+
read_query = f"SELECT id, name, value FROM {table_name} WHERE value > 25.0"
405405
expected_filtered_rows = [row for row in test_rows if row.value > 25.0]
406406

407407
with TestPipeline() as p:
@@ -415,23 +415,26 @@ def test_xlang_jdbc_custom_statements(self, database):
415415
username=config['username'],
416416
password=config['password'],
417417
classpath=config['classpath'],
418-
query=read_query))
418+
query=read_query,
419+
schema=SimpleRow))
419420

420421
assert_that(result, equal_to(expected_filtered_rows))
421422

423+
# JdbcIO#readWithPartitions requires custom queries to be passed as a
424+
# wrapped subquery to table_name.
422425
with TestPipeline() as p:
423426
p.not_use_test_runner_api = True
424427
result = (
425428
p
426429
| 'Read with custom query' >> ReadFromJdbc(
427-
table_name="",
430+
table_name=f"{read_query} as subq",
428431
driver_class_name=config['driver_class_name'],
429432
jdbc_url=config['jdbc_url'],
430433
username=config['username'],
431434
password=config['password'],
432435
classpath=config['classpath'],
433-
query=read_query,
434-
partition_column="id"))
436+
partition_column="id",
437+
schema=SimpleRow))
435438

436439
assert_that(result, equal_to(expected_filtered_rows))
437440

0 commit comments

Comments
 (0)