You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/08/04 09:01:50 UTC

[GitHub] [druid] Mxdcq opened a new issue #10236: How to implement "case when" by Native queries

Mxdcq opened a new issue #10236:
URL: https://github.com/apache/druid/issues/10236


   Hi, I face a situation where I am not allowed to use SQL syntax to implement "case when". 
   
   1) Therefore, I would like to know if it is possible to do the following "case when" by native queries?
   `sum(case when column_A = value_one then column_B when column_A = value_two then column_C else column_D end)`
   2) If the answer if "Yes", please give a sample example!
   
   Thanks in advance.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] BigRantLing commented on issue #10236: How to implement "case when" by Native queries

Posted by GitBox <gi...@apache.org>.
BigRantLing commented on issue #10236:
URL: https://github.com/apache/druid/issues/10236#issuecomment-670444651


   [Druid filtered aggregator](https://druid.apache.org/docs/latest/querying/aggregations.html#filtered-aggregator)  may be help you . I think it can be parsed to native query like below:    
   
   ```json 
   {
       "queryType":"queryType",
       ....
       "aggregations":[
           {
               "type":"filtered",
               "filter":{
                   "type":"selector",
                   "dimension":"column_A",
                   "value":"value_one"
               },
               "aggregator":{
                   "type":"longSum",
                   "fieldName":"column_B",
                   "name":"sum_B"
               }
           },
           {
               "type":"filtered",
               "filter":{
                   "type":"selector",
                   "dimension":"column_A",
                   "value":"value_two"
               },
               "aggregator":{
                   "type":"longSum",
                   "fieldName":"column_D",
                   "name":"sum_D"
               }
           }
       ]
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] BigRantLing edited a comment on issue #10236: How to implement "case when" by Native queries

Posted by GitBox <gi...@apache.org>.
BigRantLing edited a comment on issue #10236:
URL: https://github.com/apache/druid/issues/10236#issuecomment-670444651


    @Mxdcp, Hi,
   [Druid filtered aggregator](https://druid.apache.org/docs/latest/querying/aggregations.html#filtered-aggregator)  may be help you . I think it can be parsed to native query like below:    
   
   ```json 
   {
       "queryType":"queryType",
       ....
       "aggregations":[
           {
               "type":"filtered",
               "filter":{
                   "type":"selector",
                   "dimension":"column_A",
                   "value":"value_one"
               },
               "aggregator":{
                   "type":"longSum",
                   "fieldName":"column_B",
                   "name":"sum_B"
               }
           },
           {
               "type":"filtered",
               "filter":{
                   "type":"selector",
                   "dimension":"column_A",
                   "value":"value_two"
               },
               "aggregator":{
                   "type":"longSum",
                   "fieldName":"column_D",
                   "name":"sum_D"
               }
           }
       ]
   }
   ```


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] Mxdcq commented on issue #10236: How to implement "case when" by Native queries

Posted by GitBox <gi...@apache.org>.
Mxdcq commented on issue #10236:
URL: https://github.com/apache/druid/issues/10236#issuecomment-671712610


   @BigRantLing ,Hi,
   Thanks for your help. I think it partially solve my problem by using filtered aggregator. But it cannot do the else part. For example column_A has hundreds of enum values, I want to calculate something if column_A = a_1, something else if column_A = a_2, the rest if column_A not in (a_1, a_2). Anyway, thanks for the instruction.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org