Skip to content

Commit e86fbdb

Browse files
yjshenrxin
authored andcommitted
[SPARK-8283][SQL] Resolve udf_struct test failure in HiveCompatibilitySuite
This PR aimed to resolve udf_struct test failure in HiveCompatibilitySuite. Currently, this is done by loosening CreateStruct's children type from NamedExpression to Expression and automatically generating StructField name for non-NamedExpression children. The naming convention for unnamed children follows the udf's counterpart in Hive: `col1, col2, col3, ...` Author: Yijie Shen <[email protected]> Closes apache#6828 from yijieshen/SPARK-8283 and squashes the following commits: 6052b73 [Yijie Shen] Doc fix 677e0b7 [Yijie Shen] Resolve udf_struct test failure by automatically generate structField name for non-NamedExpression children
1 parent fee3438 commit e86fbdb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypes.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ case class CreateArray(children: Seq[Expression]) extends Expression {
5353
* Returns a Row containing the evaluation of all children expressions.
5454
* TODO: [[CreateStruct]] does not support codegen.
5555
*/
56-
case class CreateStruct(children: Seq[NamedExpression]) extends Expression {
56+
case class CreateStruct(children: Seq[Expression]) extends Expression {
5757

5858
override def foldable: Boolean = children.forall(_.foldable)
5959

@@ -62,9 +62,14 @@ case class CreateStruct(children: Seq[NamedExpression]) extends Expression {
6262
override lazy val dataType: StructType = {
6363
assert(resolved,
6464
s"CreateStruct contains unresolvable children: ${children.filterNot(_.resolved)}.")
65-
val fields = children.map { child =>
66-
StructField(child.name, child.dataType, child.nullable, child.metadata)
67-
}
65+
val fields = children.zipWithIndex.map { case (child, idx) =>
66+
child match {
67+
case ne: NamedExpression =>
68+
StructField(ne.name, ne.dataType, ne.nullable, ne.metadata)
69+
case _ =>
70+
StructField(s"col${idx + 1}", child.dataType, child.nullable, Metadata.empty)
71+
}
72+
}
6873
StructType(fields)
6974
}
7075

sql/hive/compatibility/src/test/scala/org/apache/spark/sql/hive/execution/HiveCompatibilitySuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
933933
"udf_stddev_pop",
934934
"udf_stddev_samp",
935935
"udf_string",
936-
// "udf_struct", TODO: FIX THIS and enable it.
936+
"udf_struct",
937937
"udf_substring",
938938
"udf_subtract",
939939
"udf_sum",

0 commit comments

Comments
 (0)