-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
[SPARK-12982][SQL] Add table name validation in temp table registration #10983
[SPARK-12982][SQL] Add table name validation in temp table registration #10983
Conversation
Add the table name validation at the temp table creation
Can one of the admins verify this patch? |
@@ -747,7 +747,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) |
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.
We have removed SqlParser
recently. Could you merge/rebase to the most recent master, and use the sqlParser
variable for this?
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.
Ok I can see the variable definition at line 211 of SqlContext.scala
@transient
protected[sql] val sqlParser = new SparkSQLParser(getSQLDialect().parse(_))
But this varable is not used anywhare.All methods use Sqlarser.parseTableIdentifier() for example @experimental
def createExternalTable(
tableName: String,
source: String,
options: Map[String, String]): DataFrame = {
val tableIdent = SqlParser.parseTableIdentifier(tableName)
val cmd =
CreateTableUsing(
tableIdent,
userSpecifiedSchema = None,
source,
temporary = false,
options,
allowExisting = false,
managedIfNoPath = false)
executePlan(cmd).toRdd
table(tableIdent)
}
And more over SparkSQLParser returns Logical plan, I need to get TableIdintefier similor to above method. So how can I use this?
@jayadevanmurali I am not sure if the problem described in the JIRA is still an issue in the current master. Could you check this? |
@hvanhovell Steps Using Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_80) scala> import org.apache.spark.sql.types.{StringType, StructField, StructType} scala> import org.apache.spark.sql.{DataFrame, Row, SQLContext} scala> import org.apache.spark.{SparkContext, SparkConf} scala> val rows = List(Row("foo"), Row("bar")); scala> val schema = StructType(Seq(StructField("col", StringType))); scala> val rdd = sc.parallelize(rows); scala> val df = sqlContext.createDataFrame(rdd, schema) scala> df.registerTempTable("t~") scala> df.sqlContext.dropTempTable("t~") t~ scala> |
You are using an older version of the master branch (last commit 25 days ago). Your version still has the Please update your master, and try again. |
Thanks @hvanhovell , Got your point. I updated my code and repeat the steps. I was able to replicate this. Please check the steps jayadevan@Satellite-L640:~/spark$ ./bin/spark-shell Using Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_80) scala> import org.apache.spark.sql.types.{StringType, StructField, StructType} scala> import org.apache.spark.sql.{DataFrame, Row, SQLContext} scala> import org.apache.spark.{SparkContext, SparkConf} scala> val rows = List(Row("foo"), Row("bar")); scala> val schema = StructType(Seq(StructField("col", StringType))); scala> val rdd = sc.parallelize(rows); scala> val df = sqlContext.createDataFrame(rdd, schema) scala> df.registerTempTable("t~") scala> df.sqlContext.dropTempTable("t~") So I will close this pull request and raise a new one. |
@jayadevanmurali please don't close the PR, your fix is valid. We really shouldn't use table names like |
Thanks @hvanhovell, Working on test case |
@jayadevanmurali could you add the test to |
@hvanhovell yes sure, no problem |
@hvanhovell the current pull request is based on an outdated code. So I would like to create a new pull request on the latest code. Hope that is fine |
Sure it is. Why not just merge the current master? |
Revert my changes.
@hvanhovell, Yea I tried to merge my branch (https://github.com/jayadevanmurali/spark/tree/branch-0.1-SPARK-SPARK-12982) with apache spark master. But I cant see any option to merge by "create pull request". That's why I suggest new PR option. |
@hvanhovell I have created a new PR for this issue with latest code. #11051. Could you please review the same. |
@jayadevanmurali could you close this one? |
Created new pr with latest code for this issue |
Add the table name validation at the temp table creation