Repository: spark
Updated Branches:
  refs/heads/master 47d1c2325 -> 470007453


[SPARK-11778][SQL] parse table name before it is passed to lookupRelation

Fix a bug in DataFrameReader.table (table with schema name such as 
"db_name.table" doesn't work)
Use SqlParser.parseTableIdentifier to parse the table name before 
lookupRelation.

Author: Huaxin Gao <[email protected]>

Closes #9773 from huaxingao/spark-11778.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/47000745
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/47000745
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/47000745

Branch: refs/heads/master
Commit: 4700074530d9a398843e13f0ef514be97a237cea
Parents: 47d1c23
Author: Huaxin Gao <[email protected]>
Authored: Thu Nov 19 13:08:01 2015 -0800
Committer: Michael Armbrust <[email protected]>
Committed: Thu Nov 19 13:08:01 2015 -0800

----------------------------------------------------------------------
 .../main/scala/org/apache/spark/sql/DataFrameReader.scala |  3 ++-
 .../spark/sql/hive/HiveDataFrameAnalyticsSuite.scala      | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/47000745/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala 
b/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
index 5872fbd..dcb3737 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/DataFrameReader.scala
@@ -313,7 +313,8 @@ class DataFrameReader private[sql](sqlContext: SQLContext) 
extends Logging {
    * @since 1.4.0
    */
   def table(tableName: String): DataFrame = {
-    DataFrame(sqlContext, 
sqlContext.catalog.lookupRelation(TableIdentifier(tableName)))
+    DataFrame(sqlContext,
+      
sqlContext.catalog.lookupRelation(SqlParser.parseTableIdentifier(tableName)))
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/spark/blob/47000745/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveDataFrameAnalyticsSuite.scala
----------------------------------------------------------------------
diff --git 
a/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveDataFrameAnalyticsSuite.scala
 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveDataFrameAnalyticsSuite.scala
index 9864acf..f19a74d 100644
--- 
a/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveDataFrameAnalyticsSuite.scala
+++ 
b/sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveDataFrameAnalyticsSuite.scala
@@ -34,10 +34,14 @@ class HiveDataFrameAnalyticsSuite extends QueryTest with 
TestHiveSingleton with
   override def beforeAll() {
     testData = Seq((1, 2), (2, 2), (3, 4)).toDF("a", "b")
     hiveContext.registerDataFrameAsTable(testData, "mytable")
+    hiveContext.sql("create schema usrdb")
+    hiveContext.sql("create table usrdb.test(c1 int)")
   }
 
   override def afterAll(): Unit = {
     hiveContext.dropTempTable("mytable")
+    hiveContext.sql("drop table usrdb.test")
+    hiveContext.sql("drop schema usrdb")
   }
 
   test("rollup") {
@@ -74,4 +78,10 @@ class HiveDataFrameAnalyticsSuite extends QueryTest with 
TestHiveSingleton with
       sql("select a, b, sum(b) from mytable group by a, b with cube").collect()
     )
   }
+
+  // There was a bug in DataFrameFrameReader.table and it has problem for 
table with schema name,
+  // Before fix, it throw 
Exceptionorg.apache.spark.sql.catalyst.analysis.NoSuchTableException
+  test("table name with schema") {
+    hiveContext.read.table("usrdb.test")
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to