[ 
https://issues.apache.org/jira/browse/IMPALA-9694?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Quanlong Huang reassigned IMPALA-9694:
--------------------------------------

    Assignee: Aman Sinha  (was: Quanlong Huang)

> IllegalStateException when inlineView has AggregationNode and different alias 
> on the same column
> ------------------------------------------------------------------------------------------------
>
>                 Key: IMPALA-9694
>                 URL: https://issues.apache.org/jira/browse/IMPALA-9694
>             Project: IMPALA
>          Issue Type: Bug
>          Components: Frontend
>            Reporter: Quanlong Huang
>            Assignee: Aman Sinha
>            Priority: Critical
>
> The following query fails with IllegalStateException:
> {code:sql}
> > create table t1(ts TIMESTAMP, id BIGINT);
> > select count(*) from (
>     select lead(ts) over (partition by id order by ts),
>            id foo,
>            id bar
>     from t1
>   ) v;
> ERROR: IllegalStateException: Illegal reference to non-materialized slot: 
> tid=0 sid=1
> {code}
> The query works without the PartitionBy clause:
> {code:sql}
> select count(*) from (
>   select lead(ts) over (order by ts),
>          id foo,
>          id bar
>   from t1
> ) v;
> {code}
> Or avoid different alias on the same column:
> {code:sql}
> select count(*) from (
>   select lead(ts) over (partition by id order by ts),
>          id foo
>   from t1
> ) v;
> {code}
> *Clues*
>  Enabling TRACE level logging of the coordinator and rerun the failed query, 
> the illegal predicate "v.foo = v.bar" shows up:
> {code:java}
> I0426 20:10:10.194453  1068 Analyzer.java:2143] 
> 4241809b91bf54de:d5365a1700000000] Created inferred predicate: 
> BinaryPredicate{op==, SlotRef{label=v.foo, type=BIGINT, id=4} 
> SlotRef{label=v.bar, type=BIGINT, id=5}, isInferred=true}
> I0426 20:10:10.194509  1068 Analyzer.java:2574] 
> 4241809b91bf54de:d5365a1700000000] Assigned BinaryPredicate{op==, 
> SlotRef{label=v.foo, type=BIGINT, id=4} SlotRef{label=v.bar, type=BIGINT, 
> id=5}, isInferred=true}
> {code}
> It's finally migrated into the inlineView and references to "t1.id" which is 
> non-materialized. The planner generates this predicate since there are two 
> auxiliary predicates "v.foo = t1.id", "v.bar = t1.id". These two auxiliary 
> predicates only occur when the AggregationNode exists. We need to look deeper 
> into this bug.
> *Workaround*
>  Replace the second occurrence of the reference column with an identity 
> expression, e.g. change the above-failed query to:
> {code:sql}
> select count(*) from (
>   select lead(ts) over (partition by id order by ts),
>          id foo,
>          id - 1 + 1 as bar
>   from t1
> ) v;
> {code}
> By replacing the second occurrence of "id" to "id- 1 + 1", the planner can't 
> detect that the equivalence between "v.foo" and "v.bar". So the 
> AggregationNode won't have the redundant predicate "v.foo = v.bar" and won't 
> have illegal reference to "t1.id".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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

Reply via email to