felipepessoto commented on code in PR #13756:
URL: https://github.com/apache/gluten/pull/13756#discussion_r4701469458
##########
backends-velox/src/test/scala/org/apache/gluten/execution/MiscOperatorSuite.scala:
##########
@@ -2646,6 +2647,47 @@ class MiscOperatorSuite extends
VeloxWholeStageTransformerSuite with AdaptiveSpa
})
}
+ test("range shuffle of TimestampNTZ produced by RowToVeloxColumnar") {
+ // The Velox plan declares TimestampNTZ as TIMESTAMP_UTC. Batches
converted from rows must use
+ // the same type, otherwise passed-through R2C batches and batches the
shuffle-input resizer
+ // rebuilt from the declared type reach the shuffle writer with different
row types.
+ withSQLConf(
+ SQLConf.ANSI_ENABLED.key -> "false",
+ SQLConf.ADAPTIVE_EXECUTION_ENABLED.key -> "false",
+ SQLConf.SHUFFLE_PARTITIONS.key -> "4",
+ GlutenConfig.COLUMNAR_RANGE_ENABLED.key -> "false",
+ VeloxConfig.COLUMNAR_VELOX_RESIZE_BATCHES_SHUFFLE_INPUT.key -> "true"
+ ) {
+ val start = java.time.LocalDateTime.of(2024, 1, 1, 0, 0)
+ // A Scala UDF falls back, so its TimestampNTZ output enters native
through
+ // RowToVeloxColumnar. asNondeterministic() keeps CollapseProject from
merging it into the
+ // native Project above it.
+ val toNtz = udf((i: Long) => start.plusSeconds(i)).asNondeterministic()
+ // Each partition holds 9000 rows, converted into batches of 4096, 4096
and 808 rows. The
+ // resizer passes the full batches through and rebuilds the short tail
batch.
+ val df = spark
+ .range(0, 18000, 1, 2)
+ .select(col("id"), toNtz(col("id")).as("ts"))
+ .select(col("ts"), (col("id") * 2).as("k"))
+ .orderBy(col("k"))
+
+ val rows = df.collect()
+ assert(rows.length == 18000)
+ rows.zipWithIndex.foreach {
+ case (row, i) =>
+ assert(row.getLong(1) == i * 2L)
+ assert(row.get(0) == start.plusSeconds(i))
+ }
+ val plan = df.queryExecution.executedPlan
+ assert(find(plan)(_.isInstanceOf[RowToVeloxColumnarExec]).isDefined)
+ assert(find(plan) {
+ case e: ColumnarShuffleExchangeExec =>
+ e.outputPartitioning.isInstanceOf[RangePartitioning]
Review Comment:
This assertion also passes for a sort shuffle, which doesn't install
`VeloxResizeBatchesExec`. And with a max batch size of 1024, for example, the
808-row tail is above the default 256-row resize minimum, so no batch is
rebuilt. Please pin the batch size and resize minimum in this test and assert
that the range exchange's input contains the resizer and native project. That
way a plan or default change can't make the original mismatch disappear from
the test.
##########
gluten-arrow/src/main/scala/org/apache/spark/sql/utils/SparkArrowUtil.scala:
##########
@@ -134,7 +148,9 @@ object SparkArrowUtil {
)).asJava
)
case dataType =>
- val fieldType = new FieldType(nullable, toArrowType(dataType,
timeZoneId), null)
+ val metadata = if (isTimestampNTZ(dataType)) timestampUtcMetadata else
null
Review Comment:
This tag reaches row-to-columnar, but shuffle read still loses it when NTZ
is the direct key or value of a map. `ShuffleReaderJniWrapper.make` calls
`arrow::ImportSchema` before `VeloxShuffleReader` derives its row type. I
reproduced that round-trip with the pinned Arrow 18.0.0: scalar and
array-element tags survived, but both tags on
`map<timestamp_ntz,timestamp_ntz>` disappeared. The reader therefore produces
`MAP<TIMESTAMP,TIMESTAMP>` where the plan expects two `TIMESTAMP_UTC` children.
Can we reuse the original-C-schema reader change from #13512 and cover both a
map key and a map value after a shuffle? This affects shuffle consumers
independently of Delta writes.
--
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]