-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-12968][SQL] Implement command to set current database #10916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
46737b5
43beb4b
ee237e4
bffae43
9df380f
87c27ef
ff5508b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -408,3 +408,13 @@ case class DescribeFunction( | |
| } | ||
| } | ||
| } | ||
|
|
||
| case class SetDatabaseCommand(databaseName: String) extends RunnableCommand { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are introducing the concept of a database change in Catalyst. Shouldn't we also have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you mean should we move parsing |
||
|
|
||
| override def run(sqlContext: SQLContext): Seq[Row] = { | ||
| sqlContext.catalog.setCurrentDatabase(databaseName) | ||
| Seq.empty[Row] | ||
| } | ||
|
|
||
| override val output: Seq[Attribute] = Seq.empty | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,7 +183,7 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with Logging { | |
| "CREATE DATABASE hive_test_db;" | ||
| -> "OK", | ||
| "USE hive_test_db;" | ||
| -> "OK", | ||
| -> "", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a dumb idea: we could return Ok...
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return OK will break hive compatibility test. I've tried in previous commits. |
||
| "CREATE TABLE hive_test(key INT, val STRING);" | ||
| -> "OK", | ||
| "SHOW TABLES;" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,9 @@ private[hive] trait ClientInterface { | |
| /** Returns the name of the active database. */ | ||
| def currentDatabase: String | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we also have a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes we should - the only thing is that the simple catalog in non-Hive doesn't support databases yet.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I think we don't need to address database support for all catalogs in this PR?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would argue that when an interface allows us to set the current database, it should also allow us read it.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add a default implementation. |
||
|
|
||
| /** Sets the name of current database. */ | ||
| def setCurrentDatabase(databaseName: String): Unit | ||
|
|
||
| /** Returns the metadata for specified database, throwing an exception if it doesn't exist */ | ||
| def getDatabase(name: String): HiveDatabase = { | ||
| getDatabaseOption(name).getOrElse(throw new NoSuchDatabaseException) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import org.scalatest.BeforeAndAfter | |
|
|
||
| import org.apache.spark.{SparkException, SparkFiles} | ||
| import org.apache.spark.sql.{AnalysisException, DataFrame, Row} | ||
| import org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException | ||
| import org.apache.spark.sql.catalyst.expressions.Cast | ||
| import org.apache.spark.sql.catalyst.plans.logical.Project | ||
| import org.apache.spark.sql.execution.joins.BroadcastNestedLoopJoin | ||
|
|
@@ -1262,6 +1263,21 @@ class HiveQuerySuite extends HiveComparisonTest with BeforeAndAfter { | |
|
|
||
| } | ||
|
|
||
| test("use database") { | ||
| val currentDatabase = sql("select current_database()").first().getString(0) | ||
|
|
||
| sql("CREATE DATABASE hive_test_db") | ||
| sql("USE hive_test_db") | ||
| assert("hive_test_db" == sql("select current_database()").first().getString(0)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The We could move the command to catalyst, and add the command itself in the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we already have database support in |
||
|
|
||
| intercept[NoSuchDatabaseException] { | ||
| sql("USE not_existing_db") | ||
| } | ||
|
|
||
| sql(s"USE $currentDatabase") | ||
| assert(currentDatabase == sql("select current_database()").first().getString(0)) | ||
| } | ||
|
|
||
| test("lookup hive UDF in another thread") { | ||
| val e = intercept[AnalysisException] { | ||
| range(1).selectExpr("not_a_udf()") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Why create a dummy implementation here? This is not consistent with the way Catalog is currently written. The other option creates more overhead though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not all catalog support database concept. So, inherited catalog can choose to implement it or not. If we don't provide a dummy implementation here, all catalogs need to implement it even it doesn't support database.