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

Jinfeng Ni commented on DRILL-4572:
-----------------------------------

It might be related to the function used in the query. For the following query, 
where both functions are defined in calcite as well,=), it works fine.

{code}
select upper(s.name2) as name3 
from (
  select
    lower(n_name) as `name2`, 
    count(*) as num_creates
  from cp.`tpch/nation.parquet`
  group by lower(n_name) 
  order by name2 ASC
) s limit 1;

+----------+
|  name3   |
+----------+
| ALGERIA  |
+----------+

{code}


> Column Alias Not Available in Subquery
> --------------------------------------
>
>                 Key: DRILL-4572
>                 URL: https://issues.apache.org/jira/browse/DRILL-4572
>             Project: Apache Drill
>          Issue Type: Bug
>          Components: Query Planning & Optimization
>    Affects Versions: 1.4.0, 1.5.0, 1.6.0
>            Reporter: John Omernik
>
> In the query and error below, I have a "inside" aggregate query where the 
> groupped field is the result of a function, but I use an alias (`cdate`) to 
> reference it.  In the outer part of the query, I try to reference that alias 
> and the query fails with the error. The error seems to imply it can't see the 
> aliased field. 
> Jinfeng Ni was also able to reproduce based on the mailing list. 
> select date_part('year', s.cdate) as ydate from (
>     select 
>     to_date(createdon, 'yyyy-MM-dd HH:mm:ss') as `cdate`, count(*) as      
> num_creates 
>     from 
>     view_mytable
>    where 
>    createdon <> '0000-00-00 00:00:00' and createdon >= '2010-01-10' 
>    group by 
>     to_date(createdon, 'yyyy-MM-dd HH:mm:ss')
>     order by cdate ASC
> ) s limit 100
> SYSTEM ERROR: AssertionError: Internal error: Type 'RecordType(ANY $f0, 
> BIGINT num_creates)' has no field 'cdate'
> [Error Id: 50caacaf-0b9b-4c1c-a3e1-53248bc385c0 on 
> hadoopmapr6.brewingintel.com:31010]



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

Reply via email to