Handling Cancel Requests

The query that calls your UDx can be canceled (usually, by the user pressing CTRL+C in vsql). When the calling query is canceled, Vertica begins a process of shutting down your UDx. Since UDTFs can perform lengthy and costly processing, the Vertica Java SDK defines several ways that Vertica attempts to signal UDTFs to terminate before it takes the step of killing the fenced-mode JVM process that is executing the UDTF. These attempts to signal the UDTF can help reduce the amount of CPU and memory that is wasted by having the UDx process continue processing after its results are no longer required.

When the user cancels a UDx, Vertica takes the following steps:

  1. It sets the isCanceled property on UDTFs to true. Your processPartition methods can test this property to see if the function call has been canceled.
  2. It calls UDTF's TransformFunction.cancel method. You should override this method to perform any shutdown tasks (such as killing threads).
  3. It calls all types of UDx's destroy method. You should implement this method to free any resources your UDx has allocated.
  4. It kills the JVM process running your UDx.

The topics in this section explain how your UDTF can use the cancel API.

In This Section