Skip to content

Commit 6b32886

Browse files
committed
revert some changes
1 parent 75935a8 commit 6b32886

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,13 +1251,15 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
12511251
CatalogColumn(ic.identifier.getText, null, nullable = true, Option(ic.STRING).map(string))
12521252
}
12531253

1254+
val sql = Option(source(ctx.query))
12541255
val tableDesc = CatalogTable(
12551256
identifier = visitTableIdentifier(ctx.tableIdentifier),
12561257
tableType = CatalogTableType.VIEW,
12571258
schema = schema,
12581259
storage = CatalogStorageFormat.empty,
12591260
properties = Option(ctx.tablePropertyList).map(visitPropertyKeyValues).getOrElse(Map.empty),
1260-
viewOriginalText = Option(source(ctx.query)),
1261+
viewOriginalText = sql,
1262+
viewText = sql,
12611263
comment = Option(ctx.STRING).map(string))
12621264

12631265
CreateViewCommand(

sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project}
2828

2929

3030
/**
31-
* Create or replace a view with given query plan. This command will convert the query plan to
32-
* canonicalized SQL string, and store it as view text in metastore, if we need to create a
33-
* permanent view.
31+
* Create Hive view on non-hive-compatible tables by specifying schema ourselves instead of
32+
* depending on Hive meta-store.
3433
*
3534
* @param tableDesc the catalog table
3635
* @param child the logical plan that represents the view; this is used to generate a canonicalized
@@ -60,8 +59,8 @@ case class CreateViewCommand(
6059
require(tableDesc.tableType == CatalogTableType.VIEW,
6160
"The type of the table to created with CREATE VIEW must be 'CatalogTableType.VIEW'.")
6261
if (!isTemporary) {
63-
require(tableDesc.viewOriginalText.isDefined,
64-
"The table to created with CREATE VIEW must have 'viewOriginalText'.")
62+
require(tableDesc.viewText.isDefined,
63+
"The table to created with CREATE VIEW must have 'viewText'.")
6564
}
6665

6766
if (allowExisting && replace) {
@@ -179,8 +178,9 @@ case class CreateViewCommand(
179178
}
180179
}
181180

181+
val viewText = tableDesc.viewText.get
182182
val viewName = quote(tableDesc.identifier.table)
183-
s"SELECT $viewOutput FROM (${tableDesc.viewOriginalText.get}) $viewName"
183+
s"SELECT $viewOutput FROM ($viewText) $viewName"
184184
}
185185

186186
// Validate the view SQL - make sure we can parse it and analyze it.

0 commit comments

Comments
 (0)