comphead commented on code in PR #7731:
URL: https://github.com/apache/datafusion-comet/pull/7731#discussion_r4743959321


##########
spark/src/main/scala/org/apache/comet/rules/EliminateRedundantTransitions.scala:
##########
@@ -184,7 +184,7 @@ case class EliminateRedundantTransitions(session: 
SparkSession)
       case CometColumnarToRowExec(child: CometCollectLimitExec) =>
         child
       case other =>
-        other
+        CometParquetResultExec.wrap(other)

Review Comment:
   This puts a new node at the root of every plan that is a filter or 
projection over an eligible scan, including plans that are never collected, so 
it changes plan shape and not only a native flag. The `run-all-spark-profiles` 
label runs Comet's own suites only. `docs/source/contributor-guide/ci.md` names 
a planner change as a reason for `run-spark-4.1-tests`, because Spark's own SQL 
suite is what would catch a plan-shape or behavior difference, and a failure in 
the merge queue evicts the pull request. This PR has no `run-spark-*` label. 
Could you apply `run-spark-4.1-tests`, or run the matching shard with 
`dev/local-ci.sh spark`, before queueing?



##########
docs/source/user-guide/latest/parquet.md:
##########
@@ -298,11 +298,20 @@ for production, so do not turn it off to avoid an entry 
on this page.
   differ only in such bytes distinct: they match Spark in a release build, and 
a debug build
   panics on top-level values 
([#7032](https://github.com/apache/datafusion-comet/issues/7032), part of
   [#4764](https://github.com/apache/datafusion-comet/issues/4764)).
-- **`TIMESTAMP_MILLIS` values that overflow when converted to microseconds.** 
In nested fields, and
-  in every column of a scan that has data filters, Comet returns NULL where 
Spark fails with
-  `ArithmeticException: long overflow`
-  ([#5553](https://github.com/apache/datafusion-comet/issues/5553),
-  [#5739](https://github.com/apache/datafusion-comet/issues/5739)).
+- **`TIMESTAMP_MILLIS` values that overflow when converted to microseconds.** 
Spark raises
+  `ArithmeticException: long overflow` when its reader decodes such a value. 
For a V1 Parquet
+  query such as `SELECT s.ts FROM t WHERE id <=> match_id`, Spark decodes the 
timestamps
+  before comparing the columns. When both readers use the same rules to match 
field names,
+  Comet checks for overflow on `collect()` in classic Spark, including 
PySpark. For each file
+  where a requested timestamp needs this conversion, Comet applies the filters 
after decoding.
+  Those filters cannot prune row groups or pages, even if all the timestamps 
fit.
+  Other filtered reads can still produce NULL on overflow. These include 
`show()`, writes,
+  `toLocalIterator()`, cached reads, Arrow-based `toPandas()` and Spark 
Connect `collect()`.
+  The check also excludes read schemas with Parquet field IDs, queries with a 
`LIMIT` and

Review Comment:
   `canCheckFilteredTimestampOverflow` also excludes scans that set 
`ignoreCorruptFiles` and scans where the relation's session and the native scan 
disagree on case sensitivity, but this sentence lists only field IDs, `LIMIT` 
and pushable predicates. `When both readers use the same rules to match field 
names` earlier in the bullet covers the case-sensitivity condition only by 
implication. Naming each exclusion lets a user work out why a query still 
returns NULL, in particular a job that sets 
`spark.sql.files.ignoreCorruptFiles=true`.



##########
spark/src/test/scala/org/apache/comet/parquet/ParquetReadSuite.scala:
##########
@@ -640,6 +640,143 @@ abstract class ParquetReadSuite extends CometTestBase {
     }
   }
 
+  private def withFilteredMillisFile(f: Path => Unit): Unit = {
+    withTempDir { dir =>
+      val path = new Path(dir.toURI.toString, "part-r-0.parquet")
+      val schema = MessageTypeParser.parseMessageType("""
+        |message root {
+        |  optional int64 id;
+        |  optional int64 match_id;
+        |  optional int64 ts(TIMESTAMP_MILLIS);
+        |  optional group s {
+        |    optional int32 k;
+        |    optional int64 ts(TIMESTAMP_MILLIS);
+        |  }
+        |}
+        |""".stripMargin)
+      val writer = createParquetWriter(schema, path)
+      Seq(0L, Long.MaxValue / 1000 + 1).zipWithIndex.foreach { case (millis, 
k) =>
+        val record = new SimpleGroup(schema)
+        record.add(0, k.toLong)
+        record.add(1, 0L)
+        record.add(2, millis)
+        val nested = record.addGroup(3)
+        nested.add(0, k)
+        nested.add(1, millis)
+        writer.write(record)
+      }
+      writer.close()
+      f(path)
+    }
+  }
+
+  test("TIMESTAMP_MILLIS overflow when Spark applies filters above the Parquet 
reader") {

Review Comment:
   Two eligibility conditions have no test that fails when the condition is 
removed. These are the `ignoreCorruptFiles` exclusion and the case-sensitivity 
match in `canCheckFilteredTimestampOverflow`. The swapped field-ID test covers 
only the field-ID condition. A case that sets 
`spark.sql.files.ignoreCorruptFiles=true` over `withFilteredMillisFile` and 
uses `id <=> match_id` would pin the first one. I expect Spark to skip the file 
when its reader throws, so the answer is empty and Comet must not raise. I did 
not run this.



-- 
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]

Reply via email to