Druid round function

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

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

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.

Hi,

All the druid nodes are running 0.13 druid version.

Thanks,

Amit kumar

Even in java.lang.Math I can’t see any round(x,y) function.
Please provide solution.

Thanks,

Amit

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

https://github.com/apache/incubator-druid/blob/0.14.0-incubating/core/src/main/java/org/apache/druid/math/expr/Function.java

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)

https://github.com/apache/incubator-druid/blob/0.15.0-incubating/core/src/main/java/org/apache/druid/math/expr/Function.java

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.

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

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

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

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

https://github.com/apache/incubator-druid/blob/0.14.0-incubating/core/src/main/java/org/apache/druid/math/expr/Function.java

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)

https://github.com/apache/incubator-druid/blob/0.15.0-incubating/core/src/main/java/org/apache/druid/math/expr/Function.java

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.

Even in java.lang.Math I can’t see any round(x,y) function.
Please provide solution.

Thanks,

Amit

Hi,

All the druid nodes are running 0.13 druid version.

Thanks,

Amit kumar

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

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

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

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.

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.

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/CACZNdYCghdTPXwJZtMTi63V85egxJwMDuJ-Cd%3D91PofmALy6VQ%40mail.gmail.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.

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/38087e56-04bd-47c3-afe8-c5b455af7e5e%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

round(100*((NodeB_C_2)/(NodeB_C_1))*1000.0)/1000.0