cloud-fan commented on a change in pull request #29721:
URL: https://github.com/apache/spark/pull/29721#discussion_r486860621



##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2555,6 +2555,24 @@ class DataFrameSuite extends QueryTest
     val df = Seq(0.0 -> -0.0).toDF("pos", "neg")
     checkAnswer(df.select($"pos" > $"neg"), Row(false))
   }
+
+  test("SPARK-32851: should fail if errors happen when generating expr code") {
+    val errMsg = intercept[SparkException] {
+      withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
+        val df = spark.range(1)
+        df.select(Column(FailedCodegenExpr(df("id").expr)) :: Nil: _*).show()
+      }
+    }.getCause.getMessage
+    assert(errMsg.contains("failed to compile:"))
+  }
 }
 
 case class GroupByKey(a: Int, b: Int)
+
+case class FailedCodegenExpr(child: Expression) extends UnaryExpression with 
CodegenFallback {
+  private lazy val proj = FailedCodegenProjection.createObject(child :: Nil)
+  override def dataType: DataType = LongType
+  override def eval(input: InternalRow): Any = {
+    proj(input).getLong(0)

Review comment:
       This test proves that if `eval` fails, the query fails. I think we 
should override `doCodeGen` and produce invalid code there?

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2555,6 +2555,24 @@ class DataFrameSuite extends QueryTest
     val df = Seq(0.0 -> -0.0).toDF("pos", "neg")
     checkAnswer(df.select($"pos" > $"neg"), Row(false))
   }
+
+  test("SPARK-32851: should fail if errors happen when generating expr code") {
+    val errMsg = intercept[SparkException] {
+      withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
+        val df = spark.range(1)
+        df.select(Column(FailedCodegenExpr(df("id").expr)) :: Nil: _*).show()
+      }
+    }.getCause.getMessage
+    assert(errMsg.contains("failed to compile:"))
+  }
 }
 
 case class GroupByKey(a: Int, b: Int)
+
+case class FailedCodegenExpr(child: Expression) extends UnaryExpression with 
CodegenFallback {
+  private lazy val proj = FailedCodegenProjection.createObject(child :: Nil)
+  override def dataType: DataType = LongType
+  override def eval(input: InternalRow): Any = {
+    proj(input).getLong(0)

Review comment:
       Then shall we just add a test in 
`CodeGeneratorWithInterpretedFallbackSuite`,  to make sure that 
`FailedCodegenProjection` fails with default codegen mode?

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2555,6 +2555,24 @@ class DataFrameSuite extends QueryTest
     val df = Seq(0.0 -> -0.0).toDF("pos", "neg")
     checkAnswer(df.select($"pos" > $"neg"), Row(false))
   }
+
+  test("SPARK-32851: should fail if errors happen when generating expr code") {
+    val errMsg = intercept[SparkException] {
+      withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
+        val df = spark.range(1)
+        df.select(Column(FailedCodegenExpr(df("id").expr)) :: Nil: _*).show()
+      }
+    }.getCause.getMessage
+    assert(errMsg.contains("failed to compile:"))
+  }
 }
 
 case class GroupByKey(a: Int, b: Int)
+
+case class FailedCodegenExpr(child: Expression) extends UnaryExpression with 
CodegenFallback {
+  private lazy val proj = FailedCodegenProjection.createObject(child :: Nil)
+  override def dataType: DataType = LongType
+  override def eval(input: InternalRow): Any = {
+    proj(input).getLong(0)

Review comment:
       My point is that, the test here is not really an end-to-end test. It's 
just used to trigger `FailedCodegenProjection`

##########
File path: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
##########
@@ -2555,6 +2555,24 @@ class DataFrameSuite extends QueryTest
     val df = Seq(0.0 -> -0.0).toDF("pos", "neg")
     checkAnswer(df.select($"pos" > $"neg"), Row(false))
   }
+
+  test("SPARK-32851: should fail if errors happen when generating expr code") {
+    val errMsg = intercept[SparkException] {
+      withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "false") {
+        val df = spark.range(1)
+        df.select(Column(FailedCodegenExpr(df("id").expr)) :: Nil: _*).show()
+      }
+    }.getCause.getMessage
+    assert(errMsg.contains("failed to compile:"))
+  }
 }
 
 case class GroupByKey(a: Int, b: Int)
+
+case class FailedCodegenExpr(child: Expression) extends UnaryExpression with 
CodegenFallback {
+  private lazy val proj = FailedCodegenProjection.createObject(child :: Nil)
+  override def dataType: DataType = LongType
+  override def eval(input: InternalRow): Any = {
+    proj(input).getLong(0)

Review comment:
       Yea I think it's OK to just change the config in test.




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