Table functions¶
The following functions operate on tables.
table_split()¶
Splits a table into multiple sub-tables and returns a list containing the sub-tables. This is useful for parallel processing or batch operations on large datasets.
Null behavior: default
Function signature¶
table_split(t: TABLE) -> LIST
or
table_split(t: TABLE, size: UINT64) -> LIST
t: The variable of the table to be split.size: The value expression that evaluates to the maximum number of rows per sub-table (the last sub-table may contain fewer rows). If not specified, the system automatically determines split boundaries based on memory distribution. The value ofsizemust be a positive integer.
Examples¶
Split a table and count total rows¶
'''
TABLE result_table TYPED TABLE {i INT, j INT}
FOR i IN range(1, 100)
FOR j IN range(1, 100)
EXPORT i, j INTO result_table
FOR t IN table_split(result_table)
RETURN sum(size(t))
'''
Return:
+--------------+
| sum(size(t)) |
+--------------+
| 10000 |
+--------------+
Split a table with a specified size¶
'''
TABLE result_table TYPED TABLE {i INT, j INT}
FOR i IN range(1, 5)
FOR j IN range(1, 5)
EXPORT i, j INTO result_table
FOR t IN table_split(result_table, cast(10 as UINT))
RETURN size(t)
'''
Return:
+---------+
| size(t) |
+---------+
| 10 |
| 10 |
| 5 |
+---------+
The table contains 25 rows (5 * 5) and is split into three sub-tables: two with 10 rows each, and one with 5 rows.
Iterate over rows in sub-tables¶
'''
TABLE result_table TYPED TABLE {i INT, j INT}
FOR i IN range(1, 3)
FOR j IN range(1, 3)
EXPORT i, j INTO result_table
FOR t IN table_split(result_table)
FOR r IN t
RETURN r.i as i, r.j as j
'''
Return:
+---+---+
| i | j |
+---+---+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 3 | 1 |
| 3 | 2 |
| 3 | 3 |
+---+---+