You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2015/06/17 02:11:12 UTC
spark git commit: [SPARK-8156] [SQL] create table to specific
database by 'use dbname'
Repository: spark
Updated Branches:
refs/heads/master ca998757e -> 0b8c8fdc1
[SPARK-8156] [SQL] create table to specific database by 'use dbname'
when i test the following code:
hiveContext.sql("""use testdb""")
val df = (1 to 3).map(i => (i, s"val_$i", i * 2)).toDF("a", "b", "c")
df.write
.format("parquet")
.mode(SaveMode.Overwrite)
.saveAsTable("ttt3")
hiveContext.sql("show TABLES in default")
found that the table ttt3 will be created under the database "default"
Author: baishuo <vc...@hotmail.com>
Closes #6695 from baishuo/SPARK-8516-use-database and squashes the following commits:
9e155f9 [baishuo] remove no use comment
cb9f027 [baishuo] modify testcase
00a7a2d [baishuo] modify testcase
4df48c7 [baishuo] modify testcase
b742e69 [baishuo] modify testcase
3d19ad9 [baishuo] create table to specific database
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/0b8c8fdc
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/0b8c8fdc
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/0b8c8fdc
Branch: refs/heads/master
Commit: 0b8c8fdc121deecacb309784f18470790306dc26
Parents: ca99875
Author: baishuo <vc...@hotmail.com>
Authored: Tue Jun 16 16:40:02 2015 -0700
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Tue Jun 16 16:40:02 2015 -0700
----------------------------------------------------------------------
.../org/apache/spark/sql/hive/HiveContext.scala | 6 ++----
.../spark/sql/hive/HiveMetastoreCatalog.scala | 2 +-
.../spark/sql/hive/MetastoreDataSourcesSuite.scala | 17 +++++++++++++++++
3 files changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/0b8c8fdc/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala
index 3b75b0b..c50835d 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveContext.scala
@@ -271,13 +271,11 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) {
* @since 1.3.0
*/
def refreshTable(tableName: String): Unit = {
- // TODO: Database support...
- catalog.refreshTable("default", tableName)
+ catalog.refreshTable(catalog.client.currentDatabase, tableName)
}
protected[hive] def invalidateTable(tableName: String): Unit = {
- // TODO: Database support...
- catalog.invalidateTable("default", tableName)
+ catalog.invalidateTable(catalog.client.currentDatabase, tableName)
}
/**
http://git-wip-us.apache.org/repos/asf/spark/blob/0b8c8fdc/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
index 619ef63..f35ae96 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
@@ -143,7 +143,7 @@ private[hive] class HiveMetastoreCatalog(val client: ClientInterface, hive: Hive
provider: String,
options: Map[String, String],
isExternal: Boolean): Unit = {
- val (dbName, tblName) = processDatabaseAndTableName("default", tableName)
+ val (dbName, tblName) = processDatabaseAndTableName(client.currentDatabase, tableName)
val tableProperties = new scala.collection.mutable.HashMap[String, String]
tableProperties.put("spark.sql.sources.provider", provider)
http://git-wip-us.apache.org/repos/asf/spark/blob/0b8c8fdc/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
----------------------------------------------------------------------
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
index af58671..79a85b2 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/MetastoreDataSourcesSuite.scala
@@ -833,4 +833,21 @@ class MetastoreDataSourcesSuite extends QueryTest with SQLTestUtils with BeforeA
(70 to 79).map(i => Row(i, s"str$i")))
}
}
+
+ test("SPARK-8156:create table to specific database by 'use dbname' ") {
+
+ val df = (1 to 3).map(i => (i, s"val_$i", i * 2)).toDF("a", "b", "c")
+ sqlContext.sql("""create database if not exists testdb8156""")
+ sqlContext.sql("""use testdb8156""")
+ df.write
+ .format("parquet")
+ .mode(SaveMode.Overwrite)
+ .saveAsTable("ttt3")
+
+ checkAnswer(
+ sqlContext.sql("show TABLES in testdb8156").filter("tableName = 'ttt3'"),
+ Row("ttt3", false))
+ sqlContext.sql("""use default""")
+ sqlContext.sql("""drop database if exists testdb8156 CASCADE""")
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org