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

相关推荐
不吃饭的猪1 天前
clickhouse-20版本安装部署
数据库·mysql·clickhouse
lhyzws1 天前
CENTOS上的网络安全工具(三十五)Portainer Kafka-Clickhouse部署 Flink安装部署与编程
clickhouse·flink·kafka
一瓢西湖水4 天前
列式数据库-以clickHouse为例
数据库·clickhouse
zhglhy4 天前
ClickHouse高性能技术解析
clickhouse
恒悦sunsite7 天前
clickhouse之clickhouse-client命令简介和使用
clickhouse·client·列式数据库·客户端命令·ctyunos
言之。9 天前
Python调用DeepSeek API查询ClickHouse
windows·python·clickhouse
zhglhy10 天前
ckman将单节点ClickHouse转为集群方案
clickhouse·ckman
葡萄月令with蒲公英11 天前
使用clickhouse_connect从csv导入数据到clickhouse报错
clickhouse
韩金群13 天前
centos离线安装配置clickhouse
linux·clickhouse·centos
谷新龙00116 天前
pg_clickhouse插件,在postgresql中借助clickhouse借用OLAP能力
数据库·clickhouse·postgresql