Raising exceptions#
Exceptions in HeavyDB are quite different from the ones used in Python. In RBC
code, you signal to the database an exception happened by calling a specific
method (error_message
) in the runner manager.
In a UDF:#
It is currently not possible to raise an exception in a UDF. The server must implement support for it first before RBC can support it.
In a UDTF#
1@heavydb('int32(TableFunctionManager, Column<int64>, OutputColumn<int64>)')
2def udtf_copy(mgr, inp, out):
3 size = len(inp)
4 if size > 4:
5 # error message must be known at compile-time
6 return mgr.error_message('TableFunctionManager error_message!')
7
8 mgr.set_output_row_size(size)
9 for i in range(size):
10 out[i] = inp[i]
11 return size
Example SQL Query
1query = '''
2 SELECT * FROM TABLE(udtf_copy(
3 cursor(SELECT * FROM TABLE(generate_series(1, 5, 1)))
4 ));
5'''
6
7with pytest.raises(HeavyDBServerError) as exc:
8 heavydb.sql_execute(query)
9exc_msg = ('Error executing table function: TableFunctionManager '
10 'error_message!')
11assert exc.match(exc_msg)