kgyrtkirk commented on issue #16728:
URL: https://github.com/apache/druid/issues/16728#issuecomment-2228976930

   interesting; for me even a similar query to yours is planned as a topn
   
   ```sql
   SELECT "page", 
       sum(added) filter (where "__time" >= '2015-09-12T00:00:00.000Z' AND 
"__time" < '2015-09-12T01:00:00.000Z') as base_added,
       sum(added) filter (where "__time" >= '2015-09-12T01:00:00.000Z' AND 
"__time" < '2015-09-12T20:00:00.000Z')  AS comparison_added,
       sum(added) filter (where "__time" >= '2015-09-12T00:00:00.000Z' AND 
"__time" < '2015-09-12T01:00:00.000Z') -
       sum(added) filter (where "__time" >= '2015-09-12T01:00:00.000Z' AND 
"__time" < '2015-09-12T20:00:00.000Z')  AS  gx
     FROM "wikipedia"  WHERE "__time" >= '2015-09-12T00:00:00.000Z' AND 
"__time" < '2015-09-12T20:00:00.000Z' GROUP BY 1 ORDER BY "gx" DESC LIMIT 33
   
   ```
   
   <details>
   <summary>plan</summary>
   
   ```json
   [
       {
           "query": {
               "queryType": "topN",
               "dataSource": {
                   "type": "table",
                   "name": "wikipedia"
               },
               "dimension": {
                   "type": "default",
                   "dimension": "page",
                   "outputName": "d0",
                   "outputType": "STRING"
               },
               "metric": {
                   "type": "numeric",
                   "metric": "p0"
               },
               "threshold": 33,
               "intervals": {
                   "type": "intervals",
                   "intervals": [
                       "2015-09-12T00:00:00.000Z/2015-09-12T20:00:00.000Z"
                   ]
               },
               "granularity": {
                   "type": "all"
               },
               "aggregations": [
                   {
                       "type": "filtered",
                       "aggregator": {
                           "type": "longSum",
                           "name": "a0",
                           "fieldName": "added"
                       },
                       "filter": {
                           "type": "range",
                           "column": "__time",
                           "matchValueType": "LONG",
                           "lower": 1442016000000,
                           "upper": 1442019600000,
                           "upperOpen": true
                       },
                       "name": "a0"
                   },
                   {
                       "type": "filtered",
                       "aggregator": {
                           "type": "longSum",
                           "name": "a1",
                           "fieldName": "added"
                       },
                       "filter": {
                           "type": "range",
                           "column": "__time",
                           "matchValueType": "LONG",
                           "lower": 1442019600000,
                           "upper": 1442088000000,
                           "upperOpen": true
                       },
                       "name": "a1"
                   }
               ],
               "postAggregations": [
                   {
                       "type": "expression",
                       "name": "p0",
                       "expression": "(\"a0\" - \"a1\")",
                       "outputType": "LONG"
                   }
               ],
               "context": {
                   "enableUnnest": true,
                   "implyFeature": "explain",
                   "implyUser": "asd",
                   "implyView": "sql",
                   "queryId": "PIVOT-f3daed67-f916-4027-a002-e0bff6572ea8-1",
                   "sqlOuterLimit": 5000,
                   "sqlQueryId": "c15c8d19-095c-40dd-aef5-92f30240b634",
                   "timeout": 300000
               }
           },
           "signature": [
               {
                   "name": "d0",
                   "type": "STRING"
               },
               {
                   "name": "a0",
                   "type": "LONG"
               },
               {
                   "name": "a1",
                   "type": "LONG"
               },
               {
                   "name": "p0",
                   "type": "LONG"
               }
           ],
           "columnMappings": [
               {
                   "queryColumn": "d0",
                   "outputColumn": "page"
               },
               {
                   "queryColumn": "a0",
                   "outputColumn": "base_added"
               },
               {
                   "queryColumn": "a1",
                   "outputColumn": "comparison_added"
               },
               {
                   "queryColumn": "p0",
                   "outputColumn": "gx"
               }
           ]
       }
   ]
   ```
   </details>
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to