linhongliu-db commented on pull request #31550:
URL: https://github.com/apache/spark/pull/31550#issuecomment-781438177


   take a look at "why temp view refers temp view in CTE is working without 
this PR".
   It's because we do `ResolveTempViews` both in `ResolveRelations` and 
`ResolveTables`.  In this case, `ResolveRelations` try to resolve `temp_view` 
as `default.temp_view` since it's not in the referred list (caused by this cte 
bug). But in `ResolveTables`, it just try to resolve all `UnreolvedRelation`s 
as a temporary view, so in this case, it succeeds (by mistake).
   
   Here is an example to explain:
   ```sql
   use default;
   create table same_name as select 100 as a;
   create temp view test_view as select * from same_name;
   select * from test_view; -- output 100
   create temp view same_name as select 99 as a; -- a temp view has the same 
name with the table
   select * from test_view; -- output 100, expected, temp view should not 
override table
   drop table default.same_name; -- drop the table
   select * from test_view; -- output 99, wrong result, we expect table not 
found because we dropped it
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to