Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/17100#discussion_r146627111
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala
---
@@ -270,12 +270,25 @@ trait CheckAnalysis extends PredicateHelper {
operator match {
case o if o.children.nonEmpty && o.missingInput.nonEmpty =>
+ val resolver = plan.conf.resolver
+ val attrsWithSameName = o.missingInput.filter { missing =>
+ o.inputSet.exists(input => resolver(missing.name,
input.name))
+ }
+ val repeatedNameHint = if (attrsWithSameName.nonEmpty) {
+ val sameNames = attrsWithSameName.map(_.name).mkString(",")
+ s"""Attribute(s) with the same name appear in the operation:
`$sameNames`.
+ |Please check if the right attribute(s) are
used.""".stripMargin
+ } else {
+ ""
+ }
+
val missingAttributes = o.missingInput.mkString(",")
val input = o.inputSet.mkString(",")
- failAnalysis(
- s"resolved attribute(s) $missingAttributes missing from
$input " +
- s"in operator ${operator.simpleString}")
+ val msg = s"""Resolved attribute(s) $missingAttributes missing
from $input
+ |in operator
${operator.simpleString}.""".stripMargin
+
+ failAnalysis(if (repeatedNameHint.nonEmpty) msg + "\n" +
repeatedNameHint else msg)
--- End diff --
How about
```
val missingAttributes = o.missingInput.mkString(",")
val input = o.inputSet.mkString(",")
val msgForMissingAttributes = s"Resolved attribute(s)
$missingAttributes missing " +
s"from $input in operator ${operator.simpleString}."
val resolver = plan.conf.resolver
val attrsWithSameName = o.missingInput.filter { missing =>
o.inputSet.exists(input => resolver(missing.name, input.name))
}
val msg = if (attrsWithSameName.nonEmpty) {
val sameNames = attrsWithSameName.map(_.name).mkString(",")
s"$msgForMissingAttributes. Attribute(s) with the same name
appear in the " +
s"operation: $sameNames. Please check if the right
attribute(s) are used."
} else {
msgForMissingAttributes
}
failAnalysis(msg)
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]