Updated on 2025-12-19 GMT+08:00

UDTF

The development process for a UDTF is similar to that of a scalar UDF, with the following key considerations:

  • The handler currently only supports returning iterators, so using yield is recommended.
  • UDTFs do not support concurrent execution or vectorized computation.
  • If the handler enters an infinite loop or produces endless output, Fabric SQL will automatically terminate the program based on the timeout setting, which defaults to 1,000 seconds.

Example

  1. Create a UDTF.
    CREATE FUNCTION py_generate_series(start int, endnum int, step int)
    RETURNS TABLE(a int)
    LANGUAGE python
    RUNTIME_VERSION='3.11.2'
    HANDLER='generate_series'
    as $$
    def generate_series(start, endnum, step):
        current = start
        while current <= endnum:
            yield current
            current += step
    $$;
  2. Execute the UDTF.
    SELECT py_generate_series(1,4,1);
     py_generate_series 
    ----------------------
                        1
                        2
                        3
                        4
    (4 rows)