Skip to content
Merged
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 @@ -270,6 +270,7 @@ case class ArraysZip(children: Seq[Expression], names: Seq[Expression])
case (u: UnresolvedAttribute, _) => Literal(u.nameParts.last)
case (e: NamedExpression, _) if e.resolved => Literal(e.name)
case (e: NamedExpression, _) => NamePlaceholder
case (e: GetStructField, _) => Literal(e.extractFieldName)
case (_, idx) => Literal(idx.toString)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,25 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
}
}

test("SPARK-40292: arrays_zip should retain field names in nested structs") {
val df = spark.sql("""
select
named_struct(
'arr_1', array(named_struct('a', 1, 'b', 2)),
'arr_2', array(named_struct('p', 1, 'q', 2)),
'field', named_struct(
'arr_3', array(named_struct('x', 1, 'y', 2))
)
) as obj
""")

val res = df.selectExpr("arrays_zip(obj.arr_1, obj.arr_2, obj.field.arr_3) as arr")

val fieldNames = res.schema.head.dataType.asInstanceOf[ArrayType]
.elementType.asInstanceOf[StructType].fieldNames
assert(fieldNames.toSeq === Seq("arr_1", "arr_2", "arr_3"))
}

def testSizeOfMap(sizeOfNull: Any): Unit = {
val df = Seq(
(Map[Int, Int](1 -> 1, 2 -> 2), "x"),
Expand Down