在wsl的python 3.14.3容器中使用databend包

pypi上的databend项目页面:https://pypi.org/project/databend/

在旧版的linux上安装会报错,虽然可以解决,但是在python中import报错就没办法了。

复制代码
import databend

thread '<unnamed>' panicked at /root/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.45.0/src/runtime/scheduler/multi_thread/worker.rs:460:13:
OS can't spawn worker thread: Operation not permitted (os error 1)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 2761651232
Aborted (core dumped)

再在WSL中安装,应该是Linux版本够高,所以安装,导入都成功。

按照页面介绍的语法,显示版本号。

复制代码
pip install databend
python3
Python 3.14.3 (main, Feb  4 2026, 20:08:31) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import databend; ctx = databend.SessionContext(); ctx.sql('SELECT version() AS version')
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                              version                                             │
│                                              String                                              │
├──────────────────────────────────────────────────────────────────────────────────────────────────┤
│ 'Databend Query v1.2.810-nightly-613a23a366(rust-1.88.0-nightly-2025-09-10T16:50:37.672119017Z)' │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘

但是查询本地文件注册就报错了。

复制代码
>>> ctx.register_tsv("cxy", "/par/data/cxy.tsv", pattern=None, connection=None)
Traceback (most recent call last):
  File "<python-input-9>", line 1, in <module>
    ctx.register_tsv("cxy", "/par/data/cxy.tsv", pattern=None, connection=None)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: DataFrame collect error: SemanticError. Code: 1065, Text = [QUERY-CTX] Query from TSV file lacks column positions. Specify as $1, $2, etc..

<Backtrace disabled by default. Please use RUST_BACKTRACE=1 to enable>

经求教Databend支持人员,告诉我应该用如下语法,并且不能用*,必须用占位符明确指定列:

复制代码
>>> ctx.sql("select * from 'fs:///' (files=>('/par/data/cxy.tsv'),file_format=>'tsv')")
Traceback (most recent call last):
  File "<python-input-4>", line 1, in <module>
    ctx.sql("select * from 'fs:///' (files=>('/par/data/cxy.tsv'),file_format=>'tsv')")
    ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Error: SemanticError. Code: 1065, Text = [QUERY-CTX] Query from TSV file lacks column positions. Specify as $1, $2, etc..
>>> ctx.sql("select $1,$2,$3 from 'fs:///' (files=>('/par/data/cxy.tsv'),file_format=>'tsv')")
┌────────────────────────────────────────────┐
│      $1     │      $2     │       $3       │
│ String NULL │ String NULL │   String NULL  │
├─────────────┼─────────────┼────────────────┤
│ 'id'        │ 'name'      │ 'language\r'   │
│ '1'         │ 'Joe'       │ 'Java\r'       │
│ '2'         │ 'Alice'     │ 'JavaScript\r' │
│ '3'         │ 'Leon'      │ 'C/C++\r'      │
│ '4'         │ 'William'   │ 'Java\r'       │
│ '5'         │ 'James'     │ 'C/C++\r'      │
│ '6'         │ 'Enson'     │ 'C/C++'        │
└────────────────────────────────────────────┘

其实还是有个问题,标题行被作为数据显示出来了。而parquet文件正好相反,如果用*直接显示内容。用1占位符反而显示json格式,工作人员解释在 parquet 上执行: select 1 ,是指把所有的列整体当做一个 variant 类型,遵循 snowflake 的语法方式。

复制代码
>>> ctx.sql("select $1 from 'fs:///' (files=>('/par/duck.parquet'),file_format=>'parquet')")
┌──────────────────────────┐
│            $1            │
│          Variant         │
├──────────────────────────┤
│ '{"mpz_sum":"13522500"}' │
└──────────────────────────┘
>>> ctx.sql("select * from 'fs:///' (files=>('/par/duck.parquet'),file_format=>'parquet')")
┌─────────────┐
│   mpz_sum   │
│ String NULL │
├─────────────┤
│ '13522500'  │
└─────────────┘
相关推荐
小小测试开发3 小时前
安装 Python 3.10+
开发语言·人工智能·python
梦想不只是梦与想4 小时前
Python 中的装饰器
python·装饰器
我叫唧唧波4 小时前
Python+AI 全栈学习笔记
人工智能·python·学习
不会就选b4 小时前
MySQL之视图
数据库·mysql
AAA大运重卡何师傅(专跑国道)5 小时前
【无标题】
开发语言·c#
copyer_xyf5 小时前
Python 异常处理
前端·后端·python
>no problem<5 小时前
基于cola5.0的基础设施层的多数据库切换方案思路
数据库·spring boot·mybatisplus·cola5.0·数据库迁移适配
OceanBase数据库官方博客5 小时前
OceanBase 赋能央国企:从发电到用电的全链路业务承载
数据库·oceanbase
XBodhi.5 小时前
Visual Studio C++ 语法错误: 缺少“;”(在“return”的前面)
开发语言·c++·visual studio
麻雀飞吧5 小时前
期货多合约策略目标持仓怎么更新才不乱
python·区块链