aboutsummaryrefslogtreecommitdiff
path: root/sql/hive/src/main/scala/org
diff options
context:
space:
mode:
authorgatorsmile <gatorsmile@gmail.com>2016-04-14 08:08:09 -0700
committerYin Huai <yhuai@databricks.com>2016-04-14 08:08:09 -0700
commit3cf3db17b35c98a408014e1810cb797d8415ffd3 (patch)
tree31e7f7110dedeea227a5582a5917ee5dbdffad60 /sql/hive/src/main/scala/org
parent6fc3dc8839eaed673c64ec87af6dfe24f8cebe0c (diff)
downloadspark-3cf3db17b35c98a408014e1810cb797d8415ffd3.tar.gz
spark-3cf3db17b35c98a408014e1810cb797d8415ffd3.tar.bz2
spark-3cf3db17b35c98a408014e1810cb797d8415ffd3.zip
[SPARK-14518][SQL] Support Comment in CREATE VIEW
#### What changes were proposed in this pull request? **HQL Syntax**: [Create View](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-Create/Drop/AlterView ) ```SQL CREATE VIEW [IF NOT EXISTS] [db_name.]view_name [(column_name [COMMENT column_comment], ...) ] [COMMENT view_comment] [TBLPROPERTIES (property_name = property_value, ...)] AS SELECT ...; ``` Add a support for the `[COMMENT view_comment]` clause #### How was this patch tested? Modified the existing test cases to verify the correctness. Author: gatorsmile <gatorsmile@gmail.com> Author: xiaoli <lixiao1983@gmail.com> Author: Xiao Li <xiaoli@Xiaos-MacBook-Pro.local> Closes #12288 from gatorsmile/addCommentInCreateView.
Diffstat (limited to 'sql/hive/src/main/scala/org')
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala16
1 files changed, 6 insertions, 10 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala
index b14db7fe71..8c707079a1 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala
@@ -26,18 +26,13 @@ import org.apache.hadoop.hive.ql.session.SessionState
import org.apache.hadoop.hive.serde.serdeConstants
import org.apache.hadoop.hive.serde2.`lazy`.LazySimpleSerDe
-import org.apache.spark.sql.AnalysisException
-import org.apache.spark.sql.catalyst.analysis.UnresolvedGenerator
import org.apache.spark.sql.catalyst.catalog._
-import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.parser._
import org.apache.spark.sql.catalyst.parser.SqlBaseParser._
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.SparkSqlAstBuilder
import org.apache.spark.sql.execution.command.CreateTable
-import org.apache.spark.sql.hive.{CreateTableAsSelect => CTAS, CreateViewAsSelect => CreateView}
-import org.apache.spark.sql.hive.{HiveGenericUDTF, HiveMetastoreTypes, HiveSerDe}
-import org.apache.spark.sql.hive.HiveShim.HiveFunctionWrapper
+import org.apache.spark.sql.hive.{CreateTableAsSelect => CTAS, CreateViewAsSelect => CreateView, HiveSerDe}
/**
* Concrete parser for HiveQl statements.
@@ -252,9 +247,6 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
if (ctx.identifierList != null) {
throw new ParseException(s"Operation not allowed: partitioned views", ctx)
} else {
- if (ctx.STRING != null) {
- throw new ParseException("Unsupported operation: COMMENT clause", ctx)
- }
val identifiers = Option(ctx.identifierCommentList).toSeq.flatMap(_.identifierComment.asScala)
val schema = identifiers.map { ic =>
CatalogColumn(ic.identifier.getText, null, nullable = true, Option(ic.STRING).map(string))
@@ -262,6 +254,7 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
createView(
ctx,
ctx.tableIdentifier,
+ comment = Option(ctx.STRING).map(string),
schema,
ctx.query,
Option(ctx.tablePropertyList).map(visitTablePropertyList).getOrElse(Map.empty),
@@ -278,6 +271,7 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
createView(
ctx,
ctx.tableIdentifier,
+ comment = None,
Seq.empty,
ctx.query,
Map.empty,
@@ -291,6 +285,7 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
private def createView(
ctx: ParserRuleContext,
name: TableIdentifierContext,
+ comment: Option[String],
schema: Seq[CatalogColumn],
query: QueryContext,
properties: Map[String, String],
@@ -304,7 +299,8 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
storage = EmptyStorageFormat,
properties = properties,
viewOriginalText = sql,
- viewText = sql)
+ viewText = sql,
+ comment = comment)
CreateView(tableDesc, plan(query), allowExist, replace, command(ctx))
}