[ 
https://issues.apache.org/jira/browse/HIVE-13991?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15323765#comment-15323765
 ] 

Yongzhi Chen commented on HIVE-13991:
-------------------------------------

There are inconsistent key values between put and get operations for map 
viewAliasToInput
In 
private void getMetaData(QB qb, ReadEntity parentInput) method:
{noformat}
        // This is the last time we'll see the Table objects for views, so add 
it to the inputs
        // now. isInsideView will tell if this view is embedded in another view.
        ReadEntity viewInput = new ReadEntity(tab, parentInput, 
!qb.isInsideView());
        viewInput = PlanUtils.addInput(inputs, viewInput);
        aliasToViewInfo.put(alias, new ObjectPair<String, 
ReadEntity>(fullViewName, viewInput));
        viewAliasToInput.put(getAliasId(alias, qb), viewInput);
{noformat}
The key is getAliasId(alias, qb), the key is non-processed alias ID, for the 
union all case, it looks like
null-subquery1:_u1-subquery1:viewsrc

But in method getParentViewInfo, alias ID is processed before get from the map. 
The alias ID replace subquery1 to empty, the key
looks like following:
null:_u1:viewsrc
{noformat}
public static ReadEntity getParentViewInfo(String alias_id,
      Map<String, ReadEntity> viewAliasToInput) {
    String[] aliases = alias_id.split(":");

    String currentAlias = null;
    ReadEntity currentInput = null;
    // Find the immediate parent possible.
    // For eg: for a query like 'select * from V3', where V3 -> V2, V2 -> V1, 
V1 -> T
    // -> implies depends on.
    // T's parent would be V1
    for (int pos = 0; pos < aliases.length; pos++) {
      currentAlias = currentAlias == null ? aliases[pos] : currentAlias + ":" + 
aliases[pos];

      currentAlias = currentAlias.replace(SemanticAnalyzer.SUBQUERY_TAG_1, "")
          .replace(SemanticAnalyzer.SUBQUERY_TAG_2, "");
      ReadEntity input = viewAliasToInput.get(currentAlias);
{noformat}

This inconsistence causes getParentViewInfo return null.
Attach the patch to fix the issue. 

> Union All on view fail with no valid permission on underneath table
> -------------------------------------------------------------------
>
>                 Key: HIVE-13991
>                 URL: https://issues.apache.org/jira/browse/HIVE-13991
>             Project: Hive
>          Issue Type: Bug
>          Components: Query Planning
>            Reporter: Yongzhi Chen
>            Assignee: Yongzhi Chen
>
> When sentry is enabled. 
> create view V as select * from T;
> When the user has read permission on view V, but does not have read 
> permission on table T,
> select * from V union all select * from V 
> failed with:
> {noformat}
> 0: jdbc:hive2://********> select * from s07view union all select * from 
> s07view limit 1;
> Error: Error while compiling statement: FAILED: SemanticException No valid 
> privileges
>  Required privileges for this query: 
> Server=server1->Db=default->Table=sample_07->action=select; 
> (state=42000,code=40000)
> {noformat} 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to