Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/11048#discussion_r52622161
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkQl.scala ---
@@ -62,6 +66,458 @@ private[sql] class SparkQl(conf: ParserConf =
SimpleParserConf()) extends Cataly
val tableIdent = extractTableIdent(nameParts)
RefreshTable(tableIdent)
+ case Token("TOK_CREATEDATABASE", Token(databaseName, Nil) ::
createDatabaseArgs) =>
+ val Seq(
+ allowExisting,
+ dbLocation,
+ databaseComment,
+ dbprops) = getClauses(Seq(
+ "TOK_IFNOTEXISTS",
+ "TOK_DATABASELOCATION",
+ "TOK_DATABASECOMMENT",
+ "TOK_DATABASEPROPERTIES"), createDatabaseArgs)
+
+ val location = dbLocation.map {
+ case Token("TOK_DATABASELOCATION", Token(loc, Nil) :: Nil) =>
unquoteString(loc)
+ }
+ val comment = databaseComment.map {
+ case Token("TOK_DATABASECOMMENT", Token(comment, Nil) :: Nil) =>
unquoteString(comment)
+ }
+ val props: Map[String, String] = dbprops.toSeq.flatMap {
+ case Token("TOK_DATABASEPROPERTIES", propList) =>
+ propList.flatMap {
+ case Token("TOK_DBPROPLIST", props) =>
+ props.map {
+ case Token("TOK_TABLEPROPERTY", keysAndValue) =>
+ val key = keysAndValue.init.map(x =>
unquoteString(x.text)).mkString(".")
+ val value = unquoteString(keysAndValue.last.text)
+ (key, value)
+ }
+ }
+ }.toMap
+
+ CreateDataBase(databaseName, allowExisting.isDefined, location,
comment, props)(node.source)
+
+ case Token("TOK_CREATEFUNCTION", func :: as :: createFuncArgs) =>
+ val funcName = func.map(x => unquoteString(x.text)).mkString(".")
+ val asName = unquoteString(as.text)
+ val Seq(
+ rList,
+ temp) = getClauses(Seq(
+ "TOK_RESOURCE_LIST",
+ "TOK_TEMPORARY"), createFuncArgs)
+
+ val resourcesMap: Map[String, String] = rList.toSeq.flatMap {
+ case Token("TOK_RESOURCE_LIST", resources) =>
+ resources.map {
+ case Token("TOK_RESOURCE_URI", rType :: Token(rPath, Nil) ::
Nil) =>
+ val resourceType = rType match {
+ case Token("TOK_JAR", Nil) => "jar"
+ case Token("TOK_FILE", Nil) => "file"
+ case Token("TOK_ARCHIVE", Nil) => "archive"
+ }
+ (resourceType, unquoteString(rPath))
+ }
+ }.toMap
+ CreateFunction(funcName, asName, resourcesMap,
temp.isDefined)(node.source)
+
+ case Token("TOK_ALTERTABLE", alterTableArgs) =>
--- End diff --
There is not one single `ALTER TABLE` command, there are many (stopped
counting at 20). The parser gives us pretty good trees to match on. For
instance: `ALTER TABLE table_name UNSET TBLPROPERTIES ('comment', 'test')`
gives us:
TOK_ALTERTABLE 1, 0, 15, 12
:- TOK_TABNAME 1, 4, 4, 12
: +- table_name 1, 4, 4, 12
+- TOK_ALTERTABLE_DROPPROPERTIES 1, 6, 15, 44
+- TOK_TABLEPROPERTIES 1, 10, 15, 44
+- TOK_TABLEPROPLIST 1, 11, 14, 44
:- TOK_TABLEPROPERTY 1, 11, 11, 44
: :- 'comment' 1, 11, 11, 44
: +- TOK_NULL 0, -1, -1, 0
+- TOK_TABLEPROPERTY 1, 14, 14, 55
:- 'test' 1, 14, 14, 55
+- TOK_NULL 0, -1, -1, 0
Lets split this code by matching on the `TOK_ALTERTABLE_*` tokens. The
result should be alot easier to understand.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]