Skip to content

Commit 9613be9

Browse files
committed
review fix
1 parent 7fef712 commit 9613be9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ case class CreateNamedStruct(children: Seq[Expression]) extends Expression {
9999
StructType(fields)
100100
}
101101

102-
override def foldable: Boolean = children.forall(_.foldable)
102+
override def foldable: Boolean = valExprs.forall(_.foldable)
103103

104104
override def nullable: Boolean = false
105105

@@ -111,7 +111,8 @@ case class CreateNamedStruct(children: Seq[Expression]) extends Expression {
111111
nameExprs.filterNot(e => e.foldable && e.dataType == StringType && !nullable)
112112
if (invalidNames.size != 0) {
113113
TypeCheckResult.TypeCheckFailure(
114-
s"Non String Literal fields at odd position : ${invalidNames.mkString(",")}")
114+
s"Odd position only allow foldable and not-null StringType expressions, got :" +
115+
s" ${invalidNames.mkString(",")}")
115116
} else {
116117
TypeCheckResult.TypeCheckSuccess
117118
}

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/ExpressionTypeCheckingSuite.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ class ExpressionTypeCheckingSuite extends SparkFunSuite {
165165
assertError(
166166
CreateNamedStruct(Seq("a", "b", 2.0)), "even number of arguments")
167167
assertError(
168-
CreateNamedStruct(Seq(1, "a", "b", 2.0)), "Non String Literal fields")
168+
CreateNamedStruct(Seq(1, "a", "b", 2.0)),
169+
"Odd position only allow foldable and not-null StringType expressions")
169170
assertError(
170-
CreateNamedStruct(Seq('a.string.at(0), "a", "b", 2.0)), "Non String Literal fields")
171+
CreateNamedStruct(Seq('a.string.at(0), "a", "b", 2.0)),
172+
"Odd position only allow foldable and not-null StringType expressions")
171173
}
172174
}

0 commit comments

Comments
 (0)