Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4068#discussion_r23667563
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -285,11 +285,22 @@ class Analyzer(catalog: Catalog,
                 result
     
               // Resolve field names using the resolver.
    -          case f @ GetField(child, fieldName) if !f.resolved && 
child.resolved =>
    +          case f @ GetField(child, fieldName) if child.resolved =>
                 child.dataType match {
                   case StructType(fields) =>
    -                val resolvedFieldName = 
fields.map(_.name).find(resolver(_, fieldName))
    -                resolvedFieldName.map(n => f.copy(fieldName = 
n)).getOrElse(f)
    +                val actualField = fields.filter(f => resolver(f.name, 
fieldName))
    +                if (actualField.length == 0) {
    +                  sys.error(
    +                    s"No such struct field $fieldName in 
${fields.map(_.name).mkString(", ")}")
    --- End diff --
    
    If we leave it unchanged, `CheckResolution` can't catch it. The reason is 
that, we need `Resolver` to check if a `GetField` is resolved, but we can't get 
`Resolver` inside `GetField`.
    Fortunately, we can catch it at runtime, as `GetField` will report error if 
it can't find the required field.
    Which way should we prefer? Leaving it unchanged or reporting error right 
away?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to