maropu commented on a change in pull request #29947:
URL: https://github.com/apache/spark/pull/29947#discussion_r499954268



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala
##########
@@ -53,7 +53,45 @@ case class PrintToStderr(child: Expression) extends 
UnaryExpression {
 }
 
 /**
- * A function throws an exception if 'condition' is not true.
+ * Throw with the result of an expression (used for debugging).
+ */
+@ExpressionDescription(
+  usage = "_FUNC_(expr) - Throws an exception with `expr`.",
+  examples = """
+    Examples:
+      > SELECT _FUNC_('custom error message');
+       java.lang.RuntimeException
+       custom error message
+  """,
+  since = "3.1.0")
+case class RaiseError(child: Expression) extends UnaryExpression with 
ImplicitCastInputTypes {
+
+  override def foldable: Boolean = false
+  override def dataType: DataType = NullType
+  override def inputTypes: Seq[AbstractDataType] = Seq(StringType)
+
+  override def prettyName: String = "raise_error"
+
+  override def nullSafeEval(input: Any): Unit =
+    throw new RuntimeException(input.toString())
+
+  // if (true) is to avoid codegen compilation exception that statement is 
unreachable
+  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
+    val eval = child.genCode(ctx)
+    ExprCode(
+      code = code"""${eval.code}
+                   |if (true) {
+                   |  throw new RuntimeException(${eval.value}.toString());
+                   |}
+                 """.stripMargin,

Review comment:
       nit format:
   ```
         code = code"""${eval.code}
           |if (true) {
           |  throw new RuntimeException(${eval.value}.toString());
           |}""".stripMargin,
   ```




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

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