imback82 commented on a change in pull request #27391: [WIP][SPARK-30612][SQL]
Resolve qualified column name with v2 tables
URL: https://github.com/apache/spark/pull/27391#discussion_r372740322
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/package.scala
##########
@@ -128,90 +127,66 @@ package object expressions {
m.mapValues(_.distinct).map(identity)
}
- /** Map to use for direct case insensitive attribute lookups. */
- @transient private lazy val direct: Map[String, Seq[Attribute]] = {
+ /** Attribute name to attributes */
+ @transient private val attrsMap: Map[String, Seq[Attribute]] = {
unique(attrs.groupBy(_.name.toLowerCase(Locale.ROOT)))
}
- /** Map to use for qualified case insensitive attribute lookups with 2
part key */
- @transient private lazy val qualified: Map[(String, String),
Seq[Attribute]] = {
- // key is 2 part: table/alias and name
- val grouped = attrs.filter(_.qualifier.nonEmpty).groupBy {
- a => (a.qualifier.last.toLowerCase(Locale.ROOT),
a.name.toLowerCase(Locale.ROOT))
- }
- unique(grouped)
- }
-
- /** Map to use for qualified case insensitive attribute lookups with 3
part key */
- @transient private val qualified3Part: Map[(String, String, String),
Seq[Attribute]] = {
- // key is 3 part: database name, table name and name
- val grouped = attrs.filter(_.qualifier.length == 2).groupBy { a =>
- (a.qualifier.head.toLowerCase(Locale.ROOT),
- a.qualifier.last.toLowerCase(Locale.ROOT),
- a.name.toLowerCase(Locale.ROOT))
- }
- unique(grouped)
- }
-
/** Perform attribute resolution given a name and a resolver. */
def resolve(nameParts: Seq[String], resolver: Resolver):
Option[NamedExpression] = {
- // Collect matching attributes given a name and a lookup.
- def collectMatches(name: String, candidates: Option[Seq[Attribute]]):
Seq[Attribute] = {
- candidates.toSeq.flatMap(_.collect {
- case a if resolver(a.name, name) => a.withName(name)
- })
+ // Returns true if the `short` qualifier is a subset of the last
elements of
Review comment:
@cloud-fan @brkyvz This is a WIP PR, but I wanted to get early feedback on
this resolution logic. Thanks in advance!
----------------------------------------------------------------
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]