Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/3941#discussion_r22745717
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Catalog.scala
---
@@ -28,77 +28,63 @@ trait Catalog {
def caseSensitive: Boolean
- def tableExists(db: Option[String], tableName: String): Boolean
+ def tableExists(tableIdentifier: Seq[String]): Boolean
def lookupRelation(
- databaseName: Option[String],
- tableName: String,
- alias: Option[String] = None): LogicalPlan
+ tableIdentifier: Seq[String],
+ alias: Option[String] = None): LogicalPlan
- def registerTable(databaseName: Option[String], tableName: String, plan:
LogicalPlan): Unit
+ def registerTable(tableIdentifier: Seq[String], plan: LogicalPlan): Unit
- def unregisterTable(databaseName: Option[String], tableName: String):
Unit
+ def unregisterTable(tableIdentifier: Seq[String]): Unit
def unregisterAllTables(): Unit
- protected def processDatabaseAndTableName(
- databaseName: Option[String],
- tableName: String): (Option[String], String) = {
+ protected def processTableIdentifier(tableIdentifier: Seq[String]):
+ Seq[String] = {
if (!caseSensitive) {
- (databaseName.map(_.toLowerCase), tableName.toLowerCase)
+ tableIdentifier.map(_.toLowerCase)
} else {
- (databaseName, tableName)
+ tableIdentifier
}
}
- protected def processDatabaseAndTableName(
- databaseName: String,
- tableName: String): (String, String) = {
- if (!caseSensitive) {
- (databaseName.toLowerCase, tableName.toLowerCase)
- } else {
- (databaseName, tableName)
- }
- }
}
class SimpleCatalog(val caseSensitive: Boolean) extends Catalog {
val tables = new mutable.HashMap[String, LogicalPlan]()
override def registerTable(
- databaseName: Option[String],
- tableName: String,
+ tableIdentifier: Seq[String],
plan: LogicalPlan): Unit = {
- val (dbName, tblName) = processDatabaseAndTableName(databaseName,
tableName)
- tables += ((tblName, plan))
+ val tableIdent = processTableIdentifier(tableIdentifier)
+ tables += ((tableIdent.mkString("."), plan))
}
- override def unregisterTable(
- databaseName: Option[String],
- tableName: String) = {
- val (dbName, tblName) = processDatabaseAndTableName(databaseName,
tableName)
- tables -= tblName
+ override def unregisterTable(tableIdentifier: Seq[String]) = {
+ val tableIdent = processTableIdentifier(tableIdentifier)
+ tables -= tableIdent.mkString(".")
}
override def unregisterAllTables() = {
tables.clear()
}
- override def tableExists(db: Option[String], tableName: String): Boolean
= {
- val (dbName, tblName) = processDatabaseAndTableName(db, tableName)
- tables.get(tblName) match {
+ override def tableExists(tableIdentifier: Seq[String]): Boolean = {
+ val tableIdent = processTableIdentifier(tableIdentifier)
+ tables.get(tableIdent.mkString(".")) match {
case Some(_) => true
case None => false
}
}
override def lookupRelation(
- databaseName: Option[String],
- tableName: String,
+ tableIdentifier: Seq[String],
alias: Option[String] = None): LogicalPlan = {
- val (dbName, tblName) = processDatabaseAndTableName(databaseName,
tableName)
- val table = tables.getOrElse(tblName, sys.error(s"Table Not Found:
$tableName"))
- val tableWithQualifiers = Subquery(tblName, table)
+ val tableIdent = processTableIdentifier(tableIdentifier)
+ val tableFullName = tableIdent.mkString(".")
+ val table = tables.getOrElse(tableFullName, sys.error(s"Table Not
Found: $tableFullName"))
+ val tableWithQualifiers = Subquery(tableIdent.head, table)
--- End diff --
That does not seem worth the confusion of having it in reverse order. Also
looking at that code more closely, we would silently discard extra part of the
table identifier right? Seems like we should explicitly handle the cases where
there are 1, 2, and more elements of the table identifier.
---
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]