Skip to content
Snippets Groups Projects
Commit a6cd9dbc authored by gatorsmile's avatar gatorsmile Committed by Wenchen Fan
Browse files

[SPARK-19029][SQL] Remove databaseName from SimpleCatalogRelation

### What changes were proposed in this pull request?
Remove useless `databaseName ` from `SimpleCatalogRelation`.

### How was this patch tested?
Existing test cases.

Author: gatorsmile <gatorsmile@gmail.com>

Closes #16438 from gatorsmile/removeDBFromSimpleCatalogRelation.
parent 46b21260
No related branches found
No related tags found
No related merge requests found
......@@ -573,7 +573,7 @@ class SessionCatalog(
val view = Option(metadata.tableType).collect {
case CatalogTableType.VIEW => name
}
SubqueryAlias(relationAlias, SimpleCatalogRelation(db, metadata), view)
SubqueryAlias(relationAlias, SimpleCatalogRelation(metadata), view)
} else {
SubqueryAlias(relationAlias, tempTables(table), Option(name))
}
......
......@@ -318,7 +318,6 @@ trait CatalogRelation {
* Note that in the future we should consolidate this and HiveCatalogRelation.
*/
case class SimpleCatalogRelation(
databaseName: String,
metadata: CatalogTable)
extends LeafNode with CatalogRelation {
......@@ -335,8 +334,4 @@ case class SimpleCatalogRelation(
}
dataCols ++ partCols
}
require(
metadata.identifier.database == Some(databaseName),
"provided database does not match the one specified in the table definition")
}
......@@ -433,24 +433,24 @@ class SessionCatalogSuite extends SparkFunSuite {
sessionCatalog.setCurrentDatabase("db2")
// If we explicitly specify the database, we'll look up the relation in that database
assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1", Some("db2")))
== SubqueryAlias("tbl1", SimpleCatalogRelation("db2", metastoreTable1), None))
== SubqueryAlias("tbl1", SimpleCatalogRelation(metastoreTable1), None))
// Otherwise, we'll first look up a temporary table with the same name
assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1"))
== SubqueryAlias("tbl1", tempTable1, Some(TableIdentifier("tbl1"))))
// Then, if that does not exist, look up the relation in the current database
sessionCatalog.dropTable(TableIdentifier("tbl1"), ignoreIfNotExists = false, purge = false)
assert(sessionCatalog.lookupRelation(TableIdentifier("tbl1"))
== SubqueryAlias("tbl1", SimpleCatalogRelation("db2", metastoreTable1), None))
== SubqueryAlias("tbl1", SimpleCatalogRelation(metastoreTable1), None))
}
test("lookup table relation with alias") {
val catalog = new SessionCatalog(newBasicCatalog())
val alias = "monster"
val tableMetadata = catalog.getTableMetadata(TableIdentifier("tbl1", Some("db2")))
val relation = SubqueryAlias("tbl1", SimpleCatalogRelation("db2", tableMetadata), None)
val relation = SubqueryAlias("tbl1", SimpleCatalogRelation(tableMetadata), None)
val relationWithAlias =
SubqueryAlias(alias,
SimpleCatalogRelation("db2", tableMetadata), None)
SimpleCatalogRelation(tableMetadata), None)
assert(catalog.lookupRelation(
TableIdentifier("tbl1", Some("db2")), alias = None) == relation)
assert(catalog.lookupRelation(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment