comphead commented on code in PR #7788:
URL: https://github.com/apache/datafusion-comet/pull/7788#discussion_r4743957391
##########
native/jni-bridge/src/errors.rs:
##########
@@ -980,6 +980,66 @@ fn try_classify_file_read_error(error: &DataFusionError)
-> Option<SparkError> {
}
}
+/// Names `file_path` in an error raised while scanning that one file, when
the error is a
+/// per-file failure that does not name its file yet. Other errors are
returned unchanged.
+///
+/// The native Parquet scan calls this inside each file's planning and stream,
where the file is
+/// still known. Without it, a schema-conversion error names no file, and a
read failure reaches
+/// the JVM without a path, which then names every file of the task (#4316,
#7213). A read
+/// failure is classified here exactly as at the JNI boundary, so only its
path changes.
+pub fn with_scan_file_path(error: DataFusionError, file_path: &str) ->
DataFusionError {
+ let named = match extract_spark_payload(&error) {
+ Some(SparkPayload::Bare(spark_error)) =>
spark_error_with_file_path(spark_error, file_path),
+ // A Java exception or a Spark error with query context is surfaced as
is.
+ Some(_) => None,
+ None => match try_classify_file_read_error(&error) {
+ Some(SparkError::CannotReadFile {
+ file_path: found,
+ message,
+ }) if found.is_empty() => Some(SparkError::CannotReadFile {
+ file_path: file_path.to_string(),
+ message,
+ }),
+ _ => None,
+ },
+ };
+ named.map(DataFusionError::from).unwrap_or(error)
+}
+
+/// `error` naming `file_path`, if it is a per-file scan error. A path the
error already carries
+/// is kept, except for `ParquetTimestampOverflow`, whose reader never knows
the original Spark
+/// path.
+fn spark_error_with_file_path(error: &SparkError, file_path: &str) ->
Option<SparkError> {
Review Comment:
`SparkError::DuplicateFieldByFieldId` has no `file_path` field
(`native/common/src/error.rs` line 247 and its JSON at line 658), yet the Spark
4.x shim wraps it with `cannotReadFilesError(dupCause, params.get("filePath")
or "")` (`spark/src/main/spark-4.x/.../ShimSparkErrorConverter.scala` lines
366-375). It is raised by `native/core/src/parquet/field_resolver.rs` line 235,
so on 4.x a duplicate field id should still read `Encountered error while
reading file .`, the same symptom as
https://github.com/apache/datafusion-comet/issues/4316. Either add the path to
that variant and fill it here, or state that it is out of scope. I did not run
this.
##########
native/jni-bridge/src/errors.rs:
##########
@@ -980,6 +980,66 @@ fn try_classify_file_read_error(error: &DataFusionError)
-> Option<SparkError> {
}
}
+/// Names `file_path` in an error raised while scanning that one file, when
the error is a
+/// per-file failure that does not name its file yet. Other errors are
returned unchanged.
+///
+/// The native Parquet scan calls this inside each file's planning and stream,
where the file is
+/// still known. Without it, a schema-conversion error names no file, and a
read failure reaches
+/// the JVM without a path, which then names every file of the task (#4316,
#7213). A read
+/// failure is classified here exactly as at the JNI boundary, so only its
path changes.
+pub fn with_scan_file_path(error: DataFusionError, file_path: &str) ->
DataFusionError {
+ let named = match extract_spark_payload(&error) {
+ Some(SparkPayload::Bare(spark_error)) =>
spark_error_with_file_path(spark_error, file_path),
+ // A Java exception or a Spark error with query context is surfaced as
is.
+ Some(_) => None,
+ None => match try_classify_file_read_error(&error) {
Review Comment:
`spark_error_with_file_path` already has a `CannotReadFile` arm that fills
an empty path, so this branch re-implements it. `try_classify_file_read_error`
always returns `CannotReadFile` with `String::new()`, so the `found.is_empty()`
guard is also always true here. `None =>
try_classify_file_read_error(&error).and_then(|classified|
spark_error_with_file_path(&classified, file_path))` does the same in one line
and removes the duplicate destructuring.
##########
native/jni-bridge/src/errors.rs:
##########
@@ -980,6 +980,66 @@ fn try_classify_file_read_error(error: &DataFusionError)
-> Option<SparkError> {
}
}
+/// Names `file_path` in an error raised while scanning that one file, when
the error is a
+/// per-file failure that does not name its file yet. Other errors are
returned unchanged.
+///
+/// The native Parquet scan calls this inside each file's planning and stream,
where the file is
+/// still known. Without it, a schema-conversion error names no file, and a
read failure reaches
+/// the JVM without a path, which then names every file of the task (#4316,
#7213). A read
+/// failure is classified here exactly as at the JNI boundary, so only its
path changes.
+pub fn with_scan_file_path(error: DataFusionError, file_path: &str) ->
DataFusionError {
+ let named = match extract_spark_payload(&error) {
+ Some(SparkPayload::Bare(spark_error)) =>
spark_error_with_file_path(spark_error, file_path),
+ // A Java exception or a Spark error with query context is surfaced as
is.
+ Some(_) => None,
+ None => match try_classify_file_read_error(&error) {
+ Some(SparkError::CannotReadFile {
+ file_path: found,
+ message,
+ }) if found.is_empty() => Some(SparkError::CannotReadFile {
+ file_path: file_path.to_string(),
+ message,
+ }),
+ _ => None,
+ },
+ };
+ named.map(DataFusionError::from).unwrap_or(error)
+}
+
+/// `error` naming `file_path`, if it is a per-file scan error. A path the
error already carries
+/// is kept, except for `ParquetTimestampOverflow`, whose reader never knows
the original Spark
+/// path.
+fn spark_error_with_file_path(error: &SparkError, file_path: &str) ->
Option<SparkError> {
+ let file_path = file_path.to_string();
+ match error {
+ SparkError::ParquetTimestampOverflow { .. } => {
+ Some(SparkError::ParquetTimestampOverflow { file_path })
+ }
+ SparkError::ParquetSchemaConvert {
+ file_path: found,
+ column,
+ physical_type,
+ spark_type,
+ } if found.is_empty() => Some(SparkError::ParquetSchemaConvert {
+ file_path,
+ column: column.clone(),
Review Comment:
The `ParquetSchemaConvert` and `CannotReadFile` arms differ from the others
only in which field holds the path. Since `SparkError` is `Clone`, a helper
that returns `Option<&mut String>` for the path of the four variants, plus a
single rule (always replace for `ParquetTimestampOverflow`, replace when empty
otherwise), would drop the per-variant field clones in this function and the
next arm.
##########
native/jni-bridge/src/errors.rs:
##########
@@ -980,6 +980,66 @@ fn try_classify_file_read_error(error: &DataFusionError)
-> Option<SparkError> {
}
}
+/// Names `file_path` in an error raised while scanning that one file, when
the error is a
+/// per-file failure that does not name its file yet. Other errors are
returned unchanged.
+///
+/// The native Parquet scan calls this inside each file's planning and stream,
where the file is
+/// still known. Without it, a schema-conversion error names no file, and a
read failure reaches
+/// the JVM without a path, which then names every file of the task (#4316,
#7213). A read
+/// failure is classified here exactly as at the JNI boundary, so only its
path changes.
+pub fn with_scan_file_path(error: DataFusionError, file_path: &str) ->
DataFusionError {
+ let named = match extract_spark_payload(&error) {
+ Some(SparkPayload::Bare(spark_error)) =>
spark_error_with_file_path(spark_error, file_path),
+ // A Java exception or a Spark error with query context is surfaced as
is.
+ Some(_) => None,
+ None => match try_classify_file_read_error(&error) {
+ Some(SparkError::CannotReadFile {
+ file_path: found,
+ message,
+ }) if found.is_empty() => Some(SparkError::CannotReadFile {
+ file_path: file_path.to_string(),
+ message,
+ }),
+ _ => None,
+ },
+ };
+ named.map(DataFusionError::from).unwrap_or(error)
+}
+
+/// `error` naming `file_path`, if it is a per-file scan error. A path the
error already carries
+/// is kept, except for `ParquetTimestampOverflow`, whose reader never knows
the original Spark
+/// path.
+fn spark_error_with_file_path(error: &SparkError, file_path: &str) ->
Option<SparkError> {
+ let file_path = file_path.to_string();
+ match error {
+ SparkError::ParquetTimestampOverflow { .. } => {
+ Some(SparkError::ParquetTimestampOverflow { file_path })
+ }
+ SparkError::ParquetSchemaConvert {
+ file_path: found,
+ column,
+ physical_type,
+ spark_type,
+ } if found.is_empty() => Some(SparkError::ParquetSchemaConvert {
+ file_path,
+ column: column.clone(),
+ physical_type: physical_type.clone(),
+ spark_type: spark_type.clone(),
+ }),
+ SparkError::ParquetMissingFieldIds { file_path: found } if
found.is_empty() => {
Review Comment:
The only production raiser of `ParquetMissingFieldIds` is
`native/core/src/parquet/eager_page_index_reader_factory.rs` line 737, and it
already sets `file_path` to `object_meta.location.to_string()`. That is the
object store key without scheme or bucket. This arm only fires for an empty
path, so it never fires for the real error, and the key is kept as the path (on
Spark 4.x it becomes the `path` of `FAILED_READ_FILE`).
`ParquetTimestampOverflow` is replaced unconditionally for this same reason.
Treat `ParquetMissingFieldIds` like it and replace the path, then start the
matching unit test from the real raiser's non-empty key instead of
`String::new()`. I read the raiser and did not run this.
##########
spark/src/main/scala/org/apache/comet/SparkErrorConverter.scala:
##########
@@ -86,10 +86,11 @@ object SparkErrorConverter extends ShimSparkErrorConverter {
val json = parse(e.getMessage)
val errorJson = json.extract[ErrorJson]
val rawParams = errorJson.params.getOrElse(Map.empty)
- // Only CannotReadFile falls back to the per-task file list from
CometExecIterator: its native
- // error carries a path only for object_store NotFound.
ParquetTimestampOverflow is also a
- // file-read error, but it must stay out of this fallback: its native
reader attaches the
- // failing file's path, while the joined list would name every file of a
multi-file task.
+ // Only CannotReadFile falls back to the per-task file list from
CometExecIterator. The native
+ // Parquet scan names the failing file itself, so the fallback serves read
failures raised
+ // outside a per-file scan, such as from other native readers. Errors that
name their file,
+ // like ParquetTimestampOverflow, stay out of it: the joined list would
name every file of a
+ // multi-file task.
Review Comment:
`perPartitionFilePaths` is filled only from `CometNativeScanExec`
(`operators.scala` line 1185), which is the scan this PR now names natively. So
the fallback is reachable only for a read failure that escapes the per-file
wrapper, and when it fires on a multi-file task it prints the joined list that
https://github.com/apache/datafusion-comet/issues/7213 reports as wrong. The
comment's "other native readers" does not match anything I found that supplies
`taskFilePaths`. Consider keeping the fallback only for a single-file task,
where it is exact, or dropping it together with the `CometExecIterator` and
`CometExecRDD` plumbing and the two `SparkErrorConverterSuite` tests. The doc
comments on `SparkError::CannotReadFile` and `ParquetSchemaConvert`
(`native/common/src/error.rs` lines 263-284), on
`try_classify_file_read_error`, and the comment at `CometNativeScanExec.scala`
lines 233-235 also still say the path is empty or filled from the task list.
--
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]