网站首页 > 技术文章 正文
在新版本中,该特性又得到了增强,现在进一步支持执行本地文件脚本或者预先定义的 shell 命令。
接下来让我们快速了解该功能如何使用。
首先,在 config.xml 文件中添加如下配置:
<user_defined_executable_functions_config>*_function.xml</user_defined_executable_functions_config>
该配置用于匹配 Executable UDF 的定义文件。
接着,在 user_files 目录下,创建一个函数定义文件 test_executable_udf.xml :
<functions>
<function>
<type>executable</type>
<name>test_executable_udf</name>
<return_type>String</return_type>
<argument>
<type>UInt64</type>
</argument>
<format>TabSeparated</format>
<command>test_executable_udf.py</command>
</function>
</functions>
最后,在 user_scripts 目录下,放入需要执行的脚本文件,例如
test_executable_udf.py :
#!/usr/bin/python3
import sys
if __name__ == '__main__':
for line in sys.stdin:
print("UDF Value is : " + line, end='')
sys.stdout.flush()
全部搞定之后,我们就能在 ClickHouse 中调用脚本函数了:
SELECT test_executable_udf(toUInt64(2))
如果想执行 Shell 命令,则只需将 *_function.xml 配置文件中,<command> 内的文件名替换成命令文本,并增加 execute_direct 参数,例如:
<command>
cd/; clickhouse-local --input-format TabSeparated --output-formatTabSeparated --structure
'x UInt64, y UInt64'
--query "SELECT x + y FROM table"
</command>
<execute_direct>0</execute_direct>
相关的 PR 地址如下:
https://github.com/ClickHouse/ClickHouse/pull/28803
- 上一篇: 24.函数说明文档(excel函数说明文档)
- 下一篇: 非典型算法题,用程序和电脑玩一个游戏
猜你喜欢
- 2024-10-01 利用神经网络模型检测摄像头上的可疑行为
- 2024-10-01 使用神经网络的自动化特征工程(神经网络的特点及使用场景)
- 2024-10-01 Python基础学习必备的8个最常用的内置函数
- 2024-10-01 利用Click和argparse给你Python程序构建一个优雅的命令行界面
- 2024-10-01 langchain中的LLM模型使用介绍(llvm 分析)
- 2024-10-01 学习Python内置函数(range)来打印数学乘法表
- 2024-10-01 Python 100天 15:print("hello world")茴香豆的写法
- 2024-10-01 python3入门实例一:Hello World(python的hello world程序编写)
- 2024-10-01 python基础篇:讲讲python的内置函数一
- 2024-10-01 Python3中的print函数(python里的print函数)
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)