Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,4 @@ private[sql] trait LookupCatalog extends Logging {
None
}
}

/**
* For temp views, extract a table identifier from a multi-part identifier if it has no catalog.
*/
object AsTemporaryViewIdentifier {
def unapply(parts: Seq[String]): Option[TableIdentifier] = parts match {
case CatalogAndMultipartIdentifier(None, Seq(table)) =>
Some(TableIdentifier(table))
case CatalogAndMultipartIdentifier(None, Seq(database, table)) =>
Some(TableIdentifier(table, Some(database)))
case _ =>
None
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,34 +102,6 @@ class LookupCatalogSuite extends SparkFunSuite with LookupCatalog with Inside {
}
}
}

test("temporary table identifier") {
Seq(
("tbl", TableIdentifier("tbl")),
("db.tbl", TableIdentifier("tbl", Some("db"))),
("`db.tbl`", TableIdentifier("db.tbl")),
("parquet.`file:/tmp/db.tbl`", TableIdentifier("file:/tmp/db.tbl", Some("parquet"))),
("`org.apache.spark.sql.json`.`s3://buck/tmp/abc.json`",
TableIdentifier("s3://buck/tmp/abc.json", Some("org.apache.spark.sql.json")))).foreach {
case (sqlIdent: String, expectedTableIdent: TableIdentifier) =>
// when there is no catalog and the namespace has one part, the rule should match
inside(parseMultipartIdentifier(sqlIdent)) {
case AsTemporaryViewIdentifier(ident) =>
ident shouldEqual expectedTableIdent
}
}

Seq("prod.func", "prod.db.tbl", "test.db.tbl", "ns1.ns2.tbl", "test.ns1.ns2.ns3.tbl")
.foreach { sqlIdent =>
inside(parseMultipartIdentifier(sqlIdent)) {
case AsTemporaryViewIdentifier(_) =>
fail("AsTemporaryViewIdentifier should not match when " +
"the catalog is set or the namespace has multiple parts")
case _ =>
// expected
}
}
}
}

class LookupCatalogWithDefaultSuite extends SparkFunSuite with LookupCatalog with Inside {
Expand Down Expand Up @@ -186,32 +158,4 @@ class LookupCatalogWithDefaultSuite extends SparkFunSuite with LookupCatalog wit
}
}
}

test("temporary table identifier") {
Seq(
("tbl", TableIdentifier("tbl")),
("db.tbl", TableIdentifier("tbl", Some("db"))),
("`db.tbl`", TableIdentifier("db.tbl")),
("parquet.`file:/tmp/db.tbl`", TableIdentifier("file:/tmp/db.tbl", Some("parquet"))),
("`org.apache.spark.sql.json`.`s3://buck/tmp/abc.json`",
TableIdentifier("s3://buck/tmp/abc.json", Some("org.apache.spark.sql.json")))).foreach {
case (sqlIdent: String, expectedTableIdent: TableIdentifier) =>
// when there is no catalog and the namespace has one part, the rule should match
inside(parseMultipartIdentifier(sqlIdent)) {
case AsTemporaryViewIdentifier(ident) =>
ident shouldEqual expectedTableIdent
}
}

Seq("prod.func", "prod.db.tbl", "test.db.tbl", "ns1.ns2.tbl", "test.ns1.ns2.ns3.tbl")
.foreach { sqlIdent =>
inside(parseMultipartIdentifier(sqlIdent)) {
case AsTemporaryViewIdentifier(_) =>
fail("AsTemporaryViewIdentifier should not match when " +
"the catalog is set or the namespace has multiple parts")
case _ =>
// expected
}
}
}
}