drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Muhammad Gelbana (JIRA)" <j...@apache.org>
Subject [jira] [Created] (DRILL-5193) UDF returns NULL as expected only if the input is a literal
Date Thu, 12 Jan 2017 11:31:51 GMT
Muhammad Gelbana created DRILL-5193:

             Summary: UDF returns NULL as expected only if the input is a literal
                 Key: DRILL-5193
                 URL: https://issues.apache.org/jira/browse/DRILL-5193
             Project: Apache Drill
          Issue Type: Bug
          Components: Functions - Drill
    Affects Versions: 1.9.0
            Reporter: Muhammad Gelbana

I defined the following UDF
import javax.inject.Inject;

import org.apache.drill.exec.expr.DrillSimpleFunc;
import org.apache.drill.exec.expr.annotations.FunctionTemplate;
import org.apache.drill.exec.expr.annotations.Output;
import org.apache.drill.exec.expr.annotations.Param;
import org.apache.drill.exec.expr.holders.IntHolder;
import org.apache.drill.exec.expr.holders.NullableVarCharHolder;
import org.apache.drill.exec.expr.holders.VarCharHolder;

import io.netty.buffer.DrillBuf;

@FunctionTemplate(name = "split_string", scope = FunctionTemplate.FunctionScope.SIMPLE, nulls
= FunctionTemplate.NullHandling.NULL_IF_NULL)
public class SplitPartFunc implements DrillSimpleFunc {

    VarCharHolder input;

    @Param(constant = true)
    VarCharHolder delimiter;

    @Param(constant = true)
    IntHolder field;

    NullableVarCharHolder out;

    DrillBuf buffer;

    public void setup() {

    public void eval() {

        String stringValue = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(input.start,
input.end, input.buffer);

        out.buffer = buffer; //If I return before this statement, a NPE is thrown :(
        if(stringValue == null){

        int fieldValue = field.value;
        if(fieldValue <= 0){

        String delimiterValue = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(delimiter.start,
delimiter.end, delimiter.buffer);
        if(delimiterValue == null){

        String[] splittedInput = stringValue.split(delimiterValue);
        if(splittedInput.length < fieldValue){

        // put the output value in the out buffer
        String outputValue = splittedInput[fieldValue - 1];
        out.start = 0;
        out.end = outputValue.getBytes().length;
        buffer.setBytes(0, outputValue.getBytes());
        out.isSet = 1;


If I run the following query on the sample employees.json file (or actually a parquet, after
modifying the table and columns names)

{code:title=SQL Query|borderStyle=solid}SELECT full_name, split_string(full_name, ' ', 4),
split_string('Whatever', ' ', 4) FROM cp.employee.json LIMIT 1{code}

I get the following result

Shouldn't I be getting the column value and null for the other 2 columns ?

This message was sent by Atlassian JIRA

View raw message