Github user dongjoon-hyun commented on a diff in the pull request: https://github.com/apache/spark/pull/12340#discussion_r59840175 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/misc.scala --- @@ -487,6 +487,50 @@ case class PrintToStderr(child: Expression) extends UnaryExpression { } /** + * A function throws an exception if 'condition' is not true. + */ +@ExpressionDescription( + usage = "_FUNC_(condition) - Throw an exception if 'condition' is not true.") +case class AssertTrue(child: Expression) extends UnaryExpression { + + override def nullable: Boolean = true + + def dataType: DataType = NullType + + override def prettyName: String = "assert_true" + + override def checkInputDataTypes(): TypeCheckResult = { + if (child.dataType != BooleanType) { + TypeCheckResult.TypeCheckFailure( + s"type of condition expression in assert_true should be boolean, not ${child.dataType}") + } else { + TypeCheckResult.TypeCheckSuccess + } + } + + override def eval(input: InternalRow) : Any = { + val v = child.eval(input) + if (java.lang.Boolean.TRUE.equals(v)) { + null + } else { + throw new RuntimeException(s"'${child.simpleString}' is not true!") + } + } + + override def genCode(ctx: CodegenContext, ev: ExprCode): String = { + val eval = child.gen(ctx) + ev.isNull = "true" + ev.value = "null" + s"""if (${eval.isNull} || !java.lang.Boolean.TRUE.equals(${eval.value})) { + | throw new RuntimeException("'${child.simpleString}' is not true."); + |} + """.stripMargin + } + + override def sql: String = s"assert_true(${child.sql})" --- End diff -- I thought like that, but It's used in SQL representation like the following. == Physical Plan == WholeStageCodegen : +- Project [null AS **assert_true(true)**#4] : +- INPUT +- Scan OneRowRelation[]
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org