ClickHouse UDF 官方示例Example报错解决方案

目录

一、环境版本

环境 版本
docker clickhouse 22.3.10.22
shell 复制代码
docker pull clickhouse/clickhouse-server:22.3.10.22

二、官方示例

官网文档

test_function使用 XML 配置创建。文件test_function.xml/etc/clickhouse-server/test_function.xml使用默认路径设置)。

xml 复制代码
<functions>
    <function>
        <type>executable</type>
        <name>test_function_python</name>
        <return_type>String</return_type>
        <argument>
            <type>UInt64</type>
            <name>value</name>
        </argument>
        <format>TabSeparated</format>
        <command>test_function.py</command>
    </function>
</functions>

user_scripts文件夹内的脚本文件test_function.py/var/lib/clickhouse/user_scripts/test_function.py使用默认路径设置)。

python 复制代码
#!/usr/bin/python3

import sys

if __name__ == '__main__':
    for line in sys.stdin:
        print("Value " + line, end='')
        sys.stdout.flush()

询问:

sql 复制代码
SELECT test_function_python(toUInt64(2));

报错:

shell 复制代码
Code: 75. DB::ErrnoException: Cannot write into pipe , errno: 32, strerror: Broken pipe: While executing TabSeparatedRowOutputFormat: While processing test_function_python(toUInt64(2)). (CANNOT_WRITE_TO_FILE_DESCRIPTOR) (version 22.3.10.22 (official build)) , server ClickHouseNode [uri=http://localhost:8123/default, options={custom_http_params=session_id=DataGrip_3dcf30c1-e0d2-4f93-8c21-7fc99420db96}]@-1444910710

执行:

sql 复制代码
SYSTEM RELOAD FUNCTIONS;
SELECT * FROM system.functions WHERE name = 'test_function_python';

发现函数已添加,却依旧运行报错

三、解决方案

1.Python脚本运行缺少权限

shell 复制代码
chmod a+x /var/lib/clickhouse/user_scripts/test_function.py

2. 缺少Python3运行环境

官方镜像中缺少Python3运行环境,需单独安装

shell 复制代码
apt update
apt install python3

四、参考借鉴

Github Issues

相关推荐
言之。3 天前
简单介绍一下Clickhouse及其引擎
clickhouse
西京刀客3 天前
clickhouse的UInt64类型(countIf() 函数返回)
clickhouse·uint64·countif
Super_King_4 天前
ClickHouse 中 ORDER BY 场景下 arrayExists 与 hasAny 性能深入研究:布隆过滤器索引的影响分析
clickhouse
Super_King_4 天前
深入研究:ClickHouse中arrayExists与hasAny在ORDER BY场景下的性能差异
clickhouse
-KamMinG4 天前
阿里云ClickHouse数据保护秘籍:本地备份与恢复详解
clickhouse·阿里云·云计算
问道飞鱼4 天前
【大数据相关】ClickHouse命令行与SQL语法详解
大数据·sql·clickhouse
MMMMMMMMMMemory9 天前
clickhouse迁移工具clickhouse-copier
clickhouse
securitor9 天前
【clickhouse】设置密码
clickhouse
天道有情战天下12 天前
ClickHouse使用Docker部署
clickhouse·docker·容器