-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23711][SPARK-25140][SQL] Catch correct exceptions when expr codegen fails #22154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,17 +17,33 @@ | |
|
|
||
| package org.apache.spark.sql.catalyst.expressions | ||
|
|
||
| import java.util.concurrent.ExecutionException | ||
|
|
||
| import org.apache.spark.SparkFunSuite | ||
| import org.apache.spark.sql.catalyst.expressions.codegen.{CodeAndComment, CodeGenerator} | ||
| import org.apache.spark.sql.catalyst.plans.PlanTestBase | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.{IntegerType, LongType} | ||
| import org.apache.spark.sql.types.IntegerType | ||
|
|
||
| class CodeGeneratorWithInterpretedFallbackSuite extends SparkFunSuite with PlanTestBase { | ||
|
|
||
| test("UnsafeProjection with codegen factory mode") { | ||
| val input = Seq(LongType, IntegerType) | ||
| .zipWithIndex.map(x => BoundReference(x._2, x._1, true)) | ||
| object FailedCodegenProjection | ||
| extends CodeGeneratorWithInterpretedFallback[Seq[Expression], UnsafeProjection] { | ||
|
|
||
| override protected def createCodeGeneratedObject(in: Seq[Expression]): UnsafeProjection = { | ||
| val invalidCode = new CodeAndComment("invalid code", Map.empty) | ||
| // We assume this compilation throws an exception | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd use this comment as part of an exception (say
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The suggested change is only for making this test suite cleaner, right? In that case I'd +1 with the suggestion of being able to clearly check we're catching the exception we know we're throwing.
|
||
| CodeGenerator.compile(invalidCode) | ||
| null | ||
| } | ||
|
|
||
| override protected def createInterpretedObject(in: Seq[Expression]): UnsafeProjection = { | ||
| InterpretedUnsafeProjection.createProjection(in) | ||
| } | ||
| } | ||
|
|
||
| test("UnsafeProjection with codegen factory mode") { | ||
| val input = Seq(BoundReference(0, IntegerType, nullable = true)) | ||
| val codegenOnly = CodegenObjectFactoryMode.CODEGEN_ONLY.toString | ||
| withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> codegenOnly) { | ||
| val obj = UnsafeProjection.createObject(input) | ||
|
|
@@ -40,4 +56,24 @@ class CodeGeneratorWithInterpretedFallbackSuite extends SparkFunSuite with PlanT | |
| assert(obj.isInstanceOf[InterpretedUnsafeProjection]) | ||
| } | ||
| } | ||
|
|
||
| test("fallback to the interpreter mode") { | ||
| val input = Seq(BoundReference(0, IntegerType, nullable = true)) | ||
| val fallback = CodegenObjectFactoryMode.FALLBACK.toString | ||
| withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> fallback) { | ||
| val obj = FailedCodegenProjection.createObject(input) | ||
| assert(obj.isInstanceOf[InterpretedUnsafeProjection]) | ||
| } | ||
| } | ||
|
|
||
| test("codegen failures in the CODEGEN_ONLY mode") { | ||
| val errMsg = intercept[ExecutionException] { | ||
| val input = Seq(BoundReference(0, IntegerType, nullable = true)) | ||
| val codegenOnly = CodegenObjectFactoryMode.CODEGEN_ONLY.toString | ||
| withSQLConf(SQLConf.CODEGEN_FACTORY_MODE.key -> codegenOnly) { | ||
| FailedCodegenProjection.createObject(input) | ||
| } | ||
| }.getMessage | ||
| assert(errMsg.contains("failed to compile: org.codehaus.commons.compiler.CompileException:")) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not have a test case for checking the fallback before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't in the original PR. @maropu -san added one in this PR which is great, plugs the hole.