[
https://issues.jboss.org/browse/TEIID-3748?page=com.atlassian.jira.plugin...
]
Don Krapohl reopened TEIID-3748:
--------------------------------
Adding log.
Query executed:
SELECT publisher_key,sum(num_clicks),count(distinct case when order_pub_comm_base >= 0
then orderid end) FROM ActivityAdvertiserTransDate WHERE trans_date_key BETWEEN
'2015-09-01' AND '2015-09-10' AND advertiser_key=2417 GROUP BY
publisher_key HAVING sum(num_clicks)>100 AND count(distinct case when
order_pub_comm_base >= 0 then orderid end)=0
See exception at line 4297
Caused by: java.sql.SQLException: [Simba][ImpalaJDBCDriver](500051) ERROR processing
query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS,
sqlState:HY000, errorMessage:AnalysisException: all DISTINCT aggregate functions need to
have the same set of parameters as count(DISTINCT (CASE WHEN (g_0.order_pub_comm_base
>= 0) THEN g_0.orderid ELSE CAST(NULL AS STRING) END)); deviating function:
count(DISTINCT (CASE WHEN (g_0.order_pub_comm_base >= 0) THEN g_0.orderid ELSE NULL
END))
), Query: SELECT `g_0`.`publisher_key`, SUM(ALL `g_0`.`num_clicks`) as `EXPR_0`,
COUNT(DISTINCT (CASE WHEN (`g_0`.`order_pub_comm_base` >= 0) THEN `g_0`.`orderid` ELSE
CAST(NULL AS STRING) END)) as `EXPR_1` FROM `mart`.`fact_activity_advertiser_trans_date`
`g_0` WHERE ((`g_0`.`advertiser_key` = 2417) AND ((`g_0`.`trans_date_key` >=
'2015-09-01') AND (`g_0`.`trans_date_key` <= '2015-09-10'))) GROUP BY
`g_0`.`publisher_key` HAVING ((SUM(ALL `g_0`.`num_clicks`) > 100) AND (COUNT(DISTINCT
(CASE WHEN (`g_0`.`order_pub_comm_base` >= 0) THEN `g_0`.`orderid` ELSE NULL END)) =
0)).
Impala translator - SELECT and HAVING statements are translating
differently for Case statements
------------------------------------------------------------------------------------------------
Key: TEIID-3748
URL:
https://issues.jboss.org/browse/TEIID-3748
Project: Teiid
Issue Type: Bug
Components: JDBC Connector
Affects Versions: 8.11.4
Environment: Ubuntu Trusty
Reporter: Don Krapohl
Assignee: Steven Hawkins
Labels: Impala_Translator, Translators
Error from Impala-
all DISTINCT aggregate functions need to have the same set of parameters as
count(DISTINCT (CASE WHEN (secondcol >= 0) THEN 1 ELSE CAST(NULL AS STRING) END))
deviating function: count(DISTINCT (CASE WHEN (secondcol >= 0) THEN 1 ELSE NULL END))
Query:
SELECT user_key, sum(firstcol),count(distinct case when secondcol >= 0 then 1 end)
FROM sometable
WHERE customer_key=6
GROUP BY user_key
HAVING sum(firstcol)>100
AND count(distinct case when secondcol >= 0 then 1 end)=0
Query explanation:
For all users
Add up values in the firstcol column (integer column)
count distinct values in secondcol where secondcol value zero or more
otherwise return null (output is string)
Translated Teiid query:
SELECT user_key, SUM(firstcol) as `EXPR_0`, COUNT(DISTINCT (CASE WHEN (secondcol >= 0)
THEN '1' ELSE CAST(NULL AS STRING) END)) as `EXPR_1`
FROM sometable
WHERE customer_key` = 6
HAVING (EXPR_0 > 100) AND (COUNT(DISTINCT (CASE WHEN (secondcol >= 0) THEN
'1' ELSE NULL END)) = 0))
Note the difference between the select and having for EXPR_1:
Select - THEN '1' ELSE CAST(NULL AS STRING) END
Having - THEN '1' ELSE NULL END
Impala doesn't accept that these are the same aggregate function. Aliases aren't
accepted in the HAVING.
One further observation- if we swap the translation and write the statement in the select
as
COUNT(DISTINCT (CASE WHEN (secondcol >= 0) THEN '1' *ELSE NULL END*))
Teiid translates the SELECT to
COUNT(DISTINCT (CASE WHEN (secondcol >= 0) THEN '1' *ELSE CAST(NULL AS STRING)
END*))
So it always makes these mismatched.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)