imback82 commented on a change in pull request #27391: [SPARK-30612][SQL]
Resolve qualified column name with v2 tables
URL: https://github.com/apache/spark/pull/27391#discussion_r374471639
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/package.scala
##########
@@ -204,13 +209,85 @@ package object expressions {
// If none of attributes match database.table.column pattern or
// `table.column` pattern, we try to resolve it as a column.
- val (candidates, nestedFields) = matches match {
+ matches match {
case (Seq(), _) =>
val name = nameParts.head
val attributes = collectMatches(name,
direct.get(name.toLowerCase(Locale.ROOT)))
(attributes, nameParts.tail)
case _ => matches
}
+ }
+
+ /**
+ * Match attributes for the case where at least one qualifier in `attrs`
has more than 2 parts.
+ */
+ private def matchWithThreeOrMorePartQualifiers(
+ nameParts: Seq[String],
+ resolver: Resolver): (Seq[Attribute], Seq[String]) = {
+ // Returns true if the `short` qualifier is a subset of the last
elements of
+ // `long` qualifier. For example, Seq("a", "b") is a subset of Seq("a",
"a", "b"),
+ // but not a subset of Seq("a", "b", "b").
+ def matchQualifier(short: Seq[String], long: Seq[String]): Boolean = {
+ (long.length >= short.length) &&
+ long.takeRight(short.length)
+ .zip(short)
+ .forall(x => resolver(x._1, x._2))
+ }
+
+ // Collect attributes that match the given name and qualifier.
+ // A match occurs if
+ // 1) the given name matches the attribute's name according to the
resolver.
+ // 2) the given qualifier is a subset of the attribute's qualifier.
+ def collectMatches(
+ name: String,
+ qualifier: Seq[String],
+ candidates: Option[Seq[Attribute]]): Seq[Attribute] = {
+ candidates.toSeq.flatMap(_.collect {
Review comment:
Yes, that's simpler. I will make changes to both places.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]