Debugging Tips

You must thoroughly debug your UDx before deploying it to a production environment. The following tips can help you get your UDx ready for deployment.

Use a Single Node For Initial Debugging

You can attach to the Vertica process using a debugger such as gdb to debug your UDx code. Doing this in a multi-node environment, however, is very difficult. Therefore, consider setting up a single-node Vertica test environment to initially debug your UDx.

Write Messages to the Vertica Log

You can write to log files using the ServerInterface.log function. Every function in your UDx receives an instance of the ServerInterface object, so you can call the log function from anywhere in your UDx. The function acts similarly to printf, taking a formatted string, and an optional set of values and writing the string to a log file. Where the message is written depends on whether your function runs in fenced mode or unfenced mode:

To help identify your function's output, Vertica adds the SQL function name bound to your UDx function to the log message.

The following code fragment shows how you can add a call to srvInterface.log in the Add2ints example code's processBlock() function to log its input values:

const vint a = arg_reader.getIntRef(0);
const vint b = arg_reader.getIntRef(1);
srvInterface.log("got a: %d and b: %d", (int) a, (int) b);

This code generates an entries in the log file for each row the UDx processes. For example:

11-05-06 14:37:20.838 nameless:0x3f3a210 [UserMessage] <UDx> Add2ints - got a: 1 and b: 2
11-05-06 14:37:20.838 nameless:0x3f3a210 [UserMessage] <UDx> Add2ints - got a: 2 and b: 2
11-05-06 14:37:20.838 nameless:0x3f3a210 [UserMessage] <UDx> Add2ints - got a: 3 and b: 2
11-05-06 14:37:20.838 nameless:0x3f3a210 [UserMessage] <UDx> Add2ints - got a: 1 and b: 4
11-05-06 14:37:20.838 nameless:0x3f3a210 [UserMessage] <UDx> Add2ints - got a: 5 and b: 2

See Monitoring the Log Files in the Administrator's Guide for details on viewing the Vertica log files.