Articles in this section

How to avoid getting division result = 0 in Druid SQL.

SYMPTOM : When there is a division in Druid SQL, users may get 0 as result. 

For example: the return on `Saving_ratio` is always 0 in the following case. 

Screen_Shot_2018-07-09_at_1.15.11_PM.png

ROOT CAUSE: 

All numbers were ingested as of type `longSum` (integer),  and in Druid SQL integer divided by integer uses integer division and rounds down.  Therefore, the `Saving_ratio` is always zero since 'Save` is less than `Income`

 

RESOLUTION: 

Ingest the data as `floatSum` instead:

      "metricsSpec": [
        {
          "type": "count",
          "name": "count"
        },
        {
          "type": "floatSum",
          "name": "Income",
          "fieldName": "Income",
          "expression": null
        },
        {
          "type": "floatSum",
          "name": "Food_spending",
          "fieldName": "Food",
          "expression": null
        },
        {
          "type": "floatSum",
          "name": "Clothing_spending",
          "fieldName": "Clothing",
          "expression": null
        },
        {
          "type": "floatSum",
          "name": "Save",
          "fieldName": "Save",
          "expression": null
        }
      ],

 

Screen_Shot_2018-07-09_at_1.24.01_PM.png

Was this article helpful?
0 out of 0 found this helpful