Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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 @@ -89,6 +89,8 @@ statement
(WITH DBPROPERTIES tablePropertyList))* #createDatabase
| ALTER database db=errorCapturingIdentifier
SET DBPROPERTIES tablePropertyList #setDatabaseProperties
| ALTER database db=errorCapturingIdentifier
SET locationSpec #setDatabaseLocation
| DROP database (IF EXISTS)? db=errorCapturingIdentifier
(RESTRICT | CASCADE)? #dropDatabase
| SHOW DATABASES (LIKE? pattern=STRING)? #showDatabases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,22 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder(conf) {
visitPropertyKeyValues(ctx.tablePropertyList))
}

/**
* Create an [[AlterDatabaseLocationCommand]] command.
*
* For example:
* {{{
* ALTER (DATABASE|SCHEMA) database SET LOCATION path;
* }}}
*/
override def visitSetDatabaseLocation(
ctx: SetDatabaseLocationContext): LogicalPlan = withOrigin(ctx) {
Comment thread
WeichenXu123 marked this conversation as resolved.
Outdated
AlterDatabaseLocationCommand(
Comment thread
WeichenXu123 marked this conversation as resolved.
Outdated
ctx.db.getText,
visitLocationSpec(ctx.locationSpec())
)
}

/**
* Create a [[DropDatabaseCommand]] command.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ case class AlterDatabasePropertiesCommand(
}
}

/**
* A command for users to set new location path for a database
* If the database does not exist, an error message will be issued to indicate the database
* does not exist.
* The syntax of using this command in SQL is:
* {{{
* ALTER (DATABASE|SCHEMA) database_name SET LOCATION path
* }}}
*/
case class AlterDatabaseLocationCommand(databaseName: String, location: String)
Comment thread
WeichenXu123 marked this conversation as resolved.
Outdated
extends RunnableCommand {

override def run(sparkSession: SparkSession): Seq[Row] = {
val catalog = sparkSession.sessionState.catalog
val db: CatalogDatabase = catalog.getDatabaseMetadata(databaseName)
catalog.alterDatabase(db.copy(locationUri = CatalogUtils.stringToURI(location)))

Seq.empty[Row]
}
}

/**
* A command for users to show the name of the database, its comment (if one has been set), and its
* root location on the filesystem. When extended is true, it also shows the database's properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ class DDLParserSuite extends AnalysisTest with SharedSQLContext {
containsThesePhrases = Seq("key_without_value"))
}

test("alter database set location") {
// ALTER (DATABASE|SCHEMA) database_name SET LOCATION
val sql1 = "ALTER DATABASE database_name SET LOCATION '/home/user/db'"

@gatorsmile gatorsmile Jul 30, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the parser test case.

Add both negative and positive end to end test cases?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it to DDLSuite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add a positive e2e test case.
What's the negative test case you want to add ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. A database that does not exist before issuing this command?
  2. Setting an illegal path that could trigger an exception inside the function stringToURI

val parsed1 = parser.parsePlan(sql1)

val expected1 = AlterDatabaseLocationCommand("database_name", "/home/user/db")
comparePlans(parsed1, expected1)
}

test("describe database") {
// DESCRIBE DATABASE [EXTENDED] db_name;
val sql1 = "DESCRIBE DATABASE EXTENDED db_name"
Expand Down