Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -1039,13 +1039,21 @@ case class Cast(child: Expression, dataType: DataType, timeZoneId: Option[String
}
}
"""
}.mkString("\n")
}
val fieldsEvalCodes = if (ctx.INPUT_ROW != null && ctx.currentVars == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't be ctx.currentVars != null?

Copy link
Member Author

Choose a reason for hiding this comment

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

If ctx.currentVars != null, we need to use mkString("\n").

ctx.splitExpressions(
expressions = fieldsEvalCode,
funcName = "castStruct",
arguments = ("InternalRow", tmpRow) :: (rowClass, result) :: Nil)
} else {
fieldsEvalCode.mkString("\n")
}

(c, evPrim, evNull) =>
s"""
final $rowClass $result = new $rowClass(${fieldsCasts.length});
final InternalRow $tmpRow = $c;
$fieldsEvalCode
$fieldsEvalCodes
$evPrim = $result;
"""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,22 @@ 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 = 250

val fromInner = new StructType(
(1 to N).map(i => StructField(s"s$i", DoubleType)).toArray)
val toInner = new StructType(
(1 to N).map(i => StructField(s"i$i", IntegerType)).toArray)
val inputInner = Row.fromSeq((1 to N).map(i => i + 0.5))
val outputInner = Row.fromSeq((1 to N))
val fromOuter = new StructType(
(1 to N).map(i => StructField(s"s$i", fromInner)).toArray)
val toOuter = new StructType(
(1 to N).map(i => StructField(s"s$i", toInner)).toArray)
val inputOuter = Row.fromSeq((1 to N).map(_ => inputInner))
val outputOuter = Row.fromSeq((1 to N).map(_ => outputInner))
checkEvaluation(cast(Literal.create(inputOuter, fromOuter), toOuter), outputOuter)
}
}