Skip to content

Conversation

@gatorsmile
Copy link
Member

What changes were proposed in this pull request?

In the current master branch, when users do not specify the database name in the ALTER VIEW AS SELECT command, we always try to alter the permanent view even if the temporary view exists. This PR is to resolve this issue.

After the fix, ALTER VIEW AS SELECT command alters the temporary view if the temp view exists; otherwise, try to alter the permanent view. This order is consistent with another command DROP VIEW, since users are unable to specify the keyword TEMPORARY.

How was this patch tested?

Added test cases.

@SparkQA
Copy link

SparkQA commented Aug 22, 2016

Test build #64182 has finished for PR 14746 at commit db45b4c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

cc @cloud-fan @yhuai

withView("testView", "default.testView") {
val catalog = spark.sessionState.catalog
val oldViewQuery = "SELECT id FROM jt"
val newViewQuery = "SELECT id, id1 FROM jt"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove extra spaces

@SparkQA
Copy link

SparkQA commented Aug 25, 2016

Test build #64396 has finished for PR 14746 at commit c5add2c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

// 1) CREATE VIEW: create a temp view when users explicitly specify the keyword TEMPORARY;
// otherwise, create a permanent view no matter whether the temporary view
// with the same name exists or not.
// 2) ALTER VIEW: alter the temporary view if the temp view exists; otherwise, try to alter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: how can you tell whether it's CREATE VIEW or ALTER VIEW?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! The only way is to pass a flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it already has 3 flags: allowExisting, replace, isTemporary. We should rethink about it and decide what flags we really need for this command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, let me think about it. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      CREATE (OR REPLACE)? TEMPORARY? VIEW (IF NOT EXISTS)? tableIdentifier
        identifierCommentList? (COMMENT STRING)?
        (PARTITIONED ON identifierList)?
        (TBLPROPERTIES tablePropertyList)? AS query

Each flag corresponds to a keyword in the CREATE VIEW DDL command.

  • OR REPLACE -> replace
  • TEMPORARY -> isTemporary
  • IF NOT EXISTS -> allowExisting

If we want to use the same command CreateViewCommand to process both CREATE VIEW and ALTER VIEW, it sounds reasonable to add a new flag. So far, I have not found a way to combine them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like CreateMode, can we use SaveMode for replace and allowExisting?

Copy link
Member Author

@gatorsmile gatorsmile Aug 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh, I got it. : ) Copied what @liancheng wrote one month ago and did the update in the last case.

allowExisting replace SaveMode
true false Ignore
false false ErrorIfExists
false true Overwrite
true true AnalysisException

Let me try it. Thanks!

@SparkQA
Copy link

SparkQA commented Aug 26, 2016

Test build #64458 has finished for PR 14746 at commit 51dbf72.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

replace: Boolean,
isTemporary: Boolean): LogicalPlan = {
isTemporary: Boolean,
isAlterViewAsSelect: Boolean): LogicalPlan = {
Copy link
Contributor

@cloud-fan cloud-fan Aug 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about a viewType parameter which is an enum?

public enum ViewType {
  Temporary,
  Permanent,
  Any
}

We are going to add global temp view soon, so this enum will also be useful at that time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do it. Thanks!

@SparkQA
Copy link

SparkQA commented Aug 27, 2016

Test build #64526 has finished for PR 14746 at commit d84db62.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Aug 28, 2016

Test build #64547 has finished for PR 14746 at commit 47fdf1f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Aug 28, 2016

Test build #64549 has finished for PR 14746 at commit 5606344.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

/**
* ViewType is used to specify the type of views.
*/
public enum ViewType {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be public to end users, we can put it in view.scala and use sealed trait to implement it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you want me to use public enum. Let me change it now. Thanks!

@SparkQA
Copy link

SparkQA commented Aug 29, 2016

Test build #64588 has finished for PR 14746 at commit baa8a1f.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@gatorsmile
Copy link
Member Author

retest this please

@SparkQA
Copy link

SparkQA commented Aug 29, 2016

Test build #64603 has finished for PR 14746 at commit baa8a1f.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@cloud-fan
Copy link
Contributor

after thinking about it more, I think it's better to use a different code path for ALTER VIEW, instead of sharing the same implementation of CREATE VIEW. Do you mind review #14874? thanks!

@gatorsmile
Copy link
Member Author

Yeah, I am also fine about splitting them into two commands. Let me close it now.

@gatorsmile gatorsmile closed this Aug 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants