Data types in javascript function filter

Hi,

I am trying to run js filter. Please have a look below .

{

“type”: “or”,

“fields”: [

{

“type”: “javascript”,

“dimension”: “#dimensionname#”,

“function”: “function(x) { var values = [‘true’];if( values.indexOf(x) != -1){ return true } else{ return false }}”

}

]

}

The above filter checks if dimension has value true (boolean), and this only works when true in single quotes. However in javascript value in single quotes consider as string.

Please note the ingested dimension value is true not ‘true’

How it actually works works in druid?

Hi Aman, you need to escape your quotes in the JS.

Hi Aman,

Druid currently stores all dimensions values as strings (this will change in a future release).

So even though you are ingesting true it gets converted to ‘true’.