You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by cloud-fan <gi...@git.apache.org> on 2016/08/30 09:38:07 UTC
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewC...
GitHub user cloud-fan opened a pull request:
https://github.com/apache/spark/pull/14874
[SPARK-17180][SPARK-17309][SQL] create AlterViewCommand to handle ALTER VIEW
## What changes were proposed in this pull request?
Currently we use `CreateViewCommand` to implement ALTER VIEW, which has 2 bugs:
1. SPARK-17180: ALTER VIEW should alter temp view if view name has no database part and temp view exists
2. SPARK-17309: ALTER VIEW should issue exception if view does not exist.
The root cause is, ALTER VIEW is quite different from CREATE VIEW, we need different code path to handle them. However, in `CreateViewCommand`, there is no way to distinguish ALTER VIEW and CREATE VIEW, we have to introduce extra flag. But instead of doing this, I think a more natural way is to separate the ALTER VIEW logic into a new command.
## How was this patch tested?
new tests in SQLViewSuite
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cloud-fan/spark minor4
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/14874.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #14874
----
commit 69e6cd4a2a6058dbfe9ac8e1b54c80f09cbb3c4b
Author: Wenchen Fan <we...@databricks.com>
Date: 2016-08-30T09:20:12Z
create AlterViewCommand to handle ALTER VIEW
----
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64689/
Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] crea...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76932176
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala ---
@@ -274,6 +276,75 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
}
}
+ test("should not allow ALTER VIEW AS when the view does not exist") {
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW testView AS SELECT 1, 2")
+ )
+
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW default.testView AS SELECT 1, 2")
+ )
+ }
+
+ test("ALTER VIEW AS should try to alter temp view first if view name has no database part") {
+ withTempView("test_view") {
+ withView("test_view") {
--- End diff --
The same here. We just need to change the ordering:
```
withView("test_view") {
withTempView("test_view") {
```
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewC...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76842003
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala ---
@@ -202,3 +196,67 @@ case class CreateViewCommand(
)
}
}
+
+/**
+ * Alter a view with given query plan. If the view name contains database prefix, this command will
+ * alter a permanent view matching the given name, or throw an exception if view not exist. Else,
+ * this command will try to alter a temporary view first, if view not exist, try permanent view
+ * next, if still not exist, throw an exception.
+ *
+ * @param name the name of this view.
+ * @param originalText the original SQL text of this view. Note that we can only alter a view by
+ * SQL API, which means we always have originalText.
+ * @param query the logical plan that represents the view; this is used to generate a canonicalized
+ * version of the SQL that can be saved in the catalog.
+ */
+case class AlterViewCommand(
+ name: TableIdentifier,
+ originalText: String,
+ query: LogicalPlan) extends RunnableCommand {
+
+ override protected def innerChildren: Seq[QueryPlan[_]] = Seq(query)
+
+ override def run(session: SparkSession): Seq[Row] = {
+ // If the plan cannot be analyzed, throw an exception and don't proceed.
+ val qe = session.sessionState.executePlan(query)
+ qe.assertAnalyzed()
+ val analyzedPlan = qe.analyzed
+
+ val tableMeta = session.sessionState.catalog.getTableMetadata(name)
+ if (tableMeta.tableType != CatalogTableType.VIEW) {
+ throw new AnalysisException(s"${tableMeta.identifier} is not a view.")
+ }
+
+ if (name.database.isDefined) {
+ alterPermanentView(session, analyzedPlan)
+ } else if (session.sessionState.catalog.isTemporaryTable(name)) {
+ session.sessionState.catalog.createTempView(name.table, analyzedPlan, overrideIfExists = true)
+ } else {
+ alterPermanentView(session, analyzedPlan)
+ }
+
+ Seq.empty[Row]
+ }
+
+ private def alterPermanentView(session: SparkSession, analyzedPlan: LogicalPlan): Unit = {
+ val viewSQL: String = new SQLBuilder(analyzedPlan).toSQL
+ // Validate the view SQL - make sure we can parse it and analyze it.
+ // If we cannot analyze the generated query, there is probably a bug in SQL generation.
+ try {
+ session.sql(viewSQL).queryExecution.assertAnalyzed()
+ } catch {
+ case NonFatal(e) =>
+ throw new RuntimeException(s"Failed to analyze the canonicalized SQL: $viewSQL", e)
+ }
+
+ val viewTableMeta = CatalogTable(
+ identifier = name,
+ tableType = CatalogTableType.VIEW,
+ storage = CatalogStorageFormat.empty,
+ schema = analyzedPlan.schema,
+ viewOriginalText = Some(originalText),
+ viewText = Some(viewSQL))
--- End diff --
Since we are doing the alter view, we should not lose the existing fields, e.g., comment and table properties.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewCommand ...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64645 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64645/consoleFull)** for PR 14874 at commit [`69e6cd4`](https://github.com/apache/spark/commit/69e6cd4a2a6058dbfe9ac8e1b54c80f09cbb3c4b).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds the following public classes _(experimental)_:
* `case class AlterViewCommand(`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewCommand ...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64645/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewCommand ...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewCommand ...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14874
This is another bug in the existing `ALTER VIEW`. Let me show what I got in Hive:
```SQL
hive> create view t1_view comment 'test_comment' TBLPROPERTIES ('p1'='v1') as select * from t1;
```
```
hive> describe formatted t1_view;
OK
# col_name data_type comment
col int
# Detailed Table Information
Database: default
Owner: root
CreateTime: Tue Aug 30 13:32:41 EDT 2016
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Table Type: VIRTUAL_VIEW
Table Parameters:
comment test_comment
p1 v1
transient_lastDdlTime 1472578361
# Storage Information
SerDe Library: null
InputFormat: org.apache.hadoop.mapred.SequenceFileInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
# View Information
View Original Text: select * from t1
View Expanded Text: select `t1`.`col` from `default`.`t1`
Time taken: 0.074 seconds, Fetched: 29 row(s)
```
```SQL
hive> alter view t1_view as select col from t1;
```
```
hive> describe formatted t1_view;
OK
# col_name data_type comment
col int
# Detailed Table Information
Database: default
Owner: root
CreateTime: Tue Aug 30 13:32:41 EDT 2016
LastAccessTime: UNKNOWN
Protect Mode: None
Retention: 0
Table Type: VIRTUAL_VIEW
Table Parameters:
comment test_comment
p1 v1
transient_lastDdlTime 1472578421
# Storage Information
SerDe Library: null
InputFormat: org.apache.hadoop.mapred.SequenceFileInputFormat
OutputFormat: org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat
Compressed: No
Num Buckets: -1
Bucket Columns: []
Sort Columns: []
# View Information
View Original Text: select col from t1
View Expanded Text: select `t1`.`col` from `default`.`t1`
Time taken: 0.065 seconds, Fetched: 29 row(s)
```
After `ALTER VIEW`, we need to keep the existing table properties and comment.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64690 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64690/consoleFull)** for PR 14874 at commit [`51726ff`](https://github.com/apache/spark/commit/51726ff82fa818717f9ec52b89ca17a62ca8bb14).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Merged build finished. Test FAILed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64690 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64690/consoleFull)** for PR 14874 at commit [`51726ff`](https://github.com/apache/spark/commit/51726ff82fa818717f9ec52b89ca17a62ca8bb14).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds the following public classes _(experimental)_:
* `case class AlterViewAsCommand(`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewC...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76835022
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
@@ -1269,19 +1269,13 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
}
/**
- * Alter the query of a view. This creates a [[CreateViewCommand]] command.
+ * Alter the query of a view. This creates a [[AlterViewCommand]] command.
--- End diff --
Could you also add DDL statements like what we did for `CREATE VIEW`?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] crea...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76931872
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala ---
@@ -274,6 +276,75 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
}
}
+ test("should not allow ALTER VIEW AS when the view does not exist") {
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW testView AS SELECT 1, 2")
+ )
+
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW default.testView AS SELECT 1, 2")
+ )
+ }
+
+ test("ALTER VIEW AS should try to alter temp view first if view name has no database part") {
+ withTempView("test_view") {
+ withView("test_view") {
+ sql("CREATE VIEW test_view AS SELECT 1 AS a, 2 AS b")
+ sql("CREATE TEMP VIEW test_view AS SELECT 1 AS a, 2 AS b")
+
+ sql("ALTER VIEW test_view AS SELECT 3 AS i, 4 AS j")
+
+ // The temporary view should be updated.
+ checkAnswer(spark.table("test_view"), Row(3, 4))
+
+ // The permanent view should stay same.
+ checkAnswer(spark.table("default.test_view"), Row(1, 2))
+ }
+ }
+ }
+
+ test("ALTER VIEW AS should alter permanent view if view name has database part") {
+ withTempView("test_view") {
+ withView("test_view") {
+ sql("CREATE VIEW test_view AS SELECT 1 AS a, 2 AS b")
+ sql("CREATE TEMP VIEW test_view AS SELECT 1 AS a, 2 AS b")
+
+ sql("ALTER VIEW default.test_view AS SELECT 3 AS i, 4 AS j")
+
+ // The temporary view should stay same.
+ checkAnswer(spark.table("test_view"), Row(1, 2))
+
+ // The permanent view should be updated.
+ checkAnswer(spark.table("default.test_view"), Row(3, 4))
+ }
+ }
+ }
+
+ test("ALTER VIEW AS should keep the previous table properties, comment, create_time, etc.") {
+ withTempView("test_view") {
--- End diff --
`test_view` is not a temporary view, right?
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14874
@gatorsmile good catch! I have fixed it, thanks!
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64703/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewC...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76836901
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala ---
@@ -202,3 +196,67 @@ case class CreateViewCommand(
)
}
}
+
+/**
+ * Alter a view with given query plan. If the view name contains database prefix, this command will
+ * alter a permanent view matching the given name, or throw an exception if view not exist. Else,
+ * this command will try to alter a temporary view first, if view not exist, try permanent view
+ * next, if still not exist, throw an exception.
+ *
+ * @param name the name of this view.
+ * @param originalText the original SQL text of this view. Note that we can only alter a view by
+ * SQL API, which means we always have originalText.
+ * @param query the logical plan that represents the view; this is used to generate a canonicalized
+ * version of the SQL that can be saved in the catalog.
+ */
+case class AlterViewCommand(
+ name: TableIdentifier,
+ originalText: String,
+ query: LogicalPlan) extends RunnableCommand {
+
+ override protected def innerChildren: Seq[QueryPlan[_]] = Seq(query)
+
+ override def run(session: SparkSession): Seq[Row] = {
+ // If the plan cannot be analyzed, throw an exception and don't proceed.
+ val qe = session.sessionState.executePlan(query)
+ qe.assertAnalyzed()
+ val analyzedPlan = qe.analyzed
+
+ val tableMeta = session.sessionState.catalog.getTableMetadata(name)
+ if (tableMeta.tableType != CatalogTableType.VIEW) {
+ throw new AnalysisException(s"${tableMeta.identifier} is not a view.")
+ }
+
+ if (name.database.isDefined) {
+ alterPermanentView(session, analyzedPlan)
+ } else if (session.sessionState.catalog.isTemporaryTable(name)) {
--- End diff --
It can be simplified to
```
if (session.sessionState.catalog.isTemporaryTable(name)) {
session.sessionState.catalog.createTempView(name.table, analyzedPlan, overrideIfExists = true)
} else {
alterPermanentView(session, analyzedPlan)
}
```
I am fine if you keep the existing way.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64703 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64703/consoleFull)** for PR 14874 at commit [`8480945`](https://github.com/apache/spark/commit/8480945f2cc30972f33f1c55100c4263b83a3497).
* This patch passes all tests.
* This patch merges cleanly.
* This patch adds no public classes.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64703 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64703/consoleFull)** for PR 14874 at commit [`8480945`](https://github.com/apache/spark/commit/8480945f2cc30972f33f1c55100c4263b83a3497).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/64690/
Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:
https://github.com/apache/spark/pull/14874
LGTM except one minor comment.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] crea...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/spark/pull/14874
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:
https://github.com/apache/spark/pull/14874
Merged build finished. Test PASSed.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] crea...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76932113
--- Diff: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala ---
@@ -274,6 +276,75 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
}
}
+ test("should not allow ALTER VIEW AS when the view does not exist") {
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW testView AS SELECT 1, 2")
+ )
+
+ intercept[NoSuchTableException](
+ sql("ALTER VIEW default.testView AS SELECT 1, 2")
+ )
+ }
+
+ test("ALTER VIEW AS should try to alter temp view first if view name has no database part") {
+ withTempView("test_view") {
+ withView("test_view") {
+ sql("CREATE VIEW test_view AS SELECT 1 AS a, 2 AS b")
+ sql("CREATE TEMP VIEW test_view AS SELECT 1 AS a, 2 AS b")
+
+ sql("ALTER VIEW test_view AS SELECT 3 AS i, 4 AS j")
+
+ // The temporary view should be updated.
+ checkAnswer(spark.table("test_view"), Row(3, 4))
+
+ // The permanent view should stay same.
+ checkAnswer(spark.table("default.test_view"), Row(1, 2))
+ }
+ }
+ }
+
+ test("ALTER VIEW AS should alter permanent view if view name has database part") {
+ withTempView("test_view") {
+ withView("test_view") {
--- End diff --
Based on my understanding, this will drop the temporary view because the resolution preference of `drop view` and then `withTempView` is unable to find any temporary view.
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SPARK-17323][SQL] create Alte...
Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:
https://github.com/apache/spark/pull/14874
thanks for the review, merging to master!
I'll send a new PR for 2.0
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark pull request #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewC...
Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/14874#discussion_r76834884
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala ---
@@ -1269,19 +1269,13 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
}
/**
- * Alter the query of a view. This creates a [[CreateViewCommand]] command.
+ * Alter the query of a view. This creates a [[AlterViewCommand]] command.
*/
override def visitAlterViewQuery(ctx: AlterViewQueryContext): LogicalPlan = withOrigin(ctx) {
- createView(
--- End diff --
Now, we can remove this function `createView`. It is only being used by `visitCreateView`. We just need to directly create a `CreateViewCommand` in `visitCreateView`
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] spark issue #14874: [SPARK-17180][SPARK-17309][SQL] create AlterViewCommand ...
Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:
https://github.com/apache/spark/pull/14874
**[Test build #64645 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/64645/consoleFull)** for PR 14874 at commit [`69e6cd4`](https://github.com/apache/spark/commit/69e6cd4a2a6058dbfe9ac8e1b54c80f09cbb3c4b).
---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org