sadikovi commented on code in PR #42667:
URL: https://github.com/apache/spark/pull/42667#discussion_r1306742597
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/BadRecordException.scala:
##########
@@ -65,3 +93,25 @@ case class StringAsDataTypeException(
fieldName: String,
fieldValue: String,
dataType: DataType) extends RuntimeException()
+
+/**
+ * No-stacktrace equivalent of
`QueryExecutionErrors.cannotParseJSONFieldError`.
+ * Used for code control flow in the parser without overhead of creating a
full exception.
+ */
+case class CannotParseJSONFieldException(
+ fieldName: String,
+ fieldValue: String,
+ jsonType: JsonToken,
+ dataType: DataType) extends RuntimeException() {
+ override def getStackTrace(): Array[StackTraceElement] = new
Array[StackTraceElement](0)
+ override def fillInStackTrace(): Throwable = this
+}
+
+/**
+ * No-stacktrace equivalent of `QueryExecutionErrors.emptyJsonFieldValueError`.
+ * Used for code control flow in the parser without overhead of creating a
full exception.
Review Comment:
That is correct, we still use exceptions to report any issues in parsing.
Throwing exceptions allows us to propagate errors across several functions.
Without this, we would have to include checks in the code for every result.
Also, we would have to capture the exception itself to be reported to the user.
If we decided to go with returning some class to indicate failed parsing, then
we would essentially be implementing exceptions. Exceptions are not that much
slower, most of the time is spent on building the stacktrace which we only need
when the very first exception is thrown.
--
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]