How to add Javascript extraction function in Druid?

51 Views Asked by At

I am not able to add this fucntion to Druid. (Don't know how to add one)

I trying to preprocess data coming from druid.

function transformData(data) {
    const res = {};
    const dataArray = data.split(',');

    dataArray.map(value => {
        res[value] = true;
    });

    if ('abc' in res) {
        return 'abc';
    } else {
        return 'xyz;
    }

    return '';
}

I want to access this transformation function as a part of SQL query while querying from Druid.

1

There are 1 best solutions below

1
Peter Marshall On

Information on how to use Javascript with Apache Druid is given on the documentation page below.

Note that Javascript is not a recommended solution for production. You should therefore see if you can craft the same function using SQL or native expressions. Failing that, take a look at the documentation on how to add your own extension module.

It looks like you're trying to do something with arrays? If so, check out the new ARRAY type in Druid and its associated functions. A Python notebook on this is available in the learn-druid repo under the "ingestion" section.

For further help, join the #dev channel in the project's Slack channel.