Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11573#discussion_r55902999
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkQl.scala ---
    @@ -64,10 +83,86 @@ private[sql] class SparkQl(conf: ParserConf = 
SimpleParserConf()) extends Cataly
             val tableIdent = extractTableIdent(nameParts)
             RefreshTable(tableIdent)
     
    +      // CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT 
database_comment]
    +      // [LOCATION path] [WITH DBPROPERTIES (key1=val1, key2=val2, ...)];
    +      case Token("TOK_CREATEDATABASE", Token(databaseName, Nil) :: args) =>
    +        val Seq(ifNotExists, dbLocation, databaseComment, dbprops) = 
getClauses(Seq(
    +          "TOK_IFNOTEXISTS",
    +          "TOK_DATABASELOCATION",
    +          "TOK_DATABASECOMMENT",
    +          "TOK_DATABASEPROPERTIES"), args)
    +        val location = dbLocation.map {
    +          case Token("TOK_DATABASELOCATION", Token(loc, Nil) :: Nil) => 
unquoteString(loc)
    +          case _ => parseFailed("Invalid CREATE DATABASE command", node)
    +        }
    +        val comment = databaseComment.map {
    +          case Token("TOK_DATABASECOMMENT", Token(com, Nil) :: Nil) => 
unquoteString(com)
    +          case _ => parseFailed("Invalid CREATE DATABASE command", node)
    +        }
    +        val props = dbprops.toSeq.flatMap {
    +          case Token("TOK_DATABASEPROPERTIES", Token("TOK_DBPROPLIST", 
propList) :: Nil) =>
    +            extractProps(propList, "TOK_TABLEPROPERTY")
    +          case _ => parseFailed("Invalid CREATE DATABASE command", node)
    +        }.toMap
    +        CreateDatabase(databaseName, ifNotExists.isDefined, location, 
comment, props)(node.source)
    +
    +      // CREATE [TEMPORARY] FUNCTION [db_name.]function_name AS class_name
    +      // [USING JAR|FILE|ARCHIVE 'file_uri' [, JAR|FILE|ARCHIVE 
'file_uri'] ];
    +      case Token("TOK_CREATEFUNCTION", args) =>
    +        // Example format:
    +        //
    +        //   TOK_CREATEFUNCTION
    +        //     :- db_name
    +        //     :- func_name
    +        //     :- alias
    +        //     +- TOK_RESOURCE_LIST
    +        //        :- TOK_RESOURCE_URI
    +        //        :  :- TOK_JAR
    +        //        :  +- '/path/to/jar'
    +        //        +- TOK_RESOURCE_URI
    +        //           :- TOK_FILE
    +        //           +- 'path/to/file'
    +        val (funcNameArgs, otherArgs) = args.partition {
    +          case Token("TOK_RESOURCE_LIST", _) => false
    +          case Token("TOK_TEMPORARY", _) => false
    +          case Token(_, Nil) => true
    +          case _ => parseFailed("Invalid CREATE FUNCTION command", node)
    +        }
    +        // If database name is specified, there are 3 tokens, otherwise 2.
    +        val (funcName, alias) = funcNameArgs match {
    +          case Token(dbName, Nil) :: Token(fname, Nil) :: Token(aname, 
Nil) :: Nil =>
    +            (unquoteString(dbName) + "." + unquoteString(fname), 
unquoteString(aname))
    +          case Token(fname, Nil) :: Token(aname, Nil) :: Nil =>
    +            (unquoteString(fname), unquoteString(aname))
    +          case _ =>
    +            parseFailed("Invalid CREATE FUNCTION command", node)
    +        }
    +        // Extract other keywords, if they exist
    +        val Seq(rList, temp) = getClauses(Seq("TOK_RESOURCE_LIST", 
"TOK_TEMPORARY"), otherArgs)
    +        val resourcesMap = 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"
    +                  case Token(f, _) => parseFailed(s"Unexpected resource 
format '$f'", node)
    +                }
    +                (resourceType, unquoteString(rPath))
    +              case _ => parseFailed("Invalid CREATE FUNCTION command", 
node)
    +            }
    +          case _ => parseFailed("Invalid CREATE FUNCTION command", node)
    +        }.toMap
    +        CreateFunction(funcName, alias, resourcesMap, 
temp.isDefined)(node.source)
    --- End diff --
    
    Let's also have a test for this case.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to