This topic describes the usage and limits of Java user-defined table functions (UDTFs) and Python UDTFs.
The following statements provide examples to show typical use cases of UDTFs in MaxCompute SQL:
select user_udtf(col0, col1, col2) as (c0, c1) from my_table; select user_udtf(col0, col1, col2) as (c0, c1) from (select * from my_table distribute by key sort by key) t; select reduce_udtf(col0, col1, col2) as (c0, c1) from (select col0, col1, col2 from (select map_udtf(a0, a1, a2, a3) as (col0, col1, col2) from my_table) t1 distribute by col0 sort by col0, col1) t2;
When you use UDTFs, take note of the following limits:
SELECTclause cannot contain other expressions.
select value, user_udtf(key) as mycol ...
- A UDTF cannot be nested.
select user_udtf1(user_udtf2(key)) as mycol...
SELECTclause cannot be used with a
DISTRIBUTE BY, or
select user_udtf(key) as mycol ... group by mycol;