Skip to content

Commit b0d2b70

Browse files
committed
fix: format file-not-found message to match Hadoop convention
Extract file path from native error message and format it as "File <path> does not exist" to match the Hadoop FileNotFoundException message format that Spark tests expect.
1 parent 64b63c5 commit b0d2b70

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

spark/src/main/spark-3.4/org/apache/spark/sql/comet/shims/ShimSparkErrorConverter.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,16 @@ trait ShimSparkErrorConverter {
246246
.intervalArithmeticOverflowError("Interval arithmetic overflow", "", sqlCtx(context)))
247247

248248
case "FileNotFound" =>
249+
val msg = params("message").toString
250+
// Extract file path from native error message and format like Hadoop's
251+
// FileNotFoundException: "File <path> does not exist"
252+
val path = "Object at location (.+?) not found".r
253+
.findFirstMatchIn(msg)
254+
.map(_.group(1))
255+
.getOrElse(msg)
249256
Some(
250257
QueryExecutionErrors.readCurrentFileNotFoundError(
251-
new FileNotFoundException(params("message").toString)))
258+
new FileNotFoundException(s"File $path does not exist")))
252259

253260
case _ =>
254261
None

spark/src/main/spark-3.5/org/apache/spark/sql/comet/shims/ShimSparkErrorConverter.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,16 @@ trait ShimSparkErrorConverter {
242242
.intervalArithmeticOverflowError("Interval arithmetic overflow", "", sqlCtx(context)))
243243

244244
case "FileNotFound" =>
245+
val msg = params("message").toString
246+
// Extract file path from native error message and format like Hadoop's
247+
// FileNotFoundException: "File <path> does not exist"
248+
val path = "Object at location (.+?) not found".r
249+
.findFirstMatchIn(msg)
250+
.map(_.group(1))
251+
.getOrElse(msg)
245252
Some(
246253
QueryExecutionErrors.readCurrentFileNotFoundError(
247-
new FileNotFoundException(params("message").toString)))
254+
new FileNotFoundException(s"File $path does not exist")))
248255

249256
case _ =>
250257
None

spark/src/main/spark-4.0/org/apache/spark/sql/comet/shims/ShimSparkErrorConverter.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,16 @@ trait ShimSparkErrorConverter {
254254
context.headOption.orNull))
255255

256256
case "FileNotFound" =>
257+
val msg = params("message").toString
258+
// Extract file path from native error message and format like Hadoop's
259+
// FileNotFoundException: "File <path> does not exist"
260+
val path = "Object at location (.+?) not found".r
261+
.findFirstMatchIn(msg)
262+
.map(_.group(1))
263+
.getOrElse(msg)
257264
Some(
258265
QueryExecutionErrors.readCurrentFileNotFoundError(
259-
new FileNotFoundException(params("message").toString)))
266+
new FileNotFoundException(s"File $path does not exist")))
260267

261268
case _ =>
262269
// Unknown error type - return None to trigger fallback

0 commit comments

Comments
 (0)