We're Moving!

The Vertica Forum is moving to a new OpenText Analytics Database (Vertica) Community.

Join us there to post discussion topics, learn about

product releases, share tips, access the blog, and much more.

Create My New Community Account Now


Issue with Vertica UDF (Scalar function) — Vertica Forum

Issue with Vertica UDF (Scalar function)

I was develping a USDF (user defined scalar function) in java for Vertica Analytic Database v7.1.2-5.

I was running it like : select dec_udf(c1) from test_table;

Table is like : create table test_table(c1 varchar(100));

 

The UDF is running fine for some rows(of this table), but it is not picking other rows. The processBlock method is not being entered for those rows. 

 

Code : 

public class MyFunctionFactory extends ScalarFunctionFactory {


public MyFunctionFactory() {
// Tell HP Vertica that any NULL arguments results in a NULL return value
strict = strictness.RETURN_NULL_ON_NULL_INPUT;
}


@Override
public void getPrototype(ServerInterface serverInterface, ColumnTypes argTypes,ColumnTypes returnType) {
argTypes.addLongVarchar();
returnType.addLongVarchar();
}

public void getReturnType(ServerInterface srvInterface, SizedColumnTypes argTypes,
SizedColumnTypes returnType) {
returnType.addLongVarchar(500);
}


@Override
public ScalarFunction createScalarFunction(ServerInterface serverInterface) {
serverInterface.log("Inside CreateScalarFunction");
return new MyFunction(serverInterface);
}

public class MyFunction extends ScalarFunction {
String text=null;
boolean val=true;

MyFunction(ServerInterface serverInterface){
serverInterface.log("Inside MyFunction constructor");
}

@Override
public void setup(ServerInterface serverInterface, SizedColumnTypes sizedColumnTypes) {
//some initialization
serverInterface.log("Exiting setup method");
}

@Override
public void processBlock(ServerInterface srvInterface, BlockReader argReader, BlockWriter resWriter)
{

srvInterface.log("Entered the process block");
try {
int i = 0;
srvInterface.log("no. of rows to be processed are :"+argReader.getNumRows());
do {
// The input and output objects have already loaded
// the first row, so you can start reading and writing
// values immediately.

// Get the argument from the BlockReader
srvInterface.log("Entered the process block do-while");
srvInterface.log("ROW NUM : " + ++i);
srvInterface.log("no. of columns to be processed are :"+argReader.getNumCols());
encryptedText = argReader.getString(0);
srvInterface.log("First row of Text = " + text);
srvInterface.log("Length of first row = " + argReader.getStringLength(0));


// Process the arguments and come up with a result. For this
// example, just add the two arguments together.


resWriter.setString(text);

// Advance the output BlocKWriter to the next row.
resWriter.next();
// Continue processing input rows until there are no more.


val = argReader.next();
if(val == false){
srvInterface.log("no input to process next");
}
srvInterface.log("current value is : "+val);
} while (val);
}catch(UdfException udfexception){
srvInterface.log("UDF Exception here : " + udfexception);
}
catch (DestroyInvocation destroyInvocation){
srvInterface.log("Destroy Invocation Exception here : " + destroyInvocation);
}
catch(Throwable e){
srvInterface.log("encountered unknown exception. " + e.getMessage());
}
srvInterface.log("Exiting this process block method");
}

}

 

test_table : 

 

id   | c1
----+-----------------------
1   | somedataisthere

 

 

 

Logs : 

2015-12-31 00:22:51.605 [Java-29849] 0x0b [UserMessage] dec_udf - Inside CreateScalarFunction
2015-12-31 00:22:51.607 [Java-29849] 0x0b [UserMessage] dec_udf  - Inside MyFunction constructor
2015-12-31 00:22:51.607 [Java-29849] 0x0b [UserMessage] dec_udf  - Entered inside setup method
2015-12-31 00:22:52.490 [Java-29849] 0x0b [UserMessage] dec_udf  - Exiting setup method
2015-12-31 00:22:55.933 [Java-29849] 0x0a Socket closed successfully
2015-12-31 00:22:55.936 [Java-29849] 0x0c Exiting UDx side process

 

Why is it not entering the processBlock method for the row in that table? When I tried testing it on another table, with same data, the processBlock is entering for that. Why is it behaving non-deterministically?

 

Please help me resolve this.Thanks.

Comments

  • Madhura,

     

    Please file a support case for this question:

     

    If you already have a MyVertica account, login to MyVertica to file or track a support ticket.

     

    If you are a Vertica customer, but need a MyVertica account, just complete the form located on the Customer Sign-Up Form page.

     

    Thanks,

     

    Sarah L

  • Hi Sarah L,

     

    This issue got resolved, apparently the some node was down when I was running this. Now it is woking fine. How to close this issue? I couldn't see any option like that, please let me know where it is.

     

    Thanks for your response.

     

    Madhura


    SarahL wrote:

    Madhura,

     

    Please file a support case for this question:

     

    If you already have a MyVertica account, login to MyVertica to file or track a support ticket.

     

    If you are a Vertica customer, but need a MyVertica account, just complete the form located on the Customer Sign-Up Form page.

     

    Thanks,

     

    Sarah L


     

  • @Sarah L, But I still have a point of confusion on why it is not logging the statements properly? For each row, the process-Block method should have been invoked but from the logs, it doesnt seem like, process block is called.

     

    These are the relevant logs : 

     

    2016-01-03 20:56:20.355 [Java-2281] 0x01 UDx side process (Java) started
    2016-01-03 20:56:20.580 [Java-2281] 0x0a Loading VerticaClassLoader
    2016-01-03 20:56:21.120 [Java-2281] 0x0b [UserMessage] myfunction - Inside CreateScalarFunction
    2016-01-03 20:56:21.121 [Java-2281] 0x0b [UserMessage] myfunction - Inside MyFunction constructor
    2016-01-03 20:56:21.122 [Java-2281] 0x0b [UserMessage] myfunction - Exiting setup method
    2016-01-03 20:56:25.545 [Java-2281] 0x0a Socket closed successfully
    2016-01-03 20:56:25.548 [Java-2281] 0x0c Exiting UDx side process

     

    It should log this

    srvInterface.log("Entered the process block");  

     

    Am I not understading correctly? process-block method doesnt trigger for each row? If not, why it is missing the logs?

     

    I am new to Vertica, any help would be appreciated.Thanks.

     

    Madhura

  • Madhura,

     

    I am not the right person to answer this question, but if you file a support case, you will get a prompt response from our excellent support team.

     

    Try the links in my previous response to open a case.

     

    Sarah

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file