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 @@ -555,6 +555,10 @@ class CodegenContext {
* @param expressions the codes to evaluate expressions.
*/
def splitExpressions(row: String, expressions: Seq[String]): String = {
if (row == null) {
// Cannot split these expressions because they are not created from a row object.
return expressions.mkString("\n")
}
val blocks = new ArrayBuffer[String]()
val blockBuilder = new StringBuilder()
for (code <- expressions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ trait CodegenSupport extends SparkPlan {
}
val evaluateInputs = evaluateVariables(outputVars)
// generate the code to create a UnsafeRow
ctx.INPUT_ROW = row
ctx.currentVars = outputVars
val ev = GenerateUnsafeProjection.createCode(ctx, colExprs, false)
val code = s"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ case class TungstenAggregate(

// create grouping key
ctx.currentVars = input
// make sure that the generated code will not be splitted as multiple functions
ctx.INPUT_ROW = null
val unsafeRowKeyCode = GenerateUnsafeProjection.createCode(
ctx, groupingExpressions.map(e => BindReferences.bindReference[Expression](e, child.output)))
val vectorizedRowKeys = ctx.generateExpressions(
Expand Down
24 changes: 24 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,30 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
}
}

test("SPARK-15327: fail to compile generated code with complex data structure") {
withTempDir{ dir =>
val json =
"""
|{"h": {"b": {"c": [{"e": "adfgd"}], "a": [{"e": "testing", "count": 3}],
|"b": [{"e": "test", "count": 1}]}}, "d": {"b": {"c": [{"e": "adfgd"}],
|"a": [{"e": "testing", "count": 3}], "b": [{"e": "test", "count": 1}]}},
|"c": {"b": {"c": [{"e": "adfgd"}], "a": [{"count": 3}],
|"b": [{"e": "test", "count": 1}]}}, "a": {"b": {"c": [{"e": "adfgd"}],
|"a": [{"count": 3}], "b": [{"e": "test", "count": 1}]}},
|"e": {"b": {"c": [{"e": "adfgd"}], "a": [{"e": "testing", "count": 3}],
|"b": [{"e": "test", "count": 1}]}}, "g": {"b": {"c": [{"e": "adfgd"}],
|"a": [{"e": "testing", "count": 3}], "b": [{"e": "test", "count": 1}]}},
|"f": {"b": {"c": [{"e": "adfgd"}], "a": [{"e": "testing", "count": 3}],
|"b": [{"e": "test", "count": 1}]}}, "b": {"b": {"c": [{"e": "adfgd"}],
|"a": [{"count": 3}], "b": [{"e": "test", "count": 1}]}}}'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice fixture, haha!

|
""".stripMargin
val rdd = sparkContext.parallelize(Array(json))
spark.read.json(rdd).write.mode("overwrite").parquet(dir.toString)
spark.read.parquet(dir.toString).collect()
}
}

test("SPARK-14986: Outer lateral view with empty generate expression") {
checkAnswer(
sql("select nil from (select 1 as x ) x lateral view outer explode(array()) n as nil"),
Expand Down