Skip to content

Commit

Permalink
[SPARK-24633][SQL] Fix codegen when split is required for arrays_zip
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

In function array_zip, when split is required by the high number of arguments, a codegen error can happen.

The PR fixes codegen for cases when splitting the code is required.

## How was this patch tested?

added UT

Author: Marco Gaido <[email protected]>

Closes #21621 from mgaido91/SPARK-24633.
  • Loading branch information
mgaido91 authored and cloud-fan committed Jun 25, 2018
1 parent bac50aa commit 594ac4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ case class ArraysZip(children: Seq[Expression]) extends Expression with ExpectsI
""".stripMargin
}

val splittedGetValuesAndCardinalities = ctx.splitExpressions(
val splittedGetValuesAndCardinalities = ctx.splitExpressionsWithCurrentInputs(
expressions = getValuesAndCardinalities,
funcName = "getValuesAndCardinalities",
returnType = "int",
Expand All @@ -210,7 +210,7 @@ case class ArraysZip(children: Seq[Expression]) extends Expression with ExpectsI
|return $biggestCardinality;
""".stripMargin,
foldFunctions = _.map(funcCall => s"$biggestCardinality = $funcCall;").mkString("\n"),
arguments =
extraArguments =
("ArrayData[]", arrVals) ::
("int", biggestCardinality) :: Nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,17 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSQLContext {
checkAnswer(df8.selectExpr("arrays_zip(v1, v2)"), expectedValue8)
}

test("SPARK-24633: arrays_zip splits input processing correctly") {
Seq("true", "false").foreach { wholestageCodegenEnabled =>
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> wholestageCodegenEnabled) {
val df = spark.range(1)
val exprs = (0 to 5).map(x => array($"id" + lit(x)))
checkAnswer(df.select(arrays_zip(exprs: _*)),
Row(Seq(Row(0, 1, 2, 3, 4, 5))))
}
}
}

test("map size function") {
val df = Seq(
(Map[Int, Int](1 -> 1, 2 -> 2), "x"),
Expand Down

0 comments on commit 594ac4f

Please sign in to comment.