case statement not working in metric level
Hi Folks,
Am trying to achieve below statement but it is showing error so is there any way get it same. In metric level, I have added this below SQL expression: sum(CASE WHEN diff=4 THEN 1 ELSE 0 ) I have grouped name as well in the column
Below error :
(pyhive.exc.DatabaseError) {u'errorCode': 7, u'message': u'Invalid format: "NULL"', u'errorType': u'USER_ERROR', u'failureInfo': {u'suppressed': [], u'cause': {u'suppressed': [], u'message': u'Invalid format: "NULL"', u'type': u'java.lang.IllegalArgumentException', u'stack': [u'org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:899)', u'com.facebook.presto.operator.scalar.DateTimeFunctions.parseDateTimeHelper(DateTimeFunctions.java:485)', u'com.facebook.presto.operator.scalar.DateTimeFunctions.fromISO8601Date(DateTimeFunctions.java:218)', u'com_facebook_presto_$gen_PageProcessor_15483.project_1(Unknown Source)', u'com_facebook_presto_$gen_PageProcessor_15483.process(Unknown Source)', u'com.facebook.presto.operator.FilterAndProjectOperator.getOutput(FilterAndProjectOperator.java:111)', u'com.facebook.presto.operator.Driver.processInternal(Driver.java:378)', u'com.facebook.presto.operator.Driver.processFor(Driver.java:301)', u'com.facebook.presto.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:622)', u'com.facebook.presto.execution.TaskExecutor$PrioritizedSplitRunner.process(TaskExecutor.java:534)', u'com.facebook.presto.execution.TaskExecutor$Runner.run(TaskExecutor.java:670)', u'java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)', u'java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)', u'java.lang.Thread.run(Thread.java:745)']}, u'message': u'Invalid format: "NULL"', u'type': u'com.facebook.presto.spi.PrestoException', u'stack': [u'com.facebook.presto.operator.scalar.DateTimeFunctions.parseDateTimeHelper(DateTimeFunctions.java:488)', u'com.facebook.presto.operator.scalar.DateTimeFunctions.fromISO8601Date(DateTimeFunctions.java:218)', u'com_facebook_presto_$gen_PageProcessor_15483.project_1(Unknown Source)', u'com_facebook_presto_$gen_PageProcessor_15483.process(Unknown Source)', u'com.facebook.presto.operator.FilterAndProjectOperator.getOutput(FilterAndProjectOperator.java:111)', u'com.facebook.presto.operator.Driver.processInternal(Driver.java:378)', u'com.facebook.presto.operator.Driver.processFor(Driver.java:301)', u'com.facebook.presto.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:622)', u'com.facebook.presto.execution.TaskExecutor$PrioritizedSplitRunner.process(TaskExecutor.java:534)', u'com.facebook.presto.execution.TaskExecutor$Runner.run(TaskExecutor.java:670)', u'java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)', u'java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)', u'java.lang.Thread.run(Thread.java:745)']}, u'errorName': u'INVALID_FUNCTION_ARGUMENT'}
you're missing an END there
sum(CASE WHEN diff=4 THEN 1 ELSE 0 )
->
sum(CASE WHEN diff=4 THEN 1 ELSE 0 END)
I Have tried with this sum(case when diff=4 then 1 else 0 END) but giving the same error.
Looks like there's something else that is wrong in the generated SQL. In previous versions you have to look at the server logs to look at the SQL statement. In recent version you can always get the latest SQL in the UI.