Madhura Pande
Madhura Pande

Reputation: 59

Error when running Vertica UDSF

I am trying to create a User-defined Scalar Function (UDSF) in vertica, so I am extending ScalarFunctionFactory and ScalarFunction classes(from vertica sdk). The compulsory override method for extending ScalarFunction is defined as follows :

 public void getPrototype(ServerInterface serverInterface, ColumnTypes argTypes,ColumnTypes returnType) {
    argTypes.addLongVarchar(); // varchar input argument 1
    argTypes.addLongVarchar(); // varchar input argument 2
    returnType.addLongVarchar(); //varchar output
}

I created a library and a function for this(referring vertica documentation on deploying a UDSF), but when tried running it, I got the following error :

Failure in UDx RPC call InvokeGetReturnType(): Error in User Defined Object [my_udf], error code: 0 The data type requires length/precision specification.

I tried to set the length of arguments but that requires argTypes to be of the 'SizedColumnTypes' type rather than 'ColumnTypes' which is the required signature for getPrototype as it is the compulsory override. It would be really helpful if someone suggests a solution on this.

Upvotes: 0

Views: 212

Answers (1)

mauro
mauro

Reputation: 5950

Max length of the output string is defined using getReturnType(). Example:

virtual void getPrototype(ServerInterface &interface,
                          ColumnTypes &argTypes,
                          ColumnTypes &returnType)
{
    argTypes.addVarchar();
    argTypes.addVarchar();
    returnType.addVarchar();
}

virtual void getReturnType(ServerInterface &srvInterface, 
                           const SizedColumnTypes &inputTypes, 
                           SizedColumnTypes &outputTypes)
{
    int len1 = inputTypes.getColumnType(1).getStringLength();
    int len2 = inputTypes.getColumnType(2).getStringLength();

    // Output size as sum of input string sizes:
    outputTypes.addVarchar(len1+len2, "column");
}

Upvotes: 1

Related Questions