Search code examples
sqldatabricks

Databricks SQL issue mismatched input ')' expecting ','


I am trying to solve the issue mismatched input ')' expecting ',', but cannot guess, what went wrong. I have read all documentation, cannot find where I am missing the comma, becasue databricks says "Error in SQL statement: ParseException: mismatched input ')' expecting ','(line 2, pos 108)":

 select 
 (CASE WHEN (fdse.`eventaction` IN ('zoom image')) THEN sum(CAST(fdse.`totalevents` AS 
 BIGINT)) END AS `zoom`)

 from GA_FAVORITES_DIGITAL_STYLIST_EVENTS as fdse
 inner join GA_FAVORITES_SESSIONS as fs
 on fdse.uniquesessionid = fs.uniquesessionid
 and fdse.trans_date = fs.trans_date
 where fs.trans_date >= date_add(current_date,-10)
 limit 10

UPD I fixed the mismatch error, but now I am having AnalysisException: grouping expressions sequence is empty, and 'fdse.eventaction' is not an aggregate function. Wrap '(CASE WHEN (fdse.eventaction IN ('zoom image')) THEN sum(CAST(fdse.totalevents AS BIGINT)) END AS zoom)' in windowing function(s) or wrap 'fdse.eventaction' in first() (or first_value) if you don't care which value you get. PLease let me know how to fix that, because if adding the parentises again it will give me again the mismatch error.


Solution

  • The issue might be because the AS is inside of the parentheses. Try this and let me know if it works:

    SELECT
    (CASE WHEN (fdse.`eventaction` IN 'zoom image') THEN SUM(CAST(fdse.`totalevents` AS BIGINT)) END) AS `zoom`
    FROM GA_FAVORITES_DIGITAL_STYLIST_EVENTS AS fdse
    INNER JOIN GA_FAVORITES_SESSIONS AS fs
    ON fdse.uniquesessionid = fs.uniquesessionid
    AND fdse.trans_date = fs.trans_date
    WHERE fs.trans_date >= date_add(current_date, -10)
    LIMIT 10
    

    Sometimes SQL errors can be misleading!