[ 
https://issues.apache.org/jira/browse/CALCITE-1822?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16037004#comment-16037004
 ] 

slim bouguerra edited comment on CALCITE-1822 at 6/5/17 2:09 PM:
-----------------------------------------------------------------


{code}
SELECT MAX(COUNT(*))
FROM Emp
GROUP BY deptno

SELECT MAX(c) FROM (
  SELECT deptno, COUNT(*) AS c
  FROM Emp
  GROUP BY deptno)  
{code}
translates to 
{code} 
{
  "queryType": "groupBy",
  "dataSource": {
    "type": "query",
    "query": {
      "queryType": "groupBy",
      "dataSource": {
        "type": "table",
        "name": "Emp"
      },
      "intervals": {
        "type": "intervals",
        "intervals": [
          "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"
        ]
      },
      "granularity": {
        "type": "all"
      },
      "dimensions": [
        {
          "type": "default",
          "dimension": "deptno",
          "outputName": "d0",
          "outputType": "STRING"
        }
      ],
      "aggregations": [
        {
          "type": "count",
          "name": "a0"
        }
      ]
    }
  },
  "intervals": {
    "type": "intervals",
    "intervals": [
      "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"
    ]
  },
  "granularity": {
    "type": "all"
  },
  "aggregations": [
    {
      "type": "longMax",
      "name": "a0",
      "fieldName": "a0"
    }
  ]
}
{code}


was (Author: bslim):
{code}          Push Aggregate that follows Aggregate down to Druid. This can 
occur if the SQL has an aggregate function applied to an aggregate function, or 
with a sub-query in the FROM clause.

{code}
SELECT MAX(COUNT(*))
FROM Emp
GROUP BY deptno

SELECT MAX(c) FROM (
  SELECT deptno, COUNT(*) AS c
  FROM Emp
  GROUP BY deptno)  {code}
{code} 
{
  "queryType": "groupBy",
  "dataSource": {
    "type": "query",
    "query": {
      "queryType": "groupBy",
      "dataSource": {
        "type": "table",
        "name": "Emp"
      },
      "intervals": {
        "type": "intervals",
        "intervals": [
          "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"
        ]
      },
      "granularity": {
        "type": "all"
      },
      "dimensions": [
        {
          "type": "default",
          "dimension": "deptno",
          "outputName": "d0",
          "outputType": "STRING"
        }
      ],
      "aggregations": [
        {
          "type": "count",
          "name": "a0"
        }
      ]
    }
  },
  "intervals": {
    "type": "intervals",
    "intervals": [
      "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z"
    ]
  },
  "granularity": {
    "type": "all"
  },
  "aggregations": [
    {
      "type": "longMax",
      "name": "a0",
      "fieldName": "a0"
    }
  ]
}
{code}

> Push Aggregate that follows Aggregate down to Druid
> ---------------------------------------------------
>
>                 Key: CALCITE-1822
>                 URL: https://issues.apache.org/jira/browse/CALCITE-1822
>             Project: Calcite
>          Issue Type: Bug
>          Components: druid
>            Reporter: Julian Hyde
>            Assignee: Julian Hyde
>
> Push Aggregate that follows Aggregate down to Druid. This can occur if the 
> SQL has an aggregate function applied to an aggregate function, or with a 
> sub-query in the FROM clause.
> {code}
> SELECT MAX(COUNT(*))
> FROM Emp
> GROUP BY deptno
> SELECT MAX(c) FROM (
>   SELECT deptno, COUNT(*) AS c
>   FROM Emp
>   GROUP BY deptno)
> {code}
> And there are other possibilities where there is a Project and/or a Filter 
> after the first Aggregate and before the second Aggregate.
> [~bslim], you wrote:
> {quote}
> For instance in druid we can do select count distinct as an inner group by 
> that group on the key and the outer one does then count. more complex cases 
> is count distinct from unions of multiple queries
> {quote}
> Can you please write a SQL statement for each of those cases?



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to