Github user chenghao-intel commented on a diff in the pull request:
https://github.com/apache/spark/pull/4892#discussion_r25920330
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
---
@@ -192,14 +193,17 @@ abstract class LogicalPlan extends
QueryPlan[LogicalPlan] with Logging {
// One match, but we also need to extract the requested nested field.
case Seq((a, nestedFields)) =>
- // The foldLeft adds UnresolvedGetField for every remaining parts
of the name,
- // and aliased it with the last part of the name.
- // For example, consider name "a.b.c", where "a" is resolved to an
existing attribute.
- // Then this will add UnresolvedGetField("b") and
UnresolvedGetField("c"), and alias
- // the final expression as "c".
- val fieldExprs = nestedFields.foldLeft(a:
Expression)(UnresolvedGetField)
- val aliasName = nestedFields.last
- Some(Alias(fieldExprs, aliasName)())
+ // The foldLeft will resolve all of the nested data type, to get
its attributes.
+ val fieldExprs = nestedFields.foldLeft(a: Expression) { case (e,
fieldName) =>
+ resolveGetField(e, fieldName, resolver)
+ }
+
+ // TODO the alias name is quite tricky to me, set it to _col1,
_col2.. ?
+ // Set it as original attribute name like "a.b.c" seems still
confusing,
+ // and we may never reference this column by its name (with "."),
except
+ // people write SQL like: SELECT a.b.c as newCol FROM nestedTable,
which
+ // explicitly specifying the alias name for the output column
+ Some(Alias(fieldExprs, name)())
--- End diff --
Yes, I agree we shouldn't break the existed logic, but I believe this is a
bug of Hive.
```
hive>create table struct1 as select named_struct("a",key, "b", value) as a,
key as b from src limit 1;
hive>select a.b, b from struct1; -- Works
hive>create table struct2 as select a.b, b from struct1;
FAILED: SemanticException [Error 10036]: Duplicate column name: b
```
I am wondering if we can break the naming rule of Hive for nested data type
references, which always causes ambiguous.
---
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]