cloud-fan commented on code in PR #60358:
URL: https://github.com/apache/spark/pull/60358#discussion_r4560106580
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/kllExpressions.scala:
##########
@@ -377,6 +377,8 @@ abstract class KllSketchMergeBase
desired quantile given the input rank. The desired quantile can either be
a single value
or an array. In the latter case, the function will return an array of
results of equal
length to the input array.
+ A NULL sketch, scalar NULL rank, or NULL rank array returns NULL.
+ NULL elements in the input rank array are treated as 0.0, requesting the
minimum quantile.
Review Comment:
**Nit (P3):** This sentence is accurate only when the rank array already has
element type DOUBLE (for the rank getters, the sketch's value type). The
getters declare `ArrayType(DoubleType, containsNull = false)`, and type
checking ignores nullability, so `array(0.5D, NULL)` is accepted and its NULL
reads as 0.0, as the new test checks. A NULL-containing array that needs an
implicit element cast takes a different path. Neither coercion mode casts an
array with `containsNull = true` to a `containsNull = false` target: non-ANSI
returns no cast (`TypeCoercion.scala:274`), and ANSI goes through
`Cast.canANSIStoreAssign`, which requires `resolvableNullability`
(`Cast.scala:544-545`). Reading that code, `array(0.5, NULL)`
(`ARRAY<DECIMAL(1,1)>`) fails analysis with
`DATATYPE_MISMATCH.UNEXPECTED_INPUT_TYPE`, although `array(0.5, 0.25)` is cast
and works. The same applies to `kll_sketch_get_rank_bigint(sketch, array(3,
NULL))`, to `array(3.0, NULL)` for the float and double rank getters, a
nd to Scala `array(lit(null), lit(10))`. The functions' own examples write
`0.5` and `3`, so a user who follows them and adds a NULL gets this error
instead of the documented zero reading.
Could the NULL-element sentence on all three surfaces (this usage text, the
Scala docs, and the PySpark Notes) state the precondition? For example: "NULL
elements are treated as 0.0 only when the rank array already has element type
DOUBLE, such as `array(0.5D, NULL)`; a NULL-containing array that needs an
implicit cast, such as `array(0.5, NULL)`, fails analysis." A test for the
coerced form would keep that statement true.
**Verification:**
- **Behavior:** A NULL-containing request array that needs an implicit
element cast, such as array(0.5, NULL) for a quantile getter and array(3, NULL)
for kll_sketch_get_rank_bigint, fails analysis with a datatype-mismatch error
for an unexpected input type.
- **Inspection:** Every NULL-element sentence for the six getters in the SQL
usage text, the Scala API docs, and the PySpark docs names the required element
type and says that an array needing an implicit element cast is rejected.
--
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]