Skip to content

Conversation

@amanomer
Copy link
Contributor

What changes were proposed in this pull request?

When creating permanent view based on temporary view, it will be created as a temporary view. Previously, Spark this was not allowed.

Why are the changes needed?

To match the behavior of postgreSQL.

Does this PR introduce any user-facing change?

No

How was this patch tested?

UT added.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@amanomer
Copy link
Contributor Author

@MaxGekk @srowen @cloud-fan

throw new AnalysisException(
s"It is not allowed to add database prefix `$database` for the TEMPORARY view name.")
// Temporary view names should NOT contain database prefix like "database.table"
if (name.database.isDefined) {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

    name.database.foreach { database =>
      throw new AnalysisException(
        s"It is not allowed to add database prefix `$database` for the TEMPORARY view name.")
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

name.database returns String.

Copy link
Member

Choose a reason for hiding this comment

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

It's not, it's an Option[String], I imagine, in which case this is indeed a little more idiomatic.

Copy link
Contributor Author

@amanomer amanomer Nov 4, 2019

Choose a reason for hiding this comment

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

My bad. name.database is an Option[String].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now, I see how foreach is working here.
Thanks @MaxGekk

@amanomer
Copy link
Contributor Author

@MaxGekk

@dongjoon-hyun
Copy link
Member

cc @maropu

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-29628] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view [SPARK-29628][SQL] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view Oct 30, 2019
@dongjoon-hyun
Copy link
Member

Hi, @amanomer . Thank you for making a PR. FYI, for SQL PR, you need to add [SQL] after JIRA ID in the PR title.

@dongjoon-hyun
Copy link
Member

cc @gatorsmile since this is a behavior change.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

@amanomer . I finished my first round review. After your updating, I'll review again.

@maropu
Copy link
Member

maropu commented Oct 31, 2019

btw, is this behaviour is common in the other DMBS-like? If no, better to add this feature in the PgSQL dialect.

@amanomer
Copy link
Contributor Author

cc @dongjoon-hyun @gengliangwang

@cloud-fan
Copy link
Contributor

This is a weird feature. Does pgsql give warning when this happens?

@maropu
Copy link
Member

maropu commented Nov 4, 2019

Yea, pgSQL does so:

-- should be created in temp object schema
CREATE VIEW v1_temp AS SELECT * FROM temp_table;
NOTICE:  view "v1_temp" will be a temporary view

https://github.com/postgres/postgres/blob/REL_12_STABLE/src/test/regress/expected/create_view.out#L86

@cloud-fan
Copy link
Contributor

If it's a feature that pgsql would warn you, I'm not sure we need to have it in Spark. This at lease should be protected by the pgsql dialect.

@srowen
Copy link
Member

srowen commented Nov 4, 2019

I generally agree, unless it's important to match semantics, I don't think we should just let this work?

@maropu
Copy link
Member

maropu commented Nov 4, 2019

I'm not sure though, if this feature is not common in the other DMBS implementations (e.g., Oracle?), I personally think it might be worth doing in the pgSQL dialect.

@amanomer
Copy link
Contributor Author

amanomer commented Nov 5, 2019

I will move this code to pgSQL dialect.

throw new AnalysisException(s"Not allowed to create a permanent view $name by " +
s"referencing a temporary view $ident")
// Temporary views are only stored in the session catalog
if (sparkSession.sqlContext.conf.usePostgreSQLDialect) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have handled pgSQLDialect case here. Since class CreateViewCommand of sql/core is not accessible from PostgreSQLDialect sql/catalyst because sql/core is dependent on sql/catalyst.

@amanomer
Copy link
Contributor Author

I have handled the review comments.Kindly check this.

}
}

private var isTempReferred = false
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure about the semantics of this. It's used in a different place from where it's checked. Is this always set to true by a code path before it needs to be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

isTempReferred A flag which will be true when permanent view is based on temporary view while using pgSQL dialect.

Copy link
Member

Choose a reason for hiding this comment

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

Yes that's not quite my question. How do we know the code path that sets this to true below will execute first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In run(), before using isTempReferred, a call to verifyTemporaryObjectsNotExists() is made which will update it's value.

@amanomer amanomer requested a review from srowen November 13, 2019 16:01
@amanomer
Copy link
Contributor Author

cc @brkyvz

@amanomer
Copy link
Contributor Author

cc @cloud-fan

@amanomer
Copy link
Contributor Author

@maropu @gengliangwang kindly review this

throw new AnalysisException(s"Not allowed to create a permanent view $name by " +
s"referencing a temporary view $ident")
// Temporary views are only stored in the session catalog
if (sparkSession.sqlContext.conf.usePostgreSQLDialect) {
Copy link
Member

Choose a reason for hiding this comment

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

We are removing this dialect as we discussed in the mailing list.

if sparkSession.sessionState.catalog.isTemporaryTable(ident) =>
// temporary views are only stored in the session catalog
throw new AnalysisException(s"Not allowed to create a permanent view $name by " +
s"referencing a temporary view $ident")
Copy link
Member

Choose a reason for hiding this comment

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

We can improve the error message and suggest end users to add the keyword TEMPORARY to create a temporary view instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR for above suggestion #26731

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gatorsmile also review #26712

cloud-fan pushed a commit that referenced this pull request Dec 5, 2019
### What changes were proposed in this pull request?
Improved error message while creating views.

### Why are the changes needed?
Error message should suggest user to use TEMPORARY keyword while creating permanent view referred by temporary view.
#26317 (comment)

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
Updated test case.

Closes #26731 from amanomer/imp_err_msg.

Authored-by: Aman Omer <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
attilapiros pushed a commit to attilapiros/spark that referenced this pull request Dec 6, 2019
### What changes were proposed in this pull request?
Improved error message while creating views.

### Why are the changes needed?
Error message should suggest user to use TEMPORARY keyword while creating permanent view referred by temporary view.
apache#26317 (comment)

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
Updated test case.

Closes apache#26731 from amanomer/imp_err_msg.

Authored-by: Aman Omer <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
@amanomer
Copy link
Contributor Author

I think, this PR is not required.

@amanomer amanomer closed this Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants