Druid round function

72 views
Skip to first unread message

Amit Kumar

unread,
Jul 2, 2019, 9:22:01 AM7/2/19
to Druid User
Hi All,

I was trying to use round function in my query
According to druid documentation:

round : round(x, y) would return the value of the x rounded to the y decimal places..

When using below query:
 "type" : "expression",
    "name" : "VIRTUALKPI_NodeB_C_15",
    "expression" : "100*((NodeB_C_2)/(NodeB_C_1))",
    "outputType" : "DOUBLE"


  Results were:
 {
  "version" : "v1",
  "timestamp" : "2019-07-02T12:00:00.000Z",
  "event" : {
    "NodeB_C_1" : 3724.0,
    "NodeB_P_1" : "EER",
    "VIRTUALKPI_NodeB_C_15" : 98.09344790547799,
    "COUNTER_GROUP_ID" : "NodeB_CG_31",
    "NodeB_C_2" : 3653.0
  }
}, {
  "version" : "v1",
  "timestamp" : "2019-07-02T12:15:00.000Z",
  "event" : {
    "NodeB_C_1" : 4093.0,
    "NodeB_P_1" : "EER",
    "VIRTUALKPI_gNodeB_C_15" : 99.12044954800879,
    "COUNTER_GROUP_ID" : "NodeB_CG_31",
    "NodeB_C_2" : 4057.0
  }

when i tried round function:

"type" : "expression",
    "name" : "VIRTUALKPI_NodeB_C_15",
    "expression" : "round(100*((NodeB_C_2)/(NodeB_C_1)),6)",
    "outputType" : "DOUBLE"


I got Exception :

{
  "error" : "Unknown exception",
  "errorMessage" : "Function[round] needs 1 argument",
  "errorClass" : "org.apache.druid.java.util.common.IAE",
  "host" : null
}


So i tried modifying query to be:
 "type" : "expression",
    "name" : "VIRTUALKPI_NodeB_C_15",
    "expression" : "round(100*((NodeB_C_2)/(NodeB_C_1))*1000)/1000",
    "outputType" : "DOUBLE"

The results were:

 {
  "version" : "v1",
  "timestamp" : "2019-07-02T12:00:00.000Z",
  "event" : {
    "NodeB_C_1" : 3724.0,
    "NodeB_P_1" : "EER",
    "VIRTUALKPI_NodeB_C_15" : 98,
    "COUNTER_GROUP_ID" : "NodeB_CG_31",
    "NodeB_C_2" : 3653.0
  }
}, {
  "version" : "v1",
  "timestamp" : "2019-07-02T12:15:00.000Z",
  "event" : {
    "NodeB_C_1" : 4093.0,
    "NodeB_P_1" : "EER",
    "VIRTUALKPI_NodeB_C_15" : 99,
    "COUNTER_GROUP_ID" : "NodeB_CG_31",
    "NodeB_C_2" : 4057.0
  }
}


Can anyone please help me in getting round off values to 3 decimal places.
Thanks in Advance.


Amit Kumar

Siva Mannem

unread,
Jul 2, 2019, 1:47:10 PM7/2/19
to Druid User
Hi Amit,
Function round should be able to accept two arguments. Not sure why it is complaining "Function[round] needs 1 argument".

What is your druid version? If it is older version, Is it possible for you to try with latest druid-0.14?
Thanks ,
--siva

Gian Merlino

unread,
Jul 2, 2019, 9:00:55 PM7/2/19
to druid...@googlegroups.com
This might mean you have a newer broker, but older data servers (historical / MMs). This combo isn't supported and can sometimes lead to weird errors like the ones you're seeing. We would always recommend upgrading the data servers first, then the brokers afterwards.

Gian


--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+...@googlegroups.com.
To post to this group, send email to druid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/druid-user/afcb29b6-082b-47b9-be16-14d2b581a083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amit Kumar

unread,
Jul 2, 2019, 9:43:01 PM7/2/19
to Druid User
Hi,

All the druid nodes are running 0.13 druid version.

Thanks,
Amit kumar

Amit Kumar

unread,
Jul 2, 2019, 10:05:39 PM7/2/19
to Druid User
Even in java.lang.Math I can't see any round(x,y) function.
Please provide solution.

Thanks,
Amit

Muthu Lalapet

unread,
Jul 2, 2019, 10:18:44 PM7/2/19
to Druid User
Just a look at the code tells us why you are getting this error.

Please see the below code, its from 0.14.0 version and it uses Math.round(param) function. Which expects only one param. Because of this implementation you are getting the error as druid is expecting only one param for that function


However in 0.15.0 version the implementation of the Round druid function is changed. Please see below link (search for 'class Round' to see the differences)


So you have two options

And also please refer to the 0.13.0 doc

https://druid.apache.org/docs/0.13.0-incubating/misc/math-expr.html it clearly says round is a single param function.

To unsubscribe from this group and stop receiving emails from it, send an email to druid...@googlegroups.com.

To post to this group, send email to druid...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/druid-user/afcb29b6-082b-47b9-be16-14d2b581a083%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Druid User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to druid...@googlegroups.com.

Amit Kumar

unread,
Jul 2, 2019, 11:02:36 PM7/2/19
to Druid User
Hi,
Thanks a lot for clarification.
But below query should given me proper result, the result of query is mentioned in above mail thread.
"type" : "expression",
    "name" : "VIRTUALKPI_NodeB_C_15",
    "expression" : "round(100*((NodeB_C_2)/(NodeB_C_1))*1000)/1000",
    "outputType" : "DOUBLE"
 
Thanks ,
Amit Kumar


To unsubscribe from this group and stop receiving emails from it, send an email to druid-user+...@googlegroups.com.

To post to this group, send email to druid...@googlegroups.com.

Muthu Lalapet

unread,
Jul 2, 2019, 11:23:16 PM7/2/19
to Druid User
Thats because Math.round returns a long value. And if you divide a long value by any number the decimals will be ignored.

See the answer in this link https://stackoverflow.com/questions/11701399/round-up-to-2-decimal-places-in-java so may be try doing this in the expression

round(100*((NodeB_C_2)/(NodeB_C_1))*1000.0)/1000.0
Hi,
Reply all
Reply to author
Forward
0 new messages