You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@kylin.apache.org by Jayakumar Balasubramanya <ja...@fintellix.com> on 2019/04/25 05:42:07 UTC

SUM on CASE not working

Hi,
               I am facing a specific limitation when trying to roll-up a metric conditionally.  We are using case statement to either choose the metric or 0 and then doing a SUM on top of it. The condition is set on a dimension which is part of the cube. Getting an exception as stated below.

Query Not working:

Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent

This is the exception for it:

No realization found for OLAPContext, CUBE_UNMATCHED_AGGREGATION[FunctionDesc [expression=SUM, parameter=CASE(>=($9, 2), CAST($4):DECIMAL(14, 4), 0), returnType=null]], rel#1153:OLAPTableScan.OLAP.[](table=[DEFAULT, FCT_PROFIT_TABLE_MONTHLY],ctx=,fields=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]) while executing SQL: "Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly group by cyc_xxx_cyclesdelinquent LIMIT 50000"


This one works on Kylin:
SELECT CASE WHEN cyc_xxx_cyclesdelinquent>=2 THEN delinquent_bal ELSE 0 END FROM (Select SUM(Cyc_xxx_BalanceAdb) as delinquent_bal, cyc_xxx_cyclesdelinquent from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent)


Regards,
JK

RE: SUM on CASE not working

Posted by Jayakumar Balasubramanya <ja...@fintellix.com>.
Hi,
               Just to further add on, we tried the option of enable-dynamic-column. When kylin.query.enable-dynamic-column=true the sum case expression works but gives wrong results when the where clause is on the aliased column, tried it in the sample cube of kylin.

Working case:

select sum(case when trans_id_alias in(11,12,13) then  price_alias else 0 end) as price_case_sum,part_dt_alias from (select price as price_alias ,trans_id as trans_id_alias,part_dt as part_dt_alias from kylin_sales where trans_id>10)
group by part_dt_alias
order by price_case_sum desc

[cid:image001.png@01D4FB6F.C2190BF0]

Not working case:

select sum(case when trans_id_alias in(11,12,13) then price_alias else 0 end) as price_case_sum,part_dt_alias from (select price_alias,trans_id_alias,part_dt_alias from (select price as price_alias ,trans_id as trans_id_alias,part_dt as part_dt_alias from kylin_sales) where trans_id_alias>10)
group by part_dt_alias
order by price_case_sum desc


[cid:image002.png@01D4FB6F.C2190BF0]



Thanks,
JK


From: Jayakumar Balasubramanya
Sent: 25 April 2019 13:08
To: user@kylin.apache.org
Subject: RE: SUM on CASE not working

Hi,
               I am using 2.6.1 version.

Thanks,
JK

From: ShaoFeng Shi <sh...@apache.org>>
Sent: 25 April 2019 12:32
To: user <us...@kylin.apache.org>>
Subject: Re: SUM on CASE not working

What's your Kylin version? Kylin 2.4 and above should already support this.

Best regards,

Shaofeng Shi 史少锋
Apache Kylin PMC
Email: shaofengshi@apache.org<ma...@apache.org>

Apache Kylin FAQ: https://kylin.apache.org/docs/gettingstarted/faq.html
Join Kylin user mail group: user-subscribe@kylin.apache.org<ma...@kylin.apache.org>
Join Kylin dev mail group: dev-subscribe@kylin.apache.org<ma...@kylin.apache.org>




Jayakumar Balasubramanya <ja...@fintellix.com>> 于2019年4月25日周四 下午1:42写道:
Hi,
               I am facing a specific limitation when trying to roll-up a metric conditionally.  We are using case statement to either choose the metric or 0 and then doing a SUM on top of it. The condition is set on a dimension which is part of the cube. Getting an exception as stated below.

Query Not working:

Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent

This is the exception for it:

No realization found for OLAPContext, CUBE_UNMATCHED_AGGREGATION[FunctionDesc [expression=SUM, parameter=CASE(>=($9, 2), CAST($4):DECIMAL(14, 4), 0), returnType=null]], rel#1153:OLAPTableScan.OLAP.[](table=[DEFAULT, FCT_PROFIT_TABLE_MONTHLY],ctx=,fields=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]) while executing SQL: "Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly group by cyc_xxx_cyclesdelinquent LIMIT 50000"


This one works on Kylin:
SELECT CASE WHEN cyc_xxx_cyclesdelinquent>=2 THEN delinquent_bal ELSE 0 END FROM (Select SUM(Cyc_xxx_BalanceAdb) as delinquent_bal, cyc_xxx_cyclesdelinquent from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent)


Regards,
JK

RE: SUM on CASE not working

Posted by Jayakumar Balasubramanya <ja...@fintellix.com>.
Hi,
               I am using 2.6.1 version.

Thanks,
JK

From: ShaoFeng Shi <sh...@apache.org>
Sent: 25 April 2019 12:32
To: user <us...@kylin.apache.org>
Subject: Re: SUM on CASE not working

What's your Kylin version? Kylin 2.4 and above should already support this.

Best regards,

Shaofeng Shi 史少锋
Apache Kylin PMC
Email: shaofengshi@apache.org<ma...@apache.org>

Apache Kylin FAQ: https://kylin.apache.org/docs/gettingstarted/faq.html
Join Kylin user mail group: user-subscribe@kylin.apache.org<ma...@kylin.apache.org>
Join Kylin dev mail group: dev-subscribe@kylin.apache.org<ma...@kylin.apache.org>




Jayakumar Balasubramanya <ja...@fintellix.com>> 于2019年4月25日周四 下午1:42写道:
Hi,
               I am facing a specific limitation when trying to roll-up a metric conditionally.  We are using case statement to either choose the metric or 0 and then doing a SUM on top of it. The condition is set on a dimension which is part of the cube. Getting an exception as stated below.

Query Not working:

Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent

This is the exception for it:

No realization found for OLAPContext, CUBE_UNMATCHED_AGGREGATION[FunctionDesc [expression=SUM, parameter=CASE(>=($9, 2), CAST($4):DECIMAL(14, 4), 0), returnType=null]], rel#1153:OLAPTableScan.OLAP.[](table=[DEFAULT, FCT_PROFIT_TABLE_MONTHLY],ctx=,fields=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]) while executing SQL: "Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from fct_profit_table_monthly group by cyc_xxx_cyclesdelinquent LIMIT 50000"


This one works on Kylin:
SELECT CASE WHEN cyc_xxx_cyclesdelinquent>=2 THEN delinquent_bal ELSE 0 END FROM (Select SUM(Cyc_xxx_BalanceAdb) as delinquent_bal, cyc_xxx_cyclesdelinquent from fct_profit_table_monthly
group by cyc_xxx_cyclesdelinquent)


Regards,
JK

Re: SUM on CASE not working

Posted by ShaoFeng Shi <sh...@apache.org>.
What's your Kylin version? Kylin 2.4 and above should already support this.

Best regards,

Shaofeng Shi 史少锋
Apache Kylin PMC
Email: shaofengshi@apache.org

Apache Kylin FAQ: https://kylin.apache.org/docs/gettingstarted/faq.html
Join Kylin user mail group: user-subscribe@kylin.apache.org
Join Kylin dev mail group: dev-subscribe@kylin.apache.org




Jayakumar Balasubramanya <ja...@fintellix.com> 于2019年4月25日周四 下午1:42写道:

> Hi,
>
>                I am facing a specific limitation when trying to roll-up a
> metric conditionally.  We are using case statement to either choose the
> metric or 0 and then doing a SUM on top of it. The condition is set on a
> dimension which is part of the cube. Getting an exception as stated below.
>
>
>
> Query Not working:
>
>
>
> Select Sum(Case when cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB
> ELSE 0 end) from fct_profit_table_monthly
>
> group by cyc_xxx_cyclesdelinquent
>
>
>
> This is the exception for it:
>
>
>
> No realization found for OLAPContext,
> CUBE_UNMATCHED_AGGREGATION[FunctionDesc [expression=SUM,
> parameter=CASE(>=($9, 2), CAST($4):DECIMAL(14, 4), 0), returnType=null]],
> rel#1153:OLAPTableScan.OLAP.[](table=[DEFAULT,
> FCT_PROFIT_TABLE_MONTHLY],ctx=,fields=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
> 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
> 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
> 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
> 68, 69, 70]) while executing SQL: "Select Sum(Case when
> cyc_xxx_cyclesdelinquent>=2 THEN CYC_XXX_BALANCEADB ELSE 0 end) from
> fct_profit_table_monthly group by cyc_xxx_cyclesdelinquent LIMIT 50000"
>
>
>
>
>
> This one works on Kylin:
>
> SELECT CASE WHEN cyc_xxx_cyclesdelinquent>=2 THEN delinquent_bal ELSE 0
> END FROM (Select SUM(Cyc_xxx_BalanceAdb) as delinquent_bal,
> cyc_xxx_cyclesdelinquent from fct_profit_table_monthly
>
> group by cyc_xxx_cyclesdelinquent)
>
>
>
>
>
> Regards,
>
> JK
>