Skip to content

Commit 50cfc33

Browse files
hvanhovellRobert Kruszewski
authored andcommitted
Revert "[SPARK-23593][SQL] Add interpreted execution for InitializeJavaBean expression"
This reverts commit c5c8b54.
1 parent fb64523 commit 50cfc33

File tree

3 files changed

+5
-103
lines changed

3 files changed

+5
-103
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,47 +1420,8 @@ case class InitializeJavaBean(beanInstance: Expression, setters: Map[String, Exp
14201420
override def children: Seq[Expression] = beanInstance +: setters.values.toSeq
14211421
override def dataType: DataType = beanInstance.dataType
14221422

1423-
private lazy val resolvedSetters = {
1424-
assert(beanInstance.dataType.isInstanceOf[ObjectType])
1425-
1426-
val ObjectType(beanClass) = beanInstance.dataType
1427-
setters.map {
1428-
case (name, expr) =>
1429-
// Looking for known type mapping.
1430-
// But also looking for general `Object`-type parameter for generic methods.
1431-
val paramTypes = ScalaReflection.expressionJavaClasses(Seq(expr)) ++ Seq(classOf[Object])
1432-
val methods = paramTypes.flatMap { fieldClass =>
1433-
try {
1434-
Some(beanClass.getDeclaredMethod(name, fieldClass))
1435-
} catch {
1436-
case e: NoSuchMethodException => None
1437-
}
1438-
}
1439-
if (methods.isEmpty) {
1440-
throw new NoSuchMethodException(s"""A method named "$name" is not declared """ +
1441-
"in any enclosing class nor any supertype")
1442-
}
1443-
methods.head -> expr
1444-
}
1445-
}
1446-
1447-
override def eval(input: InternalRow): Any = {
1448-
val instance = beanInstance.eval(input)
1449-
if (instance != null) {
1450-
val bean = instance.asInstanceOf[Object]
1451-
resolvedSetters.foreach {
1452-
case (setter, expr) =>
1453-
val paramVal = expr.eval(input)
1454-
if (paramVal == null) {
1455-
throw new NullPointerException("The parameter value for setters in " +
1456-
"`InitializeJavaBean` can not be null")
1457-
} else {
1458-
setter.invoke(bean, paramVal.asInstanceOf[AnyRef])
1459-
}
1460-
}
1461-
}
1462-
instance
1463-
}
1423+
override def eval(input: InternalRow): Any =
1424+
throw new UnsupportedOperationException("Only code-generated evaluation is supported.")
14641425

14651426
override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
14661427
val instanceGen = beanInstance.genCode(ctx)
@@ -1473,10 +1434,6 @@ case class InitializeJavaBean(beanInstance: Expression, setters: Map[String, Exp
14731434
val fieldGen = fieldValue.genCode(ctx)
14741435
s"""
14751436
|${fieldGen.code}
1476-
|if (${fieldGen.isNull}) {
1477-
| throw new NullPointerException("The parameter value for setters in " +
1478-
| "`InitializeJavaBean` can not be null");
1479-
|}
14801437
|$javaBeanInstance.$setterMethod(${fieldGen.value});
14811438
""".stripMargin
14821439
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvalHelper.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ trait ExpressionEvalHelper extends GeneratorDrivenPropertyChecks {
5555

5656
protected def checkEvaluation(
5757
expression: => Expression, expected: Any, inputRow: InternalRow = EmptyRow): Unit = {
58-
// Make it as method to obtain fresh expression everytime.
59-
def expr = prepareEvaluation(expression)
58+
val expr = prepareEvaluation(expression)
6059
val catalystValue = CatalystTypeConverters.convertToCatalyst(expected)
6160
checkEvaluationWithoutCodegen(expr, catalystValue, inputRow)
6261
checkEvaluationWithGeneratedMutableProjection(expr, catalystValue, inputRow)
@@ -112,14 +111,12 @@ trait ExpressionEvalHelper extends GeneratorDrivenPropertyChecks {
112111
val errMsg = intercept[T] {
113112
eval
114113
}.getMessage
115-
if (!errMsg.contains(expectedErrMsg)) {
114+
if (errMsg != expectedErrMsg) {
116115
fail(s"Expected error message is `$expectedErrMsg`, but `$errMsg` found")
117116
}
118117
}
119118
}
120-
121-
// Make it as method to obtain fresh expression everytime.
122-
def expr = prepareEvaluation(expression)
119+
val expr = prepareEvaluation(expression)
123120
checkException(evaluateWithoutCodegen(expr, inputRow), "non-codegen mode")
124121
checkException(evaluateWithGeneratedMutableProjection(expr, inputRow), "codegen mode")
125122
if (GenerateUnsafeProjection.canSupport(expr.dataType)) {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ObjectExpressionsSuite.scala

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -192,50 +192,6 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
192192
Invoke(funcSubObj, "binOp", DoubleType, inputSum), 0.75, InternalRow.apply(1, 0.25))
193193
}
194194

195-
test("SPARK-23593: InitializeJavaBean should support interpreted execution") {
196-
val list = new java.util.LinkedList[Int]()
197-
list.add(1)
198-
199-
val initializeBean = InitializeJavaBean(Literal.fromObject(new java.util.LinkedList[Int]),
200-
Map("add" -> Literal(1)))
201-
checkEvaluation(initializeBean, list, InternalRow.fromSeq(Seq()))
202-
203-
val initializeWithNonexistingMethod = InitializeJavaBean(
204-
Literal.fromObject(new java.util.LinkedList[Int]),
205-
Map("nonexisting" -> Literal(1)))
206-
checkExceptionInExpression[Exception](initializeWithNonexistingMethod,
207-
InternalRow.fromSeq(Seq()),
208-
"""A method named "nonexisting" is not declared in any enclosing class """ +
209-
"nor any supertype")
210-
211-
val initializeWithWrongParamType = InitializeJavaBean(
212-
Literal.fromObject(new TestBean),
213-
Map("setX" -> Literal("1")))
214-
intercept[Exception] {
215-
evaluateWithoutCodegen(initializeWithWrongParamType, InternalRow.fromSeq(Seq()))
216-
}.getMessage.contains(
217-
"""A method named "setX" is not declared in any enclosing class """ +
218-
"nor any supertype")
219-
}
220-
221-
test("Can not pass in null into setters in InitializeJavaBean") {
222-
val initializeBean = InitializeJavaBean(
223-
Literal.fromObject(new TestBean),
224-
Map("setNonPrimitive" -> Literal(null)))
225-
intercept[NullPointerException] {
226-
evaluateWithoutCodegen(initializeBean, InternalRow.fromSeq(Seq()))
227-
}.getMessage.contains("The parameter value for setters in `InitializeJavaBean` can not be null")
228-
intercept[NullPointerException] {
229-
evaluateWithGeneratedMutableProjection(initializeBean, InternalRow.fromSeq(Seq()))
230-
}.getMessage.contains("The parameter value for setters in `InitializeJavaBean` can not be null")
231-
232-
val initializeBean2 = InitializeJavaBean(
233-
Literal.fromObject(new TestBean),
234-
Map("setNonPrimitive" -> Literal("string")))
235-
evaluateWithoutCodegen(initializeBean2, InternalRow.fromSeq(Seq()))
236-
evaluateWithGeneratedMutableProjection(initializeBean2, InternalRow.fromSeq(Seq()))
237-
}
238-
239195
test("SPARK-23585: UnwrapOption should support interpreted execution") {
240196
val cls = classOf[Option[Int]]
241197
val inputObject = BoundReference(0, ObjectType(cls), nullable = true)
@@ -386,11 +342,3 @@ class ObjectExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
386342
}
387343
}
388344
}
389-
390-
class TestBean extends Serializable {
391-
private var x: Int = 0
392-
393-
def setX(i: Int): Unit = x = i
394-
def setNonPrimitive(i: AnyRef): Unit =
395-
assert(i != null, "this setter should not be called with null.")
396-
}

0 commit comments

Comments
 (0)