-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-29630][SQL] Disallow creating a permanent view that references a temporary view in an expression #26361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
cc: @cloud-fan |
|
Test build #113102 has finished for PR 26361 at commit
|
|
Test build #113110 has finished for PR 26361 at commit
|
sql/core/src/test/resources/sql-tests/inputs/postgreSQL/create_view.sql
Outdated
Show resolved
Hide resolved
| -- [SPARK-29628] Forcibly create a temporary view in CREATE VIEW if referencing a temporary view | ||
| CREATE VIEW v6_temp AS SELECT * FROM base_table WHERE id IN (SELECT id FROM temp_table); | ||
| CREATE VIEW v7_temp AS SELECT t1.id, t2.a FROM base_table t1, (SELECT * FROM temp_table) t2; | ||
| -- [SPARK-29630] Not allowed to create a permanent view by referencing a temporary view in EXISTS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't SPARK-29630 the JIRA ticket for this PR? Why it was there before this?
sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala
Outdated
Show resolved
Hide resolved
sql/core/src/main/scala/org/apache/spark/sql/execution/command/views.scala
Show resolved
Hide resolved
|
Test build #113121 has finished for PR 26361 at commit
|
|
retest this please |
|
Test build #113131 has finished for PR 26361 at commit
|
|
retest this please |
|
Test build #113136 has finished for PR 26361 at commit
|
|
retest this please |
sql/core/src/test/resources/sql-tests/results/postgreSQL/create_view.sql.out
Outdated
Show resolved
Hide resolved
|
Test build #113143 has finished for PR 26361 at commit
|
| CREATE TABLE tbl2 (c int, d int) using parquet; | ||
| CREATE TABLE tbl3 (e int, f int) using parquet; | ||
| CREATE TABLE tbl4 (g int, h int) using parquet; | ||
| -- Since Spark doesn't support CREATE TEMPORARY TABLE, we used CREATE TEMPORARY VIEW instead |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we update this comment? Now we use table as temp table in this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, fixed.
| "CREATE VIEW v AS SELECT * FROM base_table WHERE EXISTS (SELECT * FROM temp_view)", | ||
| "CREATE VIEW v AS SELECT id, (SELECT count(*) FROM temp_view) FROM base_table", | ||
| "CREATE VIEW v AS SELECT * FROM base_table " + | ||
| "WHERE id IN (SELECT id FROM base_table WHERE EXISTS (SELECT 1 FROM temp_view))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move them to create_view.sql? That's a better place for end-to-end tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved these to create_view.sql. The first two scenarios were already there, so I just moved the last one. thanks for the feedback.
|
Test build #113190 has finished for PR 26361 at commit
|
|
Test build #113213 has finished for PR 26361 at commit
|
|
thanks, merging to master! |
| -- !query 71 output | ||
|
|
||
| org.apache.spark.sql.AnalysisException | ||
| Not allowed to create a permanent view `temporal5` by referencing a temporary view `tt`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also provide the workaround in the error message. Instead just telling the users temp views are not allowed, we can say users can use permanent views in these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add something like Create a temporary view to reference temporary views; a permanent view can only reference permanent views, but sounds a bit redundant with the error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Permanent views can also reference to tables.
There exists a general issue in our existing error messages. We do not have a message reference book. When users hit the unclear error messages, what they can do is to read the source code or try different options until it works. This is not natural to end users who have zero background about Spark SQL. We need to correct them one by one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. I will do a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is the existing error message. This PR just extends the temp view check to subqueries. Agree that we can still improve the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is already addressed by #26731.
What changes were proposed in this pull request?
Disallow creating a permanent view that references a temporary view in expressions.
Why are the changes needed?
Creating a permanent view that references a temporary view is currently disallowed. For example,
However, the following is allowed.
This PR fixes the bug where temporary views used inside expressions are not checked.
Does this PR introduce any user-facing change?
Yes. Now the following SQL query throws an exception as expected:
How was this patch tested?
Added new unit tests.