CentOS 8 安装 Apache DataFusion 指南

面向 CentOS 8 服务器的 Apache DataFusion 集成安装指南,涵盖 python39 运行时准备、pip 与 cargo 两种安装方式、版本验证、最小 SQL 查询实测回显及卸载步骤。

Apache DataFusionApache DataFusion2026/10/11

CentOS 8 安装 Apache DataFusion 指南

Apache DataFusion 是用 Rust 编写的可扩展查询引擎,基于 Apache Arrow 内存格式,提供 Rust crate、Python 绑定(datafusion)以及命令行工具 datafusion-cli。它属于库/引擎类组件,没有常驻的守护进程,安装即「引入依赖 + 运行示例」。本文在 CentOS 8(x86_64)服务器上完成 Python 绑定与 CLI 的安装、验证与卸载,所有命令与回显均为该服务器实测结果。

一、前置条件

1.1 系统与账号

  • 操作系统:CentOS Linux 8(x86_64),已具备可用的 dnf 软件源。
  • 账号:以 root 执行(或具备 sudo 权限的等价账号)。
  • 硬件:建议 ≥ 2 vCPU、≥ 4 GB 内存;本文实测环境为 12 vCPU、约 32 GB 内存。

1.2 关键版本约束

DataFusion 的 Python 绑定以 manylinux 预编译 wheel 发布,标签为 cp39-abi3(以 48.0.0 为例),要求 Python ≥ 3.9。而 CentOS 8 系统自带的 Python 版本为 3.6.8,过旧无法安装。因此必须先准备 Python 3.9 运行时:

$ python3 --version
Python 3.6.8

1.3 网络与镜像

若直连 PyPI 较慢,可使用清华镜像 -i https://pypi.tuna.tsinghua.edu.cn/simple。系统需能访问 PyPI 与 crates.io(或对应镜像)。

二、准备 Python 3.9 运行时

CentOS 8 的 AppStream 提供 python39 模块,直接启用安装:

$ dnf module install -y python39
...
Complete!
$ python3.9 --version
Python 3.9.6

如后续需用 Rust 方式构建 CLI,还需 C 工具链:

$ dnf install -y gcc gcc-c++ make
$ gcc --version | head -1
gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4)

三、安装 DataFusion(pip 方式,推荐)

3.1 先固定 pyarrow 版本

直接安装最新 pyarrow 时,若没有匹配 Python 3.9 的预编译 wheel,pip 会回退到源码编译并因缺少 cmake 失败:

  error: command 'cmake' failed: No such file or directory
  ERROR: Failed building wheel for pyarrow

解决办法是显式安装带 cp39 预编译包的 pyarrow 17.0.0:

$ python3.9 -m pip install --no-input -i https://pypi.tuna.tsinghua.edu.cn/simple "pyarrow==17.0.0"
Installing collected packages: numpy, pyarrow
Successfully installed numpy-2.0.2 pyarrow-17.0.0

3.2 安装 datafusion 绑定

$ python3.9 -m pip install --no-input -i https://pypi.tuna.tsinghua.edu.cn/simple "datafusion==48.0.0"
Installing collected packages: typing-extensions, datafusion
Successfully installed datafusion-48.0.0 typing-extensions-4.16.0

3.3 可选:安装 pandas(数据互操作)

$ python3.9 -m pip install --no-input -i https://pypi.tuna.tsinghua.edu.cn/simple "pandas==2.2.3"
Successfully installed pandas-2.2.3 python-dateutil-2.9.0.post0 pytz-2026.5 six-1.17.0 tzdata-2026.5

四、安装 DataFusion CLI(cargo 方式)

datafusion-cli 没有发布到 PyPI(pip install datafusion-cli 返回 404),也没有官方预编译二进制,唯一途径是用 Rust 的 cargo 从源码构建。

4.1 安装 Rust 工具链

$ curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain stable
$ . "$HOME/.cargo/env"
$ rustc --version
rustc 1.99.0 (b940084d7 2026-09-28)
$ cargo --version
cargo 1.99.0 (5f94df478 2026-08-27)

4.2 从源码构建 CLI

$ cargo install datafusion-cli --locked
   Compiling datafusion-cli v55.2.0
    Finished `release` profile [optimized] target(s)
  Installed package `datafusion-cli v55.2.0` (executable `datafusion-cli`)
$ ~/.cargo/bin/datafusion-cli --version
datafusion-cli 55.2.0

提示:首次编译整棵依赖树在 12 核机器上约需 15 分钟;可通过 crates.io 镜像加速依赖下载。产物位于 ~/.cargo/bin/datafusion-cli。

五、版本验证

$ python3.9 -c "import datafusion; print(datafusion.__version__)"
48.0.0
$ python3.9 -m pip show datafusion
Name: datafusion
Version: 48.0.0
Summary: Build and run queries against data
Home-page: https://datafusion.apache.org/python
$ datafusion-cli -q -c "SELECT version();"
+-------------------------------------------+
| version()                                 |
+-------------------------------------------+
| Apache DataFusion 55.2.0, x86_64 on linux |
+-------------------------------------------+

六、最小 SQL 查询示例

6.1 Python 绑定

准备两个小 CSV(/root/employees.csv 与 /root/depts.csv),随后运行:

from datafusion import SessionContext
ctx = SessionContext()
ctx.register_csv("employees", "/root/employees.csv", has_header=True)
ctx.register_csv("depts", "/root/depts.csv", has_header=True)
ctx.sql("SELECT dept_id, COUNT(*) AS cnt, AVG(salary) AS avg_salary "
        "FROM employees GROUP BY dept_id ORDER BY dept_id").show()

真实回显:

+---------+-----+------------+
| dept_id | cnt | avg_salary |
+---------+-----+------------+
| 10      | 2   | 6000.0     |
| 20      | 1   | 6000.0     |
| 30      | 1   | 8000.0     |
+---------+-----+------------+

6.2 datafusion-cli

$ datafusion-cli -p /root -q -c "SELECT e.name, d.dept_name FROM 'employees.csv' e JOIN 'depts.csv' d ON e.dept_id = d.dept_id ORDER BY e.name;"
+-------+-------------+
| name  | dept_name   |
+-------+-------------+
| Alice | Engineering |
| Bob   | Sales       |
| Carol | Engineering |
| David | Marketing   |
+-------+-------------+

七、卸载

7.1 卸载 Python 绑定

$ python3.9 -m pip uninstall -y datafusion pyarrow pandas

7.2 卸载 CLI

$ cargo uninstall datafusion-cli

7.3 彻底移除 Rust 工具链(可选)

$ rustup self uninstall

卸载完成后可用 python3.9 -c "import datafusion" 与 datafusion-cli --version 验证命令已不可用。