Query cancel support
UDFs must periodically check the cancelled queries. If the cancelled queries are not checked, they cannot be terminated by the user and may appear to be “hung”. Simple UDFs can forgo query cancel checking assuming there are no loops or other language constructions that never return. The query cancel procedure is identical for both Python and Javascript.
Add the following statement to your UDF and call it periodically:
vectorwise.cancel_check()
In both the languages, the call will throw an exception if the query has been cancelled by the user. This exception will cause the UDF to terminate and the query will end. The UDF code can catch this exception and if it does, it should either rethrow the exception or ensure that the UDF exits immediately.
Here is an example of how to use the function. These examples will hang and demonstrate how to cancel the query using the function.
Python:
CREATE OR REPLACE FUNCTION loop(i int not null)
return (int not null) AS language python
source='
while i:
i += 1
vectorwise.check_cancel()
return i';
Java:
CREATE OR REPLACE FUNCTION loop(i int not null)
return (int not null) AS language javascript
source='
while (true)
{ vectorwise.check_cancel(); }
return 1;';\g
Last modified date: 12/19/2024