-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-7163] [SQL] minor refactory for HiveQl #5715
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b40ad71
draft
scwf 5b3f9f5
remove astnode related method to HiveASTNodeUtil
scwf d7a0433
compile issue
scwf fed7b58
fix substituted
scwf 82df766
added @transient for sqlParser
scwf f76a7b1
style issue
scwf 6081494
fix conflicts
scwf 0a2d6ae
fix conflicts
scwf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveASTToken.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.hive | ||
|
|
||
| private[hive] object HiveASTToken { | ||
| protected val nativeCommands = Seq( | ||
| "TOK_ALTERDATABASE_OWNER", | ||
| "TOK_ALTERDATABASE_PROPERTIES", | ||
| "TOK_ALTERINDEX_PROPERTIES", | ||
| "TOK_ALTERINDEX_REBUILD", | ||
| "TOK_ALTERTABLE_ADDCOLS", | ||
| "TOK_ALTERTABLE_ADDPARTS", | ||
| "TOK_ALTERTABLE_ALTERPARTS", | ||
| "TOK_ALTERTABLE_ARCHIVE", | ||
| "TOK_ALTERTABLE_CLUSTER_SORT", | ||
| "TOK_ALTERTABLE_DROPPARTS", | ||
| "TOK_ALTERTABLE_PARTITION", | ||
| "TOK_ALTERTABLE_PROPERTIES", | ||
| "TOK_ALTERTABLE_RENAME", | ||
| "TOK_ALTERTABLE_RENAMECOL", | ||
| "TOK_ALTERTABLE_REPLACECOLS", | ||
| "TOK_ALTERTABLE_SKEWED", | ||
| "TOK_ALTERTABLE_TOUCH", | ||
| "TOK_ALTERTABLE_UNARCHIVE", | ||
| "TOK_ALTERVIEW_ADDPARTS", | ||
| "TOK_ALTERVIEW_AS", | ||
| "TOK_ALTERVIEW_DROPPARTS", | ||
| "TOK_ALTERVIEW_PROPERTIES", | ||
| "TOK_ALTERVIEW_RENAME", | ||
|
|
||
| "TOK_CREATEDATABASE", | ||
| "TOK_CREATEFUNCTION", | ||
| "TOK_CREATEINDEX", | ||
| "TOK_CREATEROLE", | ||
| "TOK_CREATEVIEW", | ||
|
|
||
| "TOK_DESCDATABASE", | ||
| "TOK_DESCFUNCTION", | ||
|
|
||
| "TOK_DROPDATABASE", | ||
| "TOK_DROPFUNCTION", | ||
| "TOK_DROPINDEX", | ||
| "TOK_DROPROLE", | ||
| "TOK_DROPTABLE_PROPERTIES", | ||
| "TOK_DROPVIEW", | ||
| "TOK_DROPVIEW_PROPERTIES", | ||
|
|
||
| "TOK_EXPORT", | ||
|
|
||
| "TOK_GRANT", | ||
| "TOK_GRANT_ROLE", | ||
|
|
||
| "TOK_IMPORT", | ||
|
|
||
| "TOK_LOAD", | ||
|
|
||
| "TOK_LOCKTABLE", | ||
|
|
||
| "TOK_MSCK", | ||
|
|
||
| "TOK_REVOKE", | ||
|
|
||
| "TOK_SHOW_COMPACTIONS", | ||
| "TOK_SHOW_CREATETABLE", | ||
| "TOK_SHOW_GRANT", | ||
| "TOK_SHOW_ROLE_GRANT", | ||
| "TOK_SHOW_ROLE_PRINCIPALS", | ||
| "TOK_SHOW_ROLES", | ||
| "TOK_SHOW_SET_ROLE", | ||
| "TOK_SHOW_TABLESTATUS", | ||
| "TOK_SHOW_TBLPROPERTIES", | ||
| "TOK_SHOW_TRANSACTIONS", | ||
| "TOK_SHOWCOLUMNS", | ||
| "TOK_SHOWDATABASES", | ||
| "TOK_SHOWFUNCTIONS", | ||
| "TOK_SHOWINDEXES", | ||
| "TOK_SHOWLOCKS", | ||
| "TOK_SHOWPARTITIONS", | ||
|
|
||
| "TOK_SWITCHDATABASE", | ||
|
|
||
| "TOK_UNLOCKTABLE" | ||
| ) | ||
|
|
||
| // Commands that we do not need to explain. | ||
| protected val noExplainCommands = Seq( | ||
| "TOK_DESCTABLE", | ||
| "TOK_SHOWTABLES", | ||
| "TOK_TRUNCATETABLE" // truncate table" is a NativeCommand, does not need to explain. | ||
| ) ++ nativeCommands | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,20 +81,45 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) { | |
| protected[sql] def convertCTAS: Boolean = | ||
| getConf("spark.sql.hive.convertCTAS", "false").toBoolean | ||
|
|
||
| override protected[sql] def executePlan(plan: LogicalPlan): this.QueryExecution = | ||
| new this.QueryExecution(plan) | ||
| /* A catalyst metadata catalog that points to the Hive Metastore. */ | ||
| @transient | ||
| override protected[sql] lazy val catalog = new HiveMetastoreCatalog(this) with OverrideCatalog | ||
|
|
||
| // Note that HiveUDFs will be overridden by functions registered in this context. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not need this, since if we override sqlParser, we can inherited from sqlcontext the ddlParser |
||
| @transient | ||
| protected[sql] val ddlParserWithHiveQL = new DDLParser(HiveQl.parseSql(_)) | ||
| override protected[sql] lazy val functionRegistry = | ||
| new HiveFunctionRegistry with OverrideFunctionRegistry { | ||
| def caseSensitive: Boolean = false | ||
| } | ||
|
|
||
| /* An analyzer that uses the Hive metastore. */ | ||
| @transient | ||
| override protected[sql] lazy val analyzer = | ||
| new Analyzer(catalog, functionRegistry, caseSensitive = false) { | ||
| override val extendedResolutionRules = | ||
| catalog.ParquetConversions :: | ||
| catalog.CreateTables :: | ||
| catalog.PreInsertionCasts :: | ||
| ExtractPythonUdfs :: | ||
| sources.PreInsertCastAndRename :: | ||
| Nil | ||
| } | ||
|
|
||
| override protected[sql] val sqlParser = { | ||
| val fallback = new ExtendedHiveQlParser | ||
| new SparkSQLParser(fallback.parse(_)) | ||
| } | ||
|
|
||
| override protected[sql] def executePlan(plan: LogicalPlan): this.QueryExecution = | ||
| new this.QueryExecution(plan) | ||
|
|
||
| override def sql(sqlText: String): DataFrame = { | ||
| val substituted = new VariableSubstitution().substitute(hiveconf, sqlText) | ||
| // TODO: Create a framework for registering parsers instead of just hardcoding if statements. | ||
| if (conf.dialect == "sql") { | ||
| super.sql(substituted) | ||
| } else if (conf.dialect == "hiveql") { | ||
| val ddlPlan = ddlParserWithHiveQL.parse(sqlText, exceptionOnError = false) | ||
| DataFrame(this, ddlPlan.getOrElse(HiveQl.parseSql(substituted))) | ||
| DataFrame(this, parseSql(sqlText)) | ||
| } else { | ||
| sys.error(s"Unsupported SQL dialect: ${conf.dialect}. Try 'sql' or 'hiveql'") | ||
| } | ||
|
|
@@ -229,30 +254,6 @@ class HiveContext(sc: SparkContext) extends SQLContext(sc) { | |
| runSqlHive(s"SET $key=$value") | ||
| } | ||
|
|
||
| /* A catalyst metadata catalog that points to the Hive Metastore. */ | ||
| @transient | ||
| override protected[sql] lazy val catalog = new HiveMetastoreCatalog(this) with OverrideCatalog | ||
|
|
||
| // Note that HiveUDFs will be overridden by functions registered in this context. | ||
| @transient | ||
| override protected[sql] lazy val functionRegistry = | ||
| new HiveFunctionRegistry with OverrideFunctionRegistry { | ||
| def caseSensitive: Boolean = false | ||
| } | ||
|
|
||
| /* An analyzer that uses the Hive metastore. */ | ||
| @transient | ||
| override protected[sql] lazy val analyzer = | ||
| new Analyzer(catalog, functionRegistry, caseSensitive = false) { | ||
| override val extendedResolutionRules = | ||
| catalog.ParquetConversions :: | ||
| catalog.CreateTables :: | ||
| catalog.PreInsertionCasts :: | ||
| ExtractPythonUdfs :: | ||
| sources.PreInsertCastAndRename :: | ||
| Nil | ||
| } | ||
|
|
||
| override protected[sql] def createSession(): SQLSession = { | ||
| new this.SQLSession() | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
reorder to make catalog, functionRegistry, analyzer, sqlParser togethor