Revert "docs: move udf sample code to examples (#33877)" (#33881)

This reverts commit 201a90d696.
This commit is contained in:
haoranchen 2025-12-10 17:28:46 +08:00 committed by GitHub
parent 201a90d696
commit b45572eb60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 37 additions and 38 deletions

View file

@ -10,7 +10,6 @@ on:
paths-ignore:
- 'packaging/**'
- 'docs/**'
- '!docs/examples/**'
- 'tools/tdgpt/**'
- 'source/libs/executor/src/forecastoperator.c'
- 'source/libs/executor/src/anomalywindowoperator.c'

View file

@ -241,7 +241,7 @@ To better operate the above data structures, some convenience functions are prov
### C UDF Example Code
#### Scalar Function Example
#### Scalar Function Example [bit_and](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/bit_and.c)
`bit_and` implements the bitwise AND function for multiple columns. If there is only one column, it returns that column. `bit_and` ignores null values.
@ -249,12 +249,12 @@ To better operate the above data structures, some convenience functions are prov
<summary>bit_and.c</summary>
```c
{{#include docs/examples/udf/bit_and.c}}
{{#include tests/script/sh/bit_and.c}}
```
</details>
#### Aggregate Function Example 1 Returning Numeric Type
#### Aggregate Function Example 1 Returning Numeric Type [l2norm](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/l2norm.c)
`l2norm` implements the second-order norm of all data in the input columns, i.e., squaring each data point, then summing them up, and finally taking the square root.
@ -262,12 +262,12 @@ To better operate the above data structures, some convenience functions are prov
<summary>l2norm.c</summary>
```c
{{#include docs/examples/udf/l2norm.c}}
{{#include tests/script/sh/l2norm.c}}
```
</details>
#### Aggregate Function Example 2 Returning String Type
#### Aggregate Function Example 2 Returning String Type [max_vol](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/max_vol.c)
`max_vol` implements finding the maximum voltage from multiple input voltage columns, returning a composite string value consisting of the device ID + the position (row, column) of the maximum voltage + the maximum voltage value.
@ -293,12 +293,12 @@ select max_vol(vol1, vol2, vol3, deviceid) from battery;
<summary>max_vol.c</summary>
```c
{{#include docs/examples/udf/max_vol.c}}
{{#include tests/script/sh/max_vol.c}}
```
</details>
#### Aggregate Function Example 3 Split string and calculate average value
#### Aggregate Function Example 3 Split string and calculate average value [extract_avg](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/extract_avg.c)
The `extract_avg` function converts a comma-separated string sequence into a set of numerical values, counts the results of all rows, and calculates the final average. Note when implementing:
@ -327,14 +327,14 @@ select extract_avg(valStr) from scores;
Generate `.so` file
```bash
gcc -g -O0 -fPIC -shared extract_avg.c -o libextract_avg.so
gcc -g -O0 -fPIC -shared extract_vag.c -o libextract_avg.so
```
<details>
<summary>extract_avg.c</summary>
<summary>max_vol.c</summary>
```c
{{#include docs/examples/udf/extract_avg.c}}
{{#include tests/script/sh/max_vol.c}}
```
</details>
@ -866,7 +866,7 @@ Through this example, we learned how to define aggregate functions and print cus
### More Python UDF Example Code
#### Scalar Function Example
#### Scalar Function Example [pybitand](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pybitand.py)
`pybitand` implements the bitwise AND function for multiple columns. If there is only one column, it returns that column. `pybitand` ignores null values.
@ -874,32 +874,32 @@ Through this example, we learned how to define aggregate functions and print cus
<summary>pybitand.py</summary>
```python
{{#include docs/examples/udf/pybitand.py}}
{{#include tests/script/sh/pybitand.py}}
```
</details>
#### Aggregate Function Example
#### Aggregate Function Example [pyl2norm](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pyl2norm.py)
`pyl2norm` calculates the second-order norm of all data in the input column, i.e., squares each data point, then sums them up, and finally takes the square root.
<details>
<summary>pyl2norm.py</summary>
```python
{{#include docs/examples/udf/pyl2norm.py}}
```c
{{#include tests/script/sh/pyl2norm.py}}
```
</details>
#### Aggregate Function Example
#### Aggregate Function Example [pycumsum](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pycumsum.py)
`pycumsum` uses numpy to calculate the cumulative sum of all data in the input column.
<details>
<summary>pycumsum.py</summary>
```python
{{#include docs/examples/udf/pycumsum.py}}
```c
{{#include tests/script/sh/pycumsum.py}}
```
</details>

View file

@ -245,7 +245,7 @@ typedef struct SUdfInterBuf {
### C UDF 示例代码
#### 标量函数示例
#### 标量函数示例 [bit_and](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/bit_and.c)
bit_and 实现多列的按位与功能。如果只有一列返回这一列。bit_and 忽略空值。
@ -253,12 +253,12 @@ bit_and 实现多列的按位与功能。如果只有一列,返回这一列。
<summary>bit_and.c</summary>
```c
{{#include docs/examples/udf/bit_and.c}}
{{#include tests/script/sh/bit_and.c}}
```
</details>
#### 聚合函数示例 1 返回值为数值类型
#### 聚合函数示例 1 返回值为数值类型 [l2norm](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/l2norm.c)
l2norm 实现了输入列的所有数据的二阶范数,即对每个数据先平方,再累加求和,最后开方。
@ -266,12 +266,12 @@ l2norm 实现了输入列的所有数据的二阶范数,即对每个数据先
<summary>l2norm.c</summary>
```c
{{#include docs/examples/udf/l2norm.c}}
{{#include tests/script/sh/l2norm.c}}
```
</details>
#### 聚合函数示例 2 返回值为字符串类型
#### 聚合函数示例 2 返回值为字符串类型 [max_vol](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/max_vol.c)
max_vol 实现了从多个输入的电压列中找到最大电压,返回由设备 ID + 最大电压所在(行,列)+ 最大电压值 组成的组合字符串值
@ -297,12 +297,12 @@ select max_vol(vol1, vol2, vol3, deviceid) from battery;
<summary>max_vol.c</summary>
```c
{{#include docs/examples/udf/max_vol.c}}
{{#include tests/script/sh/max_vol.c}}
```
</details>
#### 聚合函数示例 3 切分字符串求平均值
#### 聚合函数示例 3 切分字符串求平均值 [extract_avg](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/extract_avg.c)
`extract_avg` 函数是将一个逗号分隔的字符串数列转为一组数值,统计所有行的结果,计算最终平均值。实现时需注意:
@ -338,7 +338,7 @@ gcc -g -O0 -fPIC -shared extract_vag.c -o libextract_avg.so
<summary>extract_avg.c</summary>
```c
{{#include docs/examples/udf/extract_avg.c}}
{{#include tests/script/sh/extract_avg.c}}
```
</details>
@ -346,7 +346,7 @@ gcc -g -O0 -fPIC -shared extract_vag.c -o libextract_avg.so
## 用 Python 语言开发 UDF
### 准备环境
准备环境的具体步骤如下:
- 第 1 步,准备好 Python 运行环境。本地编译安装 python 注意打开 `--enable-shared` 选项,不然后续安装 taospyudf 会因无法生成共享库而导致失败。
@ -869,40 +869,40 @@ close log file: spread.log
### 更多 Python UDF 示例代码
#### 标量函数示例
#### 标量函数示例 [pybitand](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pybitand.py)
pybitand 实现多列的按位与功能。如果只有一列返回这一列。pybitand 忽略空值。
<details>
<summary>pybitand.py</summary>
```python
{{#include docs/examples/udf/pybitand.py}}
```Python
{{#include tests/script/sh/pybitand.py}}
```
</details>
#### 聚合函数示例
#### 聚合函数示例 [pyl2norm](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pyl2norm.py)
pyl2norm 实现了输入列的所有数据的二阶范数,即对每个数据先平方,再累加求和,最后开方。
<details>
<summary>pyl2norm.py</summary>
```python
{{#include docs/examples/udf/pyl2norm.py}}
```c
{{#include tests/script/sh/pyl2norm.py}}
```
</details>
#### 聚合函数示例
#### 聚合函数示例 [pycumsum](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/pycumsum.py)
pycumsum 使用 numpy 计算输入列所有数据的累积和。
<details>
<summary>pycumsum.py</summary>
```python
{{#include docs/examples/udf/pycumsum.py}}
```c
{{#include tests/script/sh/pycumsum.py}}
```
</details>
@ -965,7 +965,7 @@ show functions;
```
### 查看函数信息
同名的 UDF 每更新一次,版本号会增加 1。
```sql