You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by hv...@apache.org on 2016/02/11 21:21:22 UTC

spark git commit: [SPARK-12982][SQL] Add table name validation in temp table registration

Repository: spark
Updated Branches:
  refs/heads/master e31c80737 -> 0d50a2208


[SPARK-12982][SQL] Add table name validation in temp table registration

Add the table name validation at the temp table creation

Author: jayadevanmurali <ja...@tcs.com>

Closes #11051 from jayadevanmurali/branch-0.2-SPARK-12982.


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

Branch: refs/heads/master
Commit: 0d50a22084eea91d4efb0a3ed3fa59b8d9680795
Parents: e31c807
Author: jayadevanmurali <ja...@tcs.com>
Authored: Thu Feb 11 21:21:03 2016 +0100
Committer: Herman van Hovell <hv...@questtec.nl>
Committed: Thu Feb 11 21:21:03 2016 +0100

----------------------------------------------------------------------
 .../main/scala/org/apache/spark/sql/SQLContext.scala    |  2 +-
 .../scala/org/apache/spark/sql/DataFrameSuite.scala     | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/0d50a220/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala b/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
index 050a103..d58b996 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/SQLContext.scala
@@ -720,7 +720,7 @@ class SQLContext private[sql](
    * only during the lifetime of this instance of SQLContext.
    */
   private[sql] def registerDataFrameAsTable(df: DataFrame, tableName: String): Unit = {
-    catalog.registerTable(TableIdentifier(tableName), df.logicalPlan)
+    catalog.registerTable(sqlParser.parseTableIdentifier(tableName), df.logicalPlan)
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/spark/blob/0d50a220/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
index 3ea4adc..99ba2e2 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
@@ -1305,4 +1305,16 @@ class DataFrameSuite extends QueryTest with SharedSQLContext {
       Seq(1 -> "a").toDF("i", "j").filter($"i".cast(StringType) === "1"),
       Row(1, "a"))
   }
+
+  test("SPARK-12982: Add table name validation in temp table registration") {
+    val df = Seq("foo", "bar").map(Tuple1.apply).toDF("col")
+    // invalid table name test as below
+    intercept[AnalysisException](df.registerTempTable("t~"))
+    // valid table name test as below
+    df.registerTempTable("table1")
+    // another invalid table name test as below
+    intercept[AnalysisException](df.registerTempTable("#$@sum"))
+    // another invalid table name test as below
+    intercept[AnalysisException](df.registerTempTable("table!#"))
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org