Uh oh!
There was an error while loading. Please reload this page.
[SPARK-29628][SQL] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view - #26317
[SPARK-29628][SQL] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view#26317amanomer wants to merge 12 commits into
Conversation
AmplabJenkins
commented
Oct 30, 2019
Can one of the admins verify this patch? |
amanomer
commented
Oct 30, 2019
Uh oh!
There was an error while loading. Please reload this page.
| 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) { |
There was a problem hiding this comment.
nit:
name.database.foreach { database =>thrownewAnalysisException(
s"It is not allowed to add database prefix `$database` for the TEMPORARY view name.")
}There was a problem hiding this comment.
name.database returns String.
There was a problem hiding this comment.
It's not, it's an Option[String], I imagine, in which case this is indeed a little more idiomatic.
There was a problem hiding this comment.
My bad. name.database is an Option[String].
There was a problem hiding this comment.
Now, I see how foreach is working here.
Thanks @MaxGekk
amanomer
commented
Oct 30, 2019
dongjoon-hyun
commented
Oct 30, 2019
cc @maropu |
dongjoon-hyun
commented
Oct 30, 2019
Hi, @amanomer . Thank you for making a PR. FYI, for SQL PR, you need to add |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dongjoon-hyun
commented
Oct 30, 2019
cc @gatorsmile since this is a behavior change. |
Uh oh!
There was an error while loading. Please reload this page.
dongjoon-hyun
left a comment
There was a problem hiding this comment.
@amanomer . I finished my first round review. After your updating, I'll review again.
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
commented
Oct 31, 2019
cloud-fan
commented
Nov 4, 2019
This is a weird feature. Does pgsql give warning when this happens? |
maropu
commented
Nov 4, 2019
Yea, pgSQL does so: |
cloud-fan
commented
Nov 4, 2019
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
commented
Nov 4, 2019
I generally agree, unless it's important to match semantics, I don't think we should just let this work? |
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
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) { |
There was a problem hiding this comment.
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
commented
Nov 12, 2019
I have handled the review comments.Kindly check this. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| } | ||
| } | ||
| private var isTempReferred = false |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
isTempReferred A flag which will be true when permanent view is based on temporary view while using pgSQL dialect.
There was a problem hiding this comment.
Yes that's not quite my question. How do we know the code path that sets this to true below will execute first?
There was a problem hiding this comment.
In run(), before using isTempReferred, a call to verifyTemporaryObjectsNotExists() is made which will update it's value.
Uh oh!
There was an error while loading. Please reload this page.
amanomer
commented
Nov 13, 2019
cc @brkyvz |
amanomer
commented
Nov 19, 2019
cc @cloud-fan |
amanomer
commented
Nov 25, 2019
@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) { |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
We can improve the error message and suggest end users to add the keyword TEMPORARY to create a temporary view instead.
### 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 <amanomer1996@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
### 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. Closesapache#26731 from amanomer/imp_err_msg. Authored-by: Aman Omer <amanomer1996@gmail.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
amanomer
commented
Feb 10, 2020
I think, this PR is not required. |
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.