Skip to content

Commit 9ca9248

Browse files
committed
Adding PartialResultException
1 parent 07e0498 commit 9ca9248

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/json/JacksonParser.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class JacksonParser(
367367
if (badRecordException.isEmpty) {
368368
row
369369
} else {
370-
throw BadRecordException(() => UTF8String.EMPTY_UTF8, () => Some(row), badRecordException.get)
370+
throw PartialResultException(row, badRecordException.get)
371371
}
372372
}
373373

@@ -439,8 +439,11 @@ class JacksonParser(
439439
val wrappedCharException = new CharConversionException(msg)
440440
wrappedCharException.initCause(e)
441441
throw BadRecordException(() => recordLiteral(record), () => None, wrappedCharException)
442-
case e: BadRecordException =>
443-
throw e.copy(record = () => recordLiteral(record))
442+
case PartialResultException(row, cause) =>
443+
throw BadRecordException(
444+
record = () => recordLiteral(record),
445+
partialResult = () => Some(row),
446+
cause)
444447
}
445448
}
446449
}

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/BadRecordException.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ package org.apache.spark.sql.catalyst.util
2020
import org.apache.spark.sql.catalyst.InternalRow
2121
import org.apache.spark.unsafe.types.UTF8String
2222

23+
/**
24+
* Exception thrown when the underlying parser returns a partial result of parsing.
25+
* @param partialResult the partial result of parsing a bad record.
26+
* @param cause the actual exception about why the parser cannot return full result.
27+
*/
28+
case class PartialResultException(
29+
partialResult: InternalRow,
30+
cause: Throwable)
31+
extends Exception(cause)
32+
2333
/**
2434
* Exception thrown when the underlying parser meet a bad record and can't parse it.
2535
* @param record a function to return the record that cause the parser to fail

0 commit comments

Comments
 (0)