superset icon indicating copy to clipboard operation
superset copied to clipboard

PostAggregator of PostAggregator

Open csonigo opened this issue 9 years ago • 1 comments

Hi all,

I just want to confirm that it is not possible to use a postagg metric in another postagg metric. From what I understand, post-aggregator are sent with the query and calculated on top of the inital query result. Druid Docs states that:

The arithmetic post-aggregator applies the provided function to the given fields from left to right. The fields can be aggregators or other post aggregators.

But it is unclear if the post aggregator fields can be a reference to a post aggregator defined earlier in the query or if it has to be redefined.

So I've experimented in Superset: Let's say I have the postagg definition (where someFieldA and someFieldB are simple sum aggregator for instance)

{
  "type": "arithmetic",
  "name": "sumAB",
  "fn": "+",
  "fields": [
    {
      "fieldName": "someFieldA",
      "type": "fieldAccess",
      "name": "someFieldA"
    },
    {
      "fieldName": "someFieldB",
      "type": "arithmetic",
      "name": "someFieldB"
    }
  ]
}

I cannot simply reuse this in another postagg definition like so (I have tried various value for sumAB type without success)

{
  "type": "arithmetic",
  "name": "ratioA",
  "fn": "/",
  "fields": [
    {
      "fieldName": "someFieldA",
      "type": "fieldAccess",
      "name": "someFieldA"
    },
    {
      "fieldName": "sumAB",
      "type": "??",
      "name": "sumAB"
    }
  ]
}

But would have to redefine sumAB every time I have to use it like so:

{
  "type": "arithmetic",
  "name": "ratioA",
  "fn": "/",
  "fields": [
    {
      "fieldName": "someFieldA",
      "type": "fieldAccess",
      "name": "someFieldA"
    },
    {
      "type": "arithmetic",
      "name": "sumAB",
      "fn": "+",
      "fields": [
        {
          "fieldName": "someFieldA",
          "type": "fieldAccess",
          "name": "someFieldA"
        },
        {
          "fieldName": "someFieldB",
          "type": "arithmetic",
          "name": "someFieldB"
        }
      ]
    }
  ]
}

Which of course can be really annoying if we build complex post aggregators and want to reuse intermediary calculations.

So the question is, is it possible or not? If yes, what field type should I use ? And if not, is it something you could consider supporting in the future?

Thanks in advance.

Charles

csonigo avatar Jan 12 '17 11:01 csonigo

Notice: this issue has been closed because it has been inactive for 465 days. Feel free to comment and request for this issue to be reopened.

mistercrunch avatar Apr 23 '18 05:04 mistercrunch