Skip to content

Commit

Permalink
Expand test scope + clean up test code
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Or committed Mar 16, 2016
1 parent 08969cd commit ad43a5f
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ class InMemoryCatalog extends ExternalCatalog {

private def requireFunctionExists(db: String, funcName: String): Unit = {
if (!existsFunction(db, funcName)) {
throw new AnalysisException(s"Function $funcName does not exist in $db database")
throw new AnalysisException(s"Function '$funcName' does not exist in database '$db'")
}
}

private def requireTableExists(db: String, table: String): Unit = {
if (!existsTable(db, table)) {
throw new AnalysisException(s"Table $table does not exist in $db database")
throw new AnalysisException(s"Table '$table' does not exist in database '$db'")
}
}

private def requirePartitionExists(db: String, table: String, spec: TablePartitionSpec): Unit = {
if (!existsPartition(db, table, spec)) {
throw new AnalysisException(s"Partition does not exist in database $db table $table: $spec")
throw new AnalysisException(
s"Partition does not exist in database '$db' table '$table': '$spec'")
}
}

Expand All @@ -94,7 +95,7 @@ class InMemoryCatalog extends ExternalCatalog {
ignoreIfExists: Boolean): Unit = synchronized {
if (catalog.contains(dbDefinition.name)) {
if (!ignoreIfExists) {
throw new AnalysisException(s"Database ${dbDefinition.name} already exists.")
throw new AnalysisException(s"Database '${dbDefinition.name}' already exists.")
}
} else {
catalog.put(dbDefinition.name, new DatabaseDesc(dbDefinition))
Expand All @@ -109,17 +110,17 @@ class InMemoryCatalog extends ExternalCatalog {
if (!cascade) {
// If cascade is false, make sure the database is empty.
if (catalog(db).tables.nonEmpty) {
throw new AnalysisException(s"Database $db is not empty. One or more tables exist.")
throw new AnalysisException(s"Database '$db' is not empty. One or more tables exist.")
}
if (catalog(db).functions.nonEmpty) {
throw new AnalysisException(s"Database $db is not empty. One or more functions exist.")
throw new AnalysisException(s"Database '$db' is not empty. One or more functions exist.")
}
}
// Remove the database.
catalog.remove(db)
} else {
if (!ignoreIfNotExists) {
throw new AnalysisException(s"Database $db does not exist")
throw new AnalysisException(s"Database '$db' does not exist")
}
}
}
Expand Down Expand Up @@ -160,7 +161,7 @@ class InMemoryCatalog extends ExternalCatalog {
val table = tableDefinition.name.table
if (existsTable(db, table)) {
if (!ignoreIfExists) {
throw new AnalysisException(s"Table $table already exists in $db database")
throw new AnalysisException(s"Table '$table' already exists in database '$db'")
}
} else {
catalog(db).tables.put(table, new TableDesc(tableDefinition))
Expand Down Expand Up @@ -224,8 +225,8 @@ class InMemoryCatalog extends ExternalCatalog {
val dupSpecs = parts.collect { case p if existingParts.contains(p.spec) => p.spec }
if (dupSpecs.nonEmpty) {
val dupSpecsStr = dupSpecs.mkString("\n===\n")
throw new AnalysisException(
s"The following partitions already exist in database $db table $table:\n$dupSpecsStr")
throw new AnalysisException("The following partitions already exist in database " +
s"'$db' table '$table':\n$dupSpecsStr")
}
}
parts.foreach { p => existingParts.put(p.spec, p) }
Expand All @@ -242,8 +243,8 @@ class InMemoryCatalog extends ExternalCatalog {
val missingSpecs = partSpecs.collect { case s if !existingParts.contains(s) => s }
if (missingSpecs.nonEmpty) {
val missingSpecsStr = missingSpecs.mkString("\n===\n")
throw new AnalysisException(
s"The following partitions do not exist in database $db table $table:\n$missingSpecsStr")
throw new AnalysisException("The following partitions do not exist in database " +
s"'$db' table '$table':\n$missingSpecsStr")
}
}
partSpecs.foreach(existingParts.remove)
Expand Down Expand Up @@ -295,7 +296,7 @@ class InMemoryCatalog extends ExternalCatalog {
override def createFunction(db: String, func: CatalogFunction): Unit = synchronized {
requireDbExists(db)
if (existsFunction(db, func.name.funcName)) {
throw new AnalysisException(s"Function $func already exists in $db database")
throw new AnalysisException(s"Function '$func' already exists in '$db' database")
} else {
catalog(db).functions.put(func.name.funcName, func)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class SessionCatalog(externalCatalog: ExternalCatalog) {
def getCurrentDatabase: String = currentDb

def setCurrentDatabase(db: String): Unit = {
if (!databaseExists(db)) {
throw new AnalysisException(s"cannot set current database to non-existent '$db'")
}
currentDb = db
}

Expand Down Expand Up @@ -223,7 +226,7 @@ class SessionCatalog(externalCatalog: ExternalCatalog) {
*/
def listTables(db: String, pattern: String): Seq[TableIdentifier] = {
val dbTables =
externalCatalog.listTables(db, pattern).map { t => TableIdentifier(t, Some(currentDb)) }
externalCatalog.listTables(db, pattern).map { t => TableIdentifier(t, Some(db)) }
val regex = pattern.replaceAll("\\*", ".*").r
val _tempTables = tempTables.keys().asScala
.filter { t => regex.pattern.matcher(t).matches() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,11 @@ abstract class CatalogTestUtils {
CatalogDatabase(name, name + " description", newUriForDatabase(), Map.empty)
}

def newTable(name: String, db: String): CatalogTable = {
def newTable(name: String, db: String): CatalogTable = newTable(name, Some(db))

def newTable(name: String, database: Option[String] = None): CatalogTable = {
CatalogTable(
name = TableIdentifier(name, Some(db)),
name = TableIdentifier(name, database),
tableType = CatalogTableType.EXTERNAL_TABLE,
storage = storageFormat,
schema = Seq(CatalogColumn("col1", "int"), CatalogColumn("col2", "string")),
Expand Down
Loading

0 comments on commit ad43a5f

Please sign in to comment.