-
Notifications
You must be signed in to change notification settings - Fork 4.8k
HIVE-28280: SemanticException when querying VIEW with DISTINCT clause #6103
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
Open
soumyakanti3578
wants to merge
4
commits into
apache:master
Choose a base branch
from
soumyakanti3578:HIVE-28280
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−8
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
ql/src/test/queries/clientpositive/view_top_relnode_not_project_authorization.q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
set hive.security.authorization.enabled=true; | ||
create table t1 (username string, id int); | ||
|
||
create view vw_t1 as select distinct username from t1 limit 5; | ||
explain cbo select * from vw_t1; | ||
select * from vw_t1; | ||
|
||
create view vw_t2 as | ||
select username from (select username, id from t1 where id > 10 limit 1) x where username > 'a' order by id; | ||
explain cbo select * from vw_t2; | ||
select * from vw_t2; | ||
|
||
create view vw_t3 as | ||
select username from (select username, id from t1 where id > 10 limit 10) x where username > 'a' limit 5; | ||
explain cbo select * from vw_t3; | ||
select * from vw_t3; |
129 changes: 129 additions & 0 deletions
129
ql/src/test/results/clientpositive/llap/view_top_relnode_not_project_authorization.q.out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
PREHOOK: query: create table t1 (username string, id int) | ||
PREHOOK: type: CREATETABLE | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@t1 | ||
POSTHOOK: query: create table t1 (username string, id int) | ||
POSTHOOK: type: CREATETABLE | ||
POSTHOOK: Output: database:default | ||
POSTHOOK: Output: default@t1 | ||
PREHOOK: query: create view vw_t1 as select distinct username from t1 limit 5 | ||
PREHOOK: type: CREATEVIEW | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@vw_t1 | ||
POSTHOOK: query: create view vw_t1 as select distinct username from t1 limit 5 | ||
POSTHOOK: type: CREATEVIEW | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Output: database:default | ||
POSTHOOK: Output: default@vw_t1 | ||
POSTHOOK: Lineage: vw_t1.username SIMPLE [(t1)t1.FieldSchema(name:username, type:string, comment:null), ] | ||
PREHOOK: query: explain cbo select * from vw_t1 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t1 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: explain cbo select * from vw_t1 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t1 | ||
#### A masked pattern was here #### | ||
CBO PLAN: | ||
HiveSortLimit(fetch=[5]) | ||
HiveProject(username=[$0]) | ||
HiveAggregate(group=[{0}]) | ||
HiveTableScan(table=[[default, t1]], table:alias=[t1]) | ||
|
||
PREHOOK: query: select * from vw_t1 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t1 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: select * from vw_t1 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t1 | ||
#### A masked pattern was here #### | ||
PREHOOK: query: create view vw_t2 as | ||
select username from (select username, id from t1 where id > 10 limit 1) x where username > 'a' order by id | ||
PREHOOK: type: CREATEVIEW | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@vw_t2 | ||
POSTHOOK: query: create view vw_t2 as | ||
select username from (select username, id from t1 where id > 10 limit 1) x where username > 'a' order by id | ||
POSTHOOK: type: CREATEVIEW | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Output: database:default | ||
POSTHOOK: Output: default@vw_t2 | ||
POSTHOOK: Lineage: vw_t2.username SIMPLE [(t1)t1.FieldSchema(name:username, type:string, comment:null), ] | ||
PREHOOK: query: explain cbo select * from vw_t2 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t2 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: explain cbo select * from vw_t2 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t2 | ||
#### A masked pattern was here #### | ||
CBO PLAN: | ||
HiveFilter(condition=[>($0, _UTF-16LE'a')]) | ||
HiveProject(username=[$0]) | ||
HiveSortLimit(fetch=[1]) | ||
HiveProject(username=[$0]) | ||
HiveFilter(condition=[>($1, 10)]) | ||
HiveTableScan(table=[[default, t1]], table:alias=[t1]) | ||
|
||
PREHOOK: query: select * from vw_t2 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t2 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: select * from vw_t2 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t2 | ||
#### A masked pattern was here #### | ||
PREHOOK: query: create view vw_t3 as | ||
select username from (select username, id from t1 where id > 10 limit 10) x where username > 'a' limit 5 | ||
PREHOOK: type: CREATEVIEW | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@vw_t3 | ||
POSTHOOK: query: create view vw_t3 as | ||
select username from (select username, id from t1 where id > 10 limit 10) x where username > 'a' limit 5 | ||
POSTHOOK: type: CREATEVIEW | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Output: database:default | ||
POSTHOOK: Output: default@vw_t3 | ||
POSTHOOK: Lineage: vw_t3.username SIMPLE [(t1)t1.FieldSchema(name:username, type:string, comment:null), ] | ||
PREHOOK: query: explain cbo select * from vw_t3 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t3 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: explain cbo select * from vw_t3 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t3 | ||
#### A masked pattern was here #### | ||
CBO PLAN: | ||
HiveSortLimit(fetch=[5]) | ||
HiveProject(username=[$0]) | ||
HiveFilter(condition=[>($0, _UTF-16LE'a')]) | ||
HiveProject(username=[$0]) | ||
HiveSortLimit(fetch=[10]) | ||
HiveProject(username=[$0]) | ||
HiveFilter(condition=[>($1, 10)]) | ||
HiveTableScan(table=[[default, t1]], table:alias=[t1]) | ||
|
||
PREHOOK: query: select * from vw_t3 | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@t1 | ||
PREHOOK: Input: default@vw_t3 | ||
#### A masked pattern was here #### | ||
POSTHOOK: query: select * from vw_t3 | ||
POSTHOOK: type: QUERY | ||
POSTHOOK: Input: default@t1 | ||
POSTHOOK: Input: default@vw_t3 | ||
#### A masked pattern was here #### |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why do we need a project and why the first project is important?
How do we use the project afterwards?
Does the code remain correct if we use a project that is not at the top of the plan?
Do we generally support views with
LIMIT
,ORDER BY
, etc?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 use the projects for authorization in
HiveRelFieldTrimmer.trimFields
here, and that's the only place where we use it. I believe that is why we need only the first project, that gives us the final list of fields.I don't think we can use other projects in place of the top one, as the fields could be different.
I am not really sure if we officially support views with limits or order by, but right now it looks like we can support them.
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.
The viewToProjectTableSchema has been introduced in HIVE-13095 to determine whether a user has the permission to access fields of a view. There's a comment in https://reviews.apache.org/r/43834/.
It could work if we expand the logic to all kinds of RelNodes. The code in trimFields(Project, ...) does not really use the project. The code could be applied to any kind of RelNode. The code would then work even if no project could be found (e.g., if the top level node is a join or union). The cost: adding a call to each of the
trimFields
methods.