spark-test commented on code in PR #60341:
URL: https://github.com/apache/spark/pull/60341#discussion_r4541275088
##########
sql/catalyst/src/main/java/org/apache/spark/sql/vectorized/ColumnarArray.java:
##########
@@ -218,7 +218,7 @@ public ColumnarMap getMap(int ordinal) {
@Override
public Object get(int ordinal, DataType dataType) {
- return SpecializedGettersReader.read(this, ordinal, dataType, false, true);
+ return SpecializedGettersReader.read(this, ordinal, dataType, true, true);
Review Comment:
**Non-blocking (P2):** With this change, `ColumnarArray.get()` returns null
for a null element, but the sibling public adapter `ColumnarBatchRow.get()`
still does not check `isNullAt`. That is the row that `ColumnarBatch.getRow()`
returns and `rowIterator()` yields. It dispatches straight to the typed
getters, and the primitive getters of the on-heap and off-heap vectors read the
slot regardless of its null bit. Reading the code, after `putInt(0, 42)` and
`putNull(0)` on an `IntegerType` vector, `new ColumnarArray(vector, 0,
1).get(0, IntegerType)` now returns null, but `new ColumnarBatch(new
ColumnVector[] {vector}, 1).getRow(0).get(0, IntegerType)` still returns 42,
although `isNullAt(0)` is true.
This affects every null field of a primitive-backed type (boolean, byte,
short, int, long, float, double, date, timestamp, timestamp_ntz, and the
year-month and day-time interval types) and of user-defined types backed by
one. Connector or extension code that reads batch rows, and generic consumers
that treat `get()` as null-safe, such as `InternalRow.toSeq`, silently get a
stale value, possibly left over from an earlier batch because vectors are
reused. `ColumnarRow.get()` has started with `if (isNullAt(ordinal)) return
null;` since SPARK-53434. The same line at the top of `ColumnarBatchRow.get()`
would finish this fix for batch rows. On Spark's NullType vectors, it would
also make `get(ordinal, NullType)` return null there, as it now does here.
`MutableColumnarRow.get()` has the same shape, but only the internal vectorized
aggregate hash map uses that class, and its generated code never calls `get()`,
so it can stay as it is.
**Verification:**
- **Regression:** For each type that ColumnarBatchRow.get() reads through a
primitive getter (boolean, byte, short, int, long, float, double, date,
timestamp, timestamp_ntz, and the year-month and day-time interval types), and
for a user-defined type whose SQL type is one of them, write a value into a
slot of an on-heap and of an off-heap column vector, mark the slot null, and
wrap each vector in a one-row ColumnarBatch. Check that the row from getRow()
reports the field as null and that get() on it returns null rather than the
written value. This check fails on the current code.
- **Behavior:** In the same kind of batch and for the same types, check that
a field whose slot is not null still returns its stored value through get(), so
the new null check does not hide real values.
- **Behavior:** Wrap an on-heap and an off-heap NullType column vector in a
one-row ColumnarBatch and check that get() with NullType on the row from
getRow() returns null. On the current code this call throws an unsupported-type
error.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]