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

相关推荐
4t4run4 天前
1、clickhouse 安装
数据库·clickhouse
JackSparrow4145 天前
使用Elasticsearch代替数据库like以加快查询的各种技术方案+实现细节
大数据·clickhouse·elk·elasticsearch·搜索引擎·postgresql·全文检索
梦想与想象-广州大智汇12 天前
MySQL 同步数据到 ClickHouse 方案对比分析
数据库·mysql·clickhouse
Smile_25422041813 天前
clickhouse日志疯涨问题
linux·运维·服务器·clickhouse
计算机魔术师13 天前
【技术硬核 | 存储】ClickHouse 原理与 Langfuse 存储实践:当 LLM Trace 爆炸时,PG 还扛得住吗?
人工智能·clickhouse·工程实践·sbti·职场焦虑
fire-flyer16 天前
ClickHouse系列(九):慢查询、内存 OOM 与稳定性治理
android·clickhouse
fire-flyer16 天前
ClickHouse系列(十):生产架构与最佳实践总结
clickhouse·架构
fire-flyer17 天前
ClickHouse系列(八):ClickHouse 的 UPDATE / DELETE 正确姿势
大数据·数据库·clickhouse
fire-flyer17 天前
ClickHouse系列(七):Materialized View 与多分辨率 Rollup 设计
大数据·数据库·clickhouse·架构
fire-flyer18 天前
ClickHouse系列(二):MergeTree 家族详解
大数据·数据库·clickhouse