Skip to content
Snippets Groups Projects
Commit 47000745 authored by Huaxin Gao's avatar Huaxin Gao Committed by Michael Armbrust
Browse files

[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 <huaxing@oc0558782468.ibm.com>

Closes #9773 from huaxingao/spark-11778.
parent 47d1c232
No related branches found
No related tags found
No related merge requests found
...@@ -313,7 +313,8 @@ class DataFrameReader private[sql](sqlContext: SQLContext) extends Logging { ...@@ -313,7 +313,8 @@ class DataFrameReader private[sql](sqlContext: SQLContext) extends Logging {
* @since 1.4.0 * @since 1.4.0
*/ */
def table(tableName: String): DataFrame = { def table(tableName: String): DataFrame = {
DataFrame(sqlContext, sqlContext.catalog.lookupRelation(TableIdentifier(tableName))) DataFrame(sqlContext,
sqlContext.catalog.lookupRelation(SqlParser.parseTableIdentifier(tableName)))
} }
/** /**
......
...@@ -34,10 +34,14 @@ class HiveDataFrameAnalyticsSuite extends QueryTest with TestHiveSingleton with ...@@ -34,10 +34,14 @@ class HiveDataFrameAnalyticsSuite extends QueryTest with TestHiveSingleton with
override def beforeAll() { override def beforeAll() {
testData = Seq((1, 2), (2, 2), (3, 4)).toDF("a", "b") testData = Seq((1, 2), (2, 2), (3, 4)).toDF("a", "b")
hiveContext.registerDataFrameAsTable(testData, "mytable") hiveContext.registerDataFrameAsTable(testData, "mytable")
hiveContext.sql("create schema usrdb")
hiveContext.sql("create table usrdb.test(c1 int)")
} }
override def afterAll(): Unit = { override def afterAll(): Unit = {
hiveContext.dropTempTable("mytable") hiveContext.dropTempTable("mytable")
hiveContext.sql("drop table usrdb.test")
hiveContext.sql("drop schema usrdb")
} }
test("rollup") { test("rollup") {
...@@ -74,4 +78,10 @@ class HiveDataFrameAnalyticsSuite extends QueryTest with TestHiveSingleton with ...@@ -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() 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")
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment