Skip to content

12-UDFs

Udf for C language
1. Compile UDF C code
2. Create scalar UDF function bit_and
3. Create aggregate UDF function l2norm
4. Test scalar UDF function bit_and

Udf config 1
1. prepare udf so files
2. prepare data for udf
2. create udf functions
3. basic udf query test
4. exception test for udf functions
5. drop udf functions

Udf config 2
1. prepare udf so files
2. prepare data for udf
3. create udf functions
4. basic udf query test
5. multi columns udf functions
6. try query sqls for udf functions
7. loop kill taosudf and query udf functions
8. restart taosd and query udf functions
9. drop and create udf functions without bufsize and without aggregate
10. try query sqls for udf functions
11. error create udf functions
12. drop udf functions

Udf function create
1. prepare udf so files
2. prepare data for udf
3. create udf functions
4. basic udf query test
5. multi columns udf functions
6. try query sqls for udf functions
7. loop kill taosudf and query udf functions
8. restart taosd and query udf functions
9. drop and create udf functions without bufsize and without aggregate
10. try query sqls for udf functions
11. error create udf functions
12. drop udf functions

Udf basic for python
1. Use built-in taospyudf plugin from TDengine installation
2. Create stable and child tables
3. Create scalar udfpy functions concat
4. Create aggregate udfpy functions min, sum, count
5. Insert data to child tables
6. Query scalar udfpy functions
7. Query aggregate udfpy functions
8. Verify all operations are successful

Udf python sim case
1. Create database and normal table for udf test
2. Create scalar UDF function bit_and with python file
3. Create aggregate UDF function l2norm with python file
4. Insert data into normal table
5. Query scalar UDF function bit_and from normal table
6. Query aggregate UDF function l2norm from normal table
7. Test UDF with null values
8. Test UDF with multiple columns

Udf restart taosd
1. prepare udf so library
2. prepare data
3. create udf functions
4. basic udf query test
5. multi columns udf test
6. restart taosd and query udf functions

perm_entropy aggregate UDF – accumulate-all-data-then-compute pattern
perm_entropy is a special aggregate UDF: it cannot produce any result
until ALL rows in the window have been delivered. During processing
(AGG_PROC calls) it only accumulates values into a heap-allocated array
carried inside the intermediate buffer. The actual permutation-entropy
computation happens entirely inside perm_entropy_finish after all data
has been collected.
Tests:
1. Locate libperm_entropy.so in the build tree.
2. Create a database with monotonically increasing and mixed data.
3. Register the perm_entropy aggregate UDF (BUFSIZE 256).
4. Verify correctness:
- Monotonically increasing data → entropy = 0.0 (single permutation pattern).
- Fewer rows than embed_dim (5) → NULL result (no result).
- Interval window partitioning → each window returns its own entropy.
5. Verify the UDF survives a taosd restart and returns the same results.

perm_entropy aggregate UDF – repeated queries to exercise accumulate/finish path.
Runs REPEAT_ROUNDS of diverse aggregate queries (supertable partition,
interval window, single-table) to verify correctness across repeated calls.
Memory leak detection is handled by ASAN on taosd shutdown.
Tests:
1. Register perm_entropy UDF from the build tree.
2. Insert synthetic data into a supertable with multiple child tables.
3. Run REPEAT_ROUNDS of aggregate queries and verify results are correct.

Udf kill taosudf process
1. Test command "taosudf -c" and "taosudf -V"
2. Prepare udf so files
3. Prepare data
4. Run unexpected using of udf functions
5. Create udf functions
6. Run change udf so file and query
7. Basic udf query test
8. Loop kill taosudf process and query udf functions
9. Test function name is not built-in functions

Udf C for const
1. Create database and normal table for udf test
2. Create function gpd with C code that has const parameter
3. Insert data into normal table
4. Query function gpd with const parameter from normal table