Skip to content
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

[SPARK-22500][SQL] Fix 64KB JVM bytecode limit problem with cast #19730

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,9 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
}
val rowClass = classOf[GenericInternalRow].getName
val result = ctx.freshName("result")
ctx.addMutableState(s"$rowClass", result, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that since we not assigning it, we might keep it as a local variable and pass it to the generated methods. In this way we can avoid to introduce new global variables. Have you tried that?

val tmpRow = ctx.freshName("tmpRow")
ctx.addMutableState("InternalRow", tmpRow, "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


val fieldsEvalCode = fieldsCasts.zipWithIndex.map { case (cast, i) =>
val fromFieldPrim = ctx.freshName("ffp")
Expand All @@ -1039,13 +1041,14 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
}
}
"""
}.mkString("\n")
}
val fieldsEvalCodes = ctx.splitExpressions(ctx.INPUT_ROW, fieldsEvalCode)

(c, evPrim, evNull) =>
s"""
final $rowClass $result = new $rowClass(${fieldsCasts.length});
final InternalRow $tmpRow = $c;
$fieldsEvalCode
$result = new $rowClass(${fieldsCasts.length});
$tmpRow = $c;
$fieldsEvalCodes
$evPrim = $result;
"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,17 @@ class CastSuite extends SparkFunSuite with ExpressionEvalHelper {

checkEvaluation(cast(Literal.create(input, from), to), input)
}

test("SPARK-22500: cast for struct should not generate codes beyond 64KB") {
val N = 1000
val from = new StructType(
(1 to N).map(i => StructField(s"s$i", StringType)).toArray)
val to = new StructType(
(1 to N).map(i => StructField(s"i$i", IntegerType)).toArray)

val input = Row.fromSeq((1 to N).map(i => i.toString))
val output = Row.fromSeq((1 to N))

checkEvaluation(cast(Literal.create(input, from), to), output)
}
}