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

相关推荐
知其_所以然18 小时前
使用docker安装clickhouse集群
clickhouse·docker·容器
wuli玉shell1 天前
Doris和Clickhouse对比
clickhouse·doris
SelectDB技术团队4 天前
可观测性方案怎么选?SelectDB vs Elasticsearch vs ClickHouse
大数据·数据仓库·clickhouse·elasticsearch·信息可视化·doris·半结构化
goTsHgo4 天前
ClickHouse多表join的性能优化:原理与源码详解
clickhouse·性能优化
妖果yaoyao6 天前
docker 部署clickhouse
clickhouse·docker·容器
鱼鱼不愚与7 天前
处理 Clickhouse 内存溢出
数据库·分布式·clickhouse
Wonderful_一直有你7 天前
clickhouse - 重新建表覆盖旧表-解决分区时间错误问题-197001
clickhouse
千月落10 天前
ClickHouse副本集群
服务器·数据库·clickhouse
Steven-Russell10 天前
Clickhouse基于breakpad生成minidump文件,方便问题定位
clickhouse·breakpad
涤生大数据11 天前
海量数据存储与分析:HBase vs ClickHouse vs Doris 三大数据库优劣对比指南
数据库·clickhouse·hbase