Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/2543#discussion_r18316116
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -118,6 +120,19 @@ class Analyzer(catalog: Catalog, registry:
FunctionRegistry, caseSensitive: Bool
}
/**
+ * Make [[GetField]] case insensitive by passing a findField function
+ */
+ object ResolveGetField extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan transform {
+ case q: LogicalPlan =>
+ q transformExpressions {
+ case GetField(child, fieldName, null) =>
+ GetField(child, fieldName, f => resolver(f.name, fieldName))
+ }
--- End diff --
What about something like:
```scala
q transformExpressions {
case g @ GetField(child, fieldName) if child.resolved && ! g.resolved =>
val options = g.structType.fields.filter(f => resolver(f.name,
fieldName))
options match {
case Seq(oneMatch) => GetField(child, oneMatch)
case Seq() => g // No match: leave unresolved
case multipleMatches =>
sys.error(s"Ambiguious reference to $fieldName matches
${multipleMatches.mkString(",")}")
}
}
```
That way all logic related to resolution happens here in the analyzer and
GetField can remain unchanged.
---
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]