Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/9343#discussion_r43703049
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala
---
@@ -166,26 +166,63 @@ abstract class Star extends LeafExpression with
NamedExpression {
* Represents all of the input attributes to a given relational operator,
for example in
* "SELECT * FROM ...".
*
- * @param table an optional table that should be the target of the
expansion. If omitted all
- * tables' columns are produced.
+ * This is also used to expand structs. For example:
+ * "SELECT record.* from (SELECT struct(a,b,c) as record ...)
+ *
+ * @param target an optional name that should be the target of the
expansion. If omitted all
+ * targets' columns are produced. This can either be a table
name or struct name. This
+ * is a list of identifiers that is the path of the expansion.
*/
-case class UnresolvedStar(table: Option[String]) extends Star with
Unevaluable {
+case class UnresolvedStar(target: Option[Seq[String]]) extends Star with
Unevaluable {
+
+ override def expand(input: LogicalPlan, resolver: Resolver):
Seq[NamedExpression] = {
- override def expand(input: Seq[Attribute], resolver: Resolver):
Seq[NamedExpression] = {
- val expandedAttributes: Seq[Attribute] = table match {
+ // First try to expand assuming it is table.*.
+ val expandedAttributes: Seq[Attribute] = target match {
// If there is no table specified, use all input attributes.
- case None => input
+ case None => input.output
// If there is a table, pick out attributes that are part of this
table.
- case Some(t) => input.filter(_.qualifiers.filter(resolver(_,
t)).nonEmpty)
+ case Some(t) => if (t.size == 1) {
+ input.output.filter(_.qualifiers.filter(resolver(_,
t.head)).nonEmpty)
+ } else {
+ List()
+ }
}
- expandedAttributes.zip(input).map {
+ expandedAttributes.zip(input.output).map {
--- End diff --
How about we add an assert to make sure that `expandedAttributes` and
`input.output` have the same length? Otherwise, `zip` will silently drop extra
elements.
---
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]