Quanlong Huang created IMPALA-9694:
--------------------------------------

             Summary: 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
            Reporter: Quanlong Huang


The following query fails with IllegalStateException:
{code:sql}
> create table t1(tsaend TIMESTAMP, partid BIGINT);
> select count(*) from (
    select lead(tsaend) over (partition by partid order by tsaend),
           partid foo,
           partid 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(tsaend) over (order by tsaend),
         partid foo,
         partid bar
  from t1
) v;
{code}
Or avoid different alias on the same column:
{code:sql}
select count(*) from (
  select lead(tsaend) over (partition by partid order by tsaend),
         partid 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.partid" which 
is non-materialized. The planner generates this predicate since there are two 
auxiliary predicates "v.foo = t1.partid", "v.bar = t1.partid". These two 
auxiliary predicates only occur when the AggregationNode exists. We need to 
look deeper into this bug.

*Workaround*
 Replace the second occurence of the reference column with an identity 
expression, e.g. change the above failed query to:
{code:sql}
select count(*) from (
  select lead(tsaend) over (partition by partid order by tsaend),
         partid foo,
         partid - 1 + 1 as bar
  from t1
) v;
{code}
By replacing the second occurence of "partid" to "partid - 1 + 1", the planner 
can't detect that the equivalence between "v.foo" and "v.bar". So the 
AggregationNode won't have the redudant predicate "v.foo = v.bar" and won't 
have illegal reference to "t1.partid".



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

Reply via email to