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 3 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,19 @@ 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(fieldsEvalCode, "castStruct",
("InternalRow", ctx.INPUT_ROW) :: (rowClass, result) :: ("InternalRow", tmpRow) :: Nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

how about inner struct? We also need to pass in the ctx.INPUT_ROW?

Copy link
Member Author

@kiszk kiszk Nov 16, 2017

Choose a reason for hiding this comment

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

Inner struct case in the following code and existing cases in CastSuite works well. Tomorrow, I will add similar test case with many fields.

    val struct = Literal.create(
      Row(
        UTF8String.fromString("123.4"),
        Seq("456", "true", "78.9"),
        Row(7)),
      StructType(Seq(
        StructField("i", StringType, nullable = true),
        StructField("a",
          ArrayType(StringType, containsNull = false), nullable = true),
        StructField("s",
          StructType(Seq(
            StructField("i", IntegerType, nullable = true)))))))

    val ret = cast(struct, StructType(Seq(
      StructField("d", DoubleType, nullable = true),
      StructField("a",
        ArrayType(IntegerType, containsNull = true), nullable = true),
      StructField("s",
        StructType(Seq(
          StructField("l", LongType, nullable = true)))))))

    assert(ret.resolved === true)
    checkEvaluation(ret, Row(123.4, Seq(456, null, 78), Row(7L)))

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, we don't need to pass in ctx.INPUT_ROW to the split functions.

} 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,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)
}
}