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

相关推荐
SelectDB技术团队7 小时前
SelectDB 架构演进与 ClickHouse 迁移指南
大数据·数据库·clickhouse·云原生·架构·数据分析·apache doris
ClickHouseDB1 天前
使用 ClickHouse 与 Massive 构建实时市场数据应用
clickhouse
秉寒-CHO1 天前
从 ClickHouse 到 StarRocks:我在真实业务中怎么选明细、聚合、主键模型
大数据·clickhouse
IT界的老黄牛2 天前
ClickHouse 运维 SQL 速查:system 表查跑批、内存、合并与磁盘一篇通
大数据·clickhouse·磁盘占用·命令速查·运维排查·system表
wengad3 天前
podman安装clickhouse
clickhouse·podman
l1t6 天前
duckdb、clickhouse、datafusion、cedardb、tableauhyperapi 5种分析型数据库执行递归求数独SQL比较
数据库·sql·clickhouse
l1t6 天前
一个clickhouse易错的语法问题
数据库·sql·clickhouse
流烟默7 天前
ClickHouse 集群建表实战:从引擎选择到本地表 / 分布式表落地
分布式·clickhouse
深蓝电商API8 天前
亿级数据的存储选型:MongoDB/ES/ClickHouse横评
爬虫·clickhouse·mongodb·elasticsearch
流烟默10 天前
ClickHouse Part 机制与写入优化实践指南
大数据·运维·clickhouse