|
30 | 30 |
|
31 | 31 | import apache_beam as beam |
32 | 32 | from apache_beam import coders |
| 33 | +from apache_beam.io import jdbc |
33 | 34 | from apache_beam.io.jdbc import ReadFromJdbc |
34 | 35 | from apache_beam.io.jdbc import WriteToJdbc |
35 | 36 | from apache_beam.options.pipeline_options import StandardOptions |
|
64 | 65 | ("f_timestamp", Timestamp), ("f_decimal", Decimal), |
65 | 66 | ("f_date", datetime.date), ("f_time", datetime.time)], |
66 | 67 | ) |
67 | | -coders.registry.register_coder(JdbcTestRow, coders.RowCoder) |
| 68 | +coders.registry.register_row(JdbcTestRow) |
68 | 69 |
|
69 | 70 | CustomSchemaRow = typing.NamedTuple( |
70 | 71 | "CustomSchemaRow", |
|
82 | 83 | ("renamed_time", datetime.time), |
83 | 84 | ], |
84 | 85 | ) |
85 | | -coders.registry.register_coder(CustomSchemaRow, coders.RowCoder) |
| 86 | + |
| 87 | +# Need to put inside enforce_millis_instant_for_timestamp context to align |
| 88 | +# with the same setup in ReadFromJdbc.__init__. Remove once Beam moved to |
| 89 | +# micros instant for timestamp |
| 90 | +# Alternatively, use coders.registry.register_coder(CustomSchemaRow, RowCoder) |
| 91 | +with jdbc.enforce_millis_instant_for_timestamp(): |
| 92 | + coders.registry.register_row(CustomSchemaRow) |
86 | 93 |
|
87 | 94 | SimpleRow = typing.NamedTuple( |
88 | 95 | "SimpleRow", [("id", int), ("name", str), ("value", float)]) |
89 | | -coders.registry.register_coder(SimpleRow, coders.RowCoder) |
| 96 | +coders.registry.register_row(SimpleRow) |
90 | 97 |
|
91 | 98 |
|
92 | 99 | @pytest.mark.uses_gcp_java_expansion_service |
|
0 commit comments