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

Adam Kramer commented on HIVE-1395:
-----------------------------------

Right--this is reported as a bug because Hive is crossing levels. The first use 
of a.num in the above query should look into the CLOSEST scope, which is the 
subquery labeled a. What hive is doing here is looking into the NON-CLOSEST 
scope, and returning foo.num when it should return (subquery).num. That is the 
bug.

Whether we should allow it at ALL in hive, since it's confusing, is a broader 
question. I vote either for disallowing it at all, or disallowing it in strict 
mode.

> Table aliases are ambiguous
> ---------------------------
>
>                 Key: HIVE-1395
>                 URL: https://issues.apache.org/jira/browse/HIVE-1395
>             Project: Hadoop Hive
>          Issue Type: Bug
>          Components: Query Processor
>            Reporter: Adam Kramer
>
> Consider this query:
> SELECT a.num FROM (
>   SELECT a.num AS num, b.num AS num2
>   FROM foo a LEFT OUTER JOIN bar b ON a.num=b.num
> ) a
> WHERE a.num2 IS NULL;
> ...in this case, the table alias 'a' is ambiguous. It could be the outer 
> table (i.e., the subquery result), or it could be the inner table (foo).
> In the above case, Hive silently parses the outer reference to a as the inner 
> reference. The result, then, is akin to:
> SELECT foo.num FROM foo WHERE bar.num IS NULL. This is bad.
> The bigger problem, however, is that Hive even lets people use the same table 
> alias at multiple points in the query. We should simply throw an exception 
> during the parse stage if there is any ambiguity in which table is which, 
> just like we do if the column names are ambiguous.
> Or, if for some reason we need people to be able to use 'a' to refer to 
> multiple tables or subqueries, it would be excellent if the exact parsing 
> structure were made clear and added to the wiki. In that case, I will file a 
> separate bug JIRA to complain about how it should be different. :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to