You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@impala.apache.org by "Aman Sinha (Jira)" <ji...@apache.org> on 2020/12/28 01:43:00 UTC

[jira] [Resolved] (IMPALA-2171) Analytic Function NTILE should allow for a non-constant argument

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

Aman Sinha resolved IMPALA-2171.
--------------------------------
    Resolution: Cannot Reproduce

This was likely fixed in an earlier release.  On 4.0-SNAPSHOT it works for me if the NTILE argument (which is the number of buckets) is an expression, not just a constant.  But it must evaluate to an integer value which is expected. 
The following statements worked:
{noformat}
 select ntile(2+2) over (partition by int_col order by int_col) from functional.alltypessmall;
select ntile(abs(-4)) over (partition by int_col order by int_col) from functional.alltypessmall;
{noformat}

The function gets rewritten to use row_number() and count():
{noformat}
Query: explain select ntile(abs(-4)) over (partition by int_col order by int_col) from functional.alltypessmall
+-------------------------------------------------------------+
| Explain String                                              |
+-------------------------------------------------------------+
| Max Per-Host Resource Reservation: Memory=14.01MB Threads=4 |
| Per-Host Resource Estimates: Memory=46MB                    |
| Codegen disabled by planner                                 |
|                                                             |
| PLAN-ROOT SINK                                              |
| |                                                           |
| 05:EXCHANGE [UNPARTITIONED]                                 |
| |                                                           |
| 03:ANALYTIC                                                 |
| |  functions: count()                                       |
| |  partition by: int_col                                    |
| |  row-size=20B cardinality=100                             |
| |                                                           |
| 02:ANALYTIC                                                 |
| |  functions: row_number()                                  |
| |  partition by: int_col                                    |
| |  order by: int_col ASC                                    |
| |  window: ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW |
| |  row-size=12B cardinality=100                             |
| |                                                           |
| 01:SORT                                                     |
| |  order by: int_col ASC NULLS LAST                         |
| |  row-size=4B cardinality=100                              |
| |                                                           |
| 04:EXCHANGE [HASH(int_col)]                                 |
| |                                                           |
| 00:SCAN HDFS [functional.alltypessmall]                     |
|    HDFS partitions=4/4 files=4 size=6.32KB                  |
|    row-size=4B cardinality=100                              |
+-------------------------------------------------------------+
{noformat}

> Analytic Function NTILE should allow for a non-constant argument
> ----------------------------------------------------------------
>
>                 Key: IMPALA-2171
>                 URL: https://issues.apache.org/jira/browse/IMPALA-2171
>             Project: IMPALA
>          Issue Type: Improvement
>          Components: Frontend
>    Affects Versions: Impala 2.3.0
>            Reporter: Sailesh Mukil
>            Priority: Minor
>              Labels: sql-language
>
> The analytic function NTILE is written as a query rewrite in the FE and currently only allows for constant arguments. The analyze() function in AnalyticExpr throws an exception if the argument passed to NTILE is non-constant.
> It needs to be changed to allow for non-constant arguments which might require some work in the BE as well (to validate the argument).



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