Search code examples
group-bymismatchsiddhiwso2-cep

SiddhiQL query Error : mismatched input 'group'


I am using a simple SiddhiQL query to get number of records having same timestamp till minute entry and these timestamps. The query is:

from inputStream
select time:dateFormat(ts,'yyyy-MM-dd HH:mm') as formatedTs, count(formatedTs)
group by formatedTs
insert into outputStream;

It gives me the error mismatched input 'group' expecting {'*', '+', '-', '/', '%', '<', '<=', '>', '>=', '==', '!=', AS, OR, AND, IN}. What's wrong with group by clause in this context?


Solution

  • Reason for the error:

    This particular error is coming due to the missing AS, following count(formatedTs)

    (This is indicated in the error message as well. mismatched input 'group' expecting {'*', '+', '-', '/', '%', '<', '<=', '>', '>=', '==', '!=', AS, OR, AND, IN} Query Compiler thinks group is in wrong place due to the missing AS)

    Correction needed:

    So the select statement, needs to be corrected as below:

    select time:dateFormat(ts,'yyyy-MM-dd HH:mm') as formatedTs, count(formatedTs) as tsCount
    

    Further correction which you might need:

    Also, does the inputStream has an attribute named formatedTs? If not, after fixing the select statement, you'll get another error like below:

    Cannot find attribute type as 'formatedTs' does not exist in 'inputStream'

    because the attribute for which you are taking the count should exist in the inputStream

    If that is the case, following query (which should compile successfully) might help you:

    from inputStream
    select time:dateFormat(ts,'yyyy-MM-dd HH:mm') as formatedTs, count(ts) as countTs
    group by ts
    insert into outputStream;
    

    Update

    Updating the query since your requirement is to group by the formatted timestamp:

    from inputStream
    select time:dateFormat(ts,'yyyy-MM-dd HH:mm') as formatedTs
    insert into innerStream;
    
    from innerStream
    select formatedTs, count(formatedTs) as countTs
    group by formatedTs
    insert into outStream;