grorge123 commented on code in PR #5526:
URL: https://github.com/apache/datafusion-comet/pull/5526#discussion_r3886564490
##########
spark/src/main/scala/org/apache/comet/codegen/CometBatchKernelCodegen.scala:
##########
@@ -117,7 +126,7 @@ object CometBatchKernelCodegen extends Logging with
CometExprTraitShim with Come
* nested-field count on `spark.sql.codegen.maxFields`.
*/
def canHandle(boundExpr: Expression): Option[String] = {
- if (!isSupportedDataType(boundExpr.dataType)) {
+ if (!isSupportedDataType(boundExpr.dataType, allowNullType = true)) {
Review Comment:
Fixed: `coalesceBroadcastBatches` now uses `hasNestedNullType` to check the
schema, and ships the batches uncoalesced when a `NullType` sits inside a
struct or map.
Tests: `UtilsSuite` ("coalesceBroadcastBatches ships maps with nested
NullType uncoalesced") checks that such batches come back uncoalesced, and
`CometJoinSuite` ("Broadcast HashJoin with NullType map columns on the build
side") runs a hinted broadcast hash join with `map(_1, NULL)` and
`transform_values(map(), (k, v) -> _1)` on the build side, with AQE on and off.
##########
spark/src/main/scala/org/apache/comet/codegen/CometBatchKernelCodegen.scala:
##########
@@ -81,18 +81,27 @@ object CometBatchKernelCodegen extends Logging with
CometExprTraitShim with Come
/**
* Type surface the kernel covers on both input and output sides. Recursive:
complex types are
* supported when their children are.
+ *
+ * `NullType` is output-only: [[CometBatchKernelCodegenOutput]] can write an
all-null Arrow
+ * `NullVector`, but `CometScalaUDFCodegen.specFor` cannot build an
[[ArrowColumnSpec]] for one,
+ * so a `NullType` input (nested or not) has to keep falling back to Spark.
*/
- def isSupportedDataType(dt: DataType): Boolean = dt match {
+ def isSupportedDataType(dt: DataType): Boolean = isSupportedDataType(dt,
allowNullType = false)
+
+ private def isSupportedDataType(dt: DataType, allowNullType: Boolean):
Boolean = dt match {
+ case NullType => allowNullType
case BooleanType | ByteType | ShortType | IntegerType | LongType => true
case FloatType | DoubleType => true
case _: DecimalType => true
case _: StringType | _: BinaryType => true
case DateType | TimestampType | TimestampNTZType => true
case dt if isTimeType(dt) => true
case _: YearMonthIntervalType | _: DayTimeIntervalType |
CalendarIntervalType => true
- case ArrayType(inner, _) => isSupportedDataType(inner)
- case st: StructType => st.fields.forall(f =>
isSupportedDataType(f.dataType))
- case mt: MapType => isSupportedDataType(mt.keyType) &&
isSupportedDataType(mt.valueType)
+ case ArrayType(inner, _) => isSupportedDataType(inner, allowNullType)
+ case st: StructType => st.fields.forall(f =>
isSupportedDataType(f.dataType, allowNullType))
+ case mt: MapType =>
+ isSupportedDataType(mt.keyType, allowNullType) &&
Review Comment:
Since Arrow 18.3.0's `MinorType.NULL.getNewVector` is `new
NullVector(field.getName())`, every `NullType` map key comes back nullable
after any vector is created for it. We added `Utils.withNonNullableMapKeys`,
which repairs the key flag, route all IPC writers through
`Utils.newArrowStreamWriter` so the repair is applied in one place, and added a
scalastyle rule as a lint check for `new ArrowStreamWriter`. The same repair is
applied in `CometArrowStream.actualFieldOf` (the stream schema handed to
native) and in `CometArrowPythonRunnerBase` before it builds its destination
struct.
Tests: `UtilsSuite` pins the Arrow behaviour (asserts the key comes back
nullable, so the workaround can be dropped once Arrow fixes it), checks
`withNonNullableMapKeys` restores the flag, round-trips a `NullType` map key
through `serializeBatches`, and checks `newArrowStreamWriter` keeps/returns the
root a later row count must be set on. `CometJoinSuite` covers the broadcast
path, `CometColumnarShuffleSuite` covers `Map[NullType, _]` and `Map[_,
NullType]` through the JVM columnar shuffle, and `test_pyarrow_udf.py` covers
`mapInArrow` with `Map[NullType, _]` input on Spark 4.1.3 in both accelerated
and fallback modes. Also verified under the `spark-3.5` profile.
--
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]