Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2382#discussion_r18065885
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
 ---
    @@ -96,21 +103,69 @@ abstract class LogicalPlan extends 
QueryPlan[LogicalPlan] {
         val options = input.flatMap { option =>
           // If the first part of the desired name matches a qualifier for 
this possible match, drop it.
           val remainingParts =
    -        if (option.qualifiers.contains(parts.head) && parts.size > 1) 
parts.drop(1) else parts
    -      if (option.name == remainingParts.head) (option, 
remainingParts.tail.toList) :: Nil else Nil
    +        if (option.qualifiers.find(resolver(_, parts.head)).nonEmpty && 
parts.size > 1) {
    +          parts.drop(1)
    +        } else {
    +          parts
    +        }
    +
    +      if (resolver(option.name, remainingParts.head)) {
    +        // Preserve the case of the user's attribute reference.
    +        (option.withName(remainingParts.head), remainingParts.tail.toList) 
:: Nil
    +      } else {
    +        Nil
    +      }
         }
     
         options.distinct match {
    -      case Seq((a, Nil)) => Some(a) // One match, no nested fields, use it.
    +      // One match, no nested fields, use it.
    +      case Seq((a, Nil)) => Some(a)
    +
           // One match, but we also need to extract the requested nested field.
           case Seq((a, nestedFields)) =>
    -        Some(Alias(nestedFields.foldLeft(a: Expression)(GetField), 
nestedFields.last)())
    -      case Seq() => None         // No matches.
    +        val aliased =
    +          Alias(
    +            resolveNesting(nestedFields, a, resolver),
    +            nestedFields.last)() // Preserve the case of the user's field 
access.
    +        Some(aliased)
    +
    +      // No matches.
    +      case Seq() =>
    +        logTrace(s"Could not find $name in ${input.mkString(", ")}")
    +        None
    +
    +      // More than one match.
           case ambiguousReferences =>
             throw new TreeNodeException(
               this, s"Ambiguous references to $name: 
${ambiguousReferences.mkString(",")}")
         }
       }
    +
    +  /**
    +   * Given a list of successive nested field accesses, and a based 
expression, attempt to resolve
    +   * the actual field lookups on this expression.
    +   */
    +  private def resolveNesting(
    +      nestedFields: List[String],
    +      expression: Expression,
    +      resolver: Resolver): Expression = {
    +
    +    (nestedFields, expression.dataType) match {
    +      case (Nil, _) => expression
    +      case (requestedField :: rest, StructType(fields)) =>
    +        val actualField = fields.filter(f => resolver(f.name, 
requestedField))
    --- End diff --
    
    Hmm, good point.  Right now you can't make a SQLContext case insensitive, 
but when you can this will be problem.  Maybe you should note this on 
[SPARK-3617](https://issues.apache.org/jira/browse/SPARK-3617)


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to