github-actions[bot] commented on code in PR #41848:
URL: https://github.com/apache/beam/pull/41848#discussion_r4757771623


##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java:
##########
@@ -1710,14 +1730,34 @@ public KV<Long, KV<PartitionColumnT, PartitionColumnT>> 
apply(
               .withOutputParallelization(false)
               .withDisableAutoCommit(getDisableAutoCommit());
 
-      if (getUseBeamSchema()) {
-        checkStateNotNull(schema);
-        readAll = readAll.withCoder((Coder<T>) RowCoder.of(schema));
-      } else if (getCoder() != null) {
-        readAll = readAll.withCoder(getCoder());
+      @Nullable Coder<T> coder =
+          getUseBeamSchema() ? (Coder<T>) 
RowCoder.of(checkStateNotNull(schema)) : getCoder();
+      if (coder != null) {
+        readAll = readAll.withCoder(coder);
+      }
+
+      PCollection<T> rangeRows = ranges.apply("Read ranges", readAll);

Review Comment:
   **🔴 Critical**: `Flatten.pCollections()` only copies the raw `Coder` from 
the first input `PCollection` (`inputs.get(0).getCoder()`);Wait/Flatten on 
`PCollection`s before `finishSpecifyingOutput` or without preserving schema on 
the flattened output can cause issues, or more specifically: in 
`ReadWithPartitions.expand`, `partitionedRows.setRowSchema(schema)` sets a 
`SchemaCoder` on `partitionedRows`, and `Flatten.pCollections()` copies 
`inputs.get(0).getCoder()` to the flattened `PCollection`. However, `nullRows` 
is produced by `JdbcIO.read()` which uses `RowCoder.of(schema)` (via 
`CoderRegistry` / `BeamRowMapper` without `setRowSchema`), so `nullRows` has a 
different coder or lacks `SchemaCoder` if `coder` is not set, or if 
`withCoder()` was not explicitly called on `ReadWithPartitions` when 
`withRowOutput()` was used! Specifically, in `withRowOutput()`, 
`.withCoder(RowCoder.of(schema))` is only set in `ReadRows.expand()`, whereas 
in `ReadWithPartitions.withRowOutput()`, `getCo
 der()` remains `null`! Because `nullRows` does not have `.withCoder(...)` or 
`setRowSchema(schema)` called on it, `input.apply("Read NULL partition rows", 
readNulls)` will fail coder inference or fall back to a non-SchemaCoder when 
`hasSchema()` is true. You should set the row schema (or coder) on `nullRows` 
as well (or apply `setRowSchema(schema)` on the final returned `PCollection`).



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to