# Apache DataFusion Comet

**Apache DataFusion Comet** 是 [Apache Spark](https://www.edgepedia.org/zh/apache-spark) 的开源加速器，以 Spark 插件的形式实现，将 Spark 物理计划转换为 [Apache DataFusion](https://www.edgepedia.org/zh/apache-datafusion) 物理计划，并在 CPU 上原生执行，无需修改用户代码。<sup>[1](https://datafusion.apache.org/comet/)</sup><sup> • </sup><sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup> 它最初由 Apple 实现，于 2024 年 3 月捐赠给 [Apache Arrow](https://www.edgepedia.org/zh/apache-arrow) 项目，现为 Apache 软件基金会旗下 Apache DataFusion 的子项目。<sup>[3](https://arrow.apache.org/blog/2024/03/06/comet-donation/)</sup>

| 关键事实 | 详情 |
|---|---|
| 功能 | 在 DataFusion 原生（Rust）引擎上运行现有的 Spark SQL 和 DataFrame 查询；用户添加 Comet jar 包并设置 `spark.plugins=org.apache.spark.CometPlugin`<sup>[1](https://datafusion.apache.org/comet/)</sup> |
| 硬件 | 运行于通用 CPU；无需 GPU 或 FPGA 加速器<sup>[1](https://datafusion.apache.org/comet/)</sup> |
| 平台支持 | 支持 Spark 3.4、3.5、4.0、4.1 和 4.2（4.2 为实验性），需 Java 17 或更高版本；Spark 3.4 已弃用<sup>[4](https://datafusion.apache.org/comet/about/faq.html)</sup> |
| 覆盖范围增长 | 首个版本 0.1.0 支持 13 个算子和 106 个表达式；到 1.0.0 版本时，代码库可识别超过 400 个 Spark 表达式<sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup> |
| 回退行为 | 不支持的算子会导致整个查询阶段回退到常规 Spark 执行；结果不受影响<sup>[5](https://apache.googlesource.com/datafusion-comet/%2B/refs/heads/main/docs/source/user-guide/latest/operators.md)</sup> |
| 基准测试结果 | Amazon EKS 上的 TPC-DS 3TB：Parquet 表加速 1.57 倍，Iceberg 表加速 1.75 倍（Comet 1.0.0）<sup>[6](https://awslabs.github.io/data-on-eks/docs/benchmarks/spark-datafusion-comet-benchmark)</sup> |
| 发布历史 | 2024 年 3 月捐赠；首个版本 0.1.0 于 2024 年 7 月发布；1.0.0 版本于 2026 年 8 月 7 日发布<sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup><sup> • </sup><sup>[7](https://archive.apache.org/dist/datafusion/)</sup> |

## 架构

Spark 保留其解析器、优化器和分布式控制流。通过该插件，Spark 的物理计划被捕获，Comet 支持的算子被转换为 Protocol Buffer 格式，然后传递给 DataFusion 原生引擎执行。DataFusion 是一个用 Rust 编写的向量化查询引擎，使用 Apache Arrow 作为内存格式，直接读取 Parquet 和 Iceberg 数据，并将结果以 Arrow 列式批次的形式返回给 Spark。<sup>[1](https://datafusion.apache.org/comet/)</sup><sup> • </sup><sup>[8](https://datafusion.apache.org/comet/about/gluten_comparison.html)</sup>

覆盖范围在设计上就是部分的。对于受支持的算子，Comet 将其替换为原生等价实现，并将相邻的原生算子作为一个单元执行；因此，包含任何不支持算子的查询阶段会回退到 Spark 的标准执行。<sup>[5](https://apache.googlesource.com/datafusion-comet/%2B/refs/heads/main/docs/source/user-guide/latest/operators.md)</sup> 可以通过类似 `spark.comet.exec.sort.enabled=false` 的设置关闭单个算子，而设置 `spark.comet.exec.enabled=false` 则会完全禁用原生执行。<sup>[5](https://apache.googlesource.com/datafusion-comet/%2B/refs/heads/main/docs/source/user-guide/latest/operators.md)</sup>

## 代码生成调度器

部分覆盖的主要代价是回退。每当某个表达式缺少原生 Rust 实现时，Comet 就会将整个子树回退到 Spark 的行式执行，而为 Spark 的行式算子提供数据所需的列式到行式转换，可能会抵消 Comet 在计划其他部分获得的加速。<sup>[9](https://datafusion.apache.org/blog/2026/06/20/datafusion-comet-0.17.0/)</sup><sup> • </sup><sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup>

0.17.0 版本引入了 JVM 代码生成调度器作为解决方案。它在 Comet 流水线内运行 Spark 自己生成的代码（`doGenCode`），直接操作 Arrow 批次，因此数据保持列式，只有缺失的表达式在 JVM 代码中运行。被调度的表达式并不比在 Spark 中更快，但一个不支持的表达式不再会迫使整个查询阶段回退到行式执行。<sup>[9](https://datafusion.apache.org/blog/2026/06/20/datafusion-comet-0.17.0/)</sup>

由于被调度的表达式运行的是 Spark 自己的代码，它们与 Spark 完全一致。0.17.0 版本将此应用于正则表达式和 JSON 函数，在原生 Rust 或 C++ 重新实现必然会产生差异的地方提供了与 Spark 兼容的行为；1.0.0 版本将该机制扩展到类型转换和其他表达式，并延伸至 Scala 和 Java UDF。<sup>[9](https://datafusion.apache.org/blog/2026/06/20/datafusion-comet-0.17.0/)</sup><sup> • </sup><sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup>

## 兼容性与正确性

Comet 旨在与受支持的 Spark 版本实现 100% 兼容，并在 CI 中运行 Apache Spark 自己的 SQL 测试套件，提供超过 24,000 个单元测试，同时还有比较启用与禁用 Comet 时结果的 Scala 端到端测试、针对 null、NaN 和时区等边界情况的模糊测试，以及受 sqllogictest 启发的测试格式。默认情况下，Comet 使用与 Spark 匹配的实现，包括在原生实现存在差异的地方运行 Spark 自己生成的代码；已记录的差异，例如对包含无效 UTF-8 的字符串的处理，列在兼容性指南中。<sup>[4](https://datafusion.apache.org/comet/about/faq.html)</sup><sup> • </sup><sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup><sup> • </sup><sup>[10](https://datafusion.apache.org/comet/user-guide/latest/compatibility/index.html)</sup>

数据源覆盖范围比 Spark 更窄。Comet 包含自己的 Parquet 读取器，对于 [Apache Iceberg](https://www.edgepedia.org/zh/apache-iceberg) 表，提供默认开启的原生扫描以及用户必须自行开启的原生写入；对 [Delta Lake](https://www.edgepedia.org/zh/delta-lake)、Hudi 和 Paimon 表的扫描不会获得加速，由 Spark 执行这些读取。<sup>[4](https://datafusion.apache.org/comet/about/faq.html)</sup><sup> • </sup><sup>[11](https://github.com/apache/datafusion-comet/blob/main/docs/source/user-guide/latest/datasources.md)</sup> Comet 仅针对开源的 Apache Spark 构建和测试；厂商发行版可能会更改 Comet 调用的内部 Spark API，因此云用户被建议运行开源 Spark，例如在 [Kubernetes](https://www.edgepedia.org/zh/kubernetes) 上。<sup>[4](https://datafusion.apache.org/comet/about/faq.html)</sup>

## 与其他加速器的比较

Comet 属于一类使用原生列式引擎加速 Spark 的项目，与专有的 Databricks Photon 引擎、[Apache Gluten](https://www.edgepedia.org/zh/apache-gluten) 以及 NVIDIA cuDF（原 RAPIDS）插件并列。<sup>[3](https://arrow.apache.org/blog/2024/03/06/comet-donation/)</sup> Apache Gluten 在设计上与 Comet 最为接近：一个 Spark 插件，将其支持的计划部分传递给原生引擎，例如 C++ 引擎 Velox。Apache Auron（孵化中），前身为 Blaze，也是一个基于 DataFusion 构建的 Spark 插件。Gluten 和 Auron 正在增加对 Flink 的支持，而 Comet 仅专注于 Spark。<sup>[4](https://datafusion.apache.org/comet/about/faq.html)</sup>

与 Gluten 的主要架构差异在于原生引擎：Rust 编写的 DataFusion 与 Meta 创建的 C++ 引擎 Velox，Gluten 以 [Substrait](https://www.edgepedia.org/zh/substrait) 格式序列化计划，而 Comet 使用自己的 Protocol Buffer 格式。Comet 的维护者指出，Rust 的编译期内存安全降低了在每个 Spark 执行器中运行的组件发生内存损坏崩溃的风险，且没有垃圾回收开销。<sup>[8](https://datafusion.apache.org/comet/about/gluten_comparison.html)</sup> AWS Labs 的一项独立基准测试在 Amazon EKS 上使用 Graviton4 实例比较了 Comet 0.16.0 与 Gluten 1.6.0 在 TPC-DS 3TB 上的表现，发现整体性能相似，Gluten 在这些基准测试中略微领先，并且与 Delta Lake、Hudi 和 Paimon 的原生集成更广泛，而 Comet 在 Spark 4.0 的 ANSI 模式、Iceberg 工作负载和代码生成调度方面具有优势。<sup>[8](https://datafusion.apache.org/comet/about/gluten_comparison.html)</sup>

## 实际性能

独立基准测试显示出显著但依赖于工作负载的收益。在 AWS Data on EKS 基准测试中（Spark 3.5.8 上的 TPC-DS 3TB，4 个 r8gd.12xlarge 节点，数据存储在 S3 中），Comet 1.0.0 将 Parquet 上的总运行时间从 3,650.56 秒减少到 2,318.74 秒（1.57 倍），将 Iceberg 上的总运行时间从 4,665.47 秒减少到 2,668.29 秒（1.75 倍）；79% 的 Parquet 查询提升超过 20%，而 Iceberg 上最大的性能回退是单个查询的 142%。<sup>[6](https://awslabs.github.io/data-on-eks/docs/benchmarks/spark-datafusion-comet-benchmark)</sup> 一项针对 Spark 4.2.0 在相同集群配置上运行的项目基准测试报告称，Comet 1.1.0 的总加速为 1.84 倍，103 个 TPC-DS 查询的几何平均值为 1.66 倍，有 4 个查询性能较慢。<sup>[12](https://www.mail-archive.com/github%40datafusion.apache.org/msg171826.html)</sup>

结果取决于计划形态。EKS 分析将最大的收益归因于 Comet 用广播连接替代排序合并连接（q56 加速 3.21 倍，shuffle 读取从 2.2 GB 降至 38.4 MB）以及原生列式算子（q67 加速 3.01 倍，GC 时间从 97.5 秒降至 1.0 秒），而短查询和部分扫描因设置开销和尾部延迟而变慢。<sup>[6](https://awslabs.github.io/data-on-eks/docs/benchmarks/spark-datafusion-comet-benchmark)</sup> AWS 团队在 EKS 上首次运行 3TB TPC-DS 时比原版 Spark 慢 11%；在与维护者合作修复后，同一基准测试比原版 Spark 快 32%。<sup>[13](https://datafusion.apache.org/blog/output/2026/06/03/comet-eks/)</sup>

## 历史

Comet 被捐赠给 Apache Arrow，于 2024 年 3 月 6 日宣布，随后被组织为 Apache DataFusion 的子项目。<sup>[3](https://arrow.apache.org/blog/2024/03/06/comet-donation/)</sup> 其发布档案涵盖从 0.1.0（2024 年 7 月）到 1.1.0（2026 年 10 月），其中 2026 年 8 月 7 日发布的 1.0.0 版本标志着转向语义化版本。<sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup><sup> • </sup><sup>[7](https://archive.apache.org/dist/datafusion/)</sup> 到该版本发布时，项目已发布 20 个版本，并吸引了超过 120 名开发者的贡献。<sup>[2](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)</sup>

## References

1. [Apache DataFusion Comet documentation](https://datafusion.apache.org/comet/)
2. [Apache DataFusion Comet 1.0.0 Release, Apache DataFusion Blog](https://datafusion.apache.org/blog/output/2026/08/07/datafusion-comet-1.0.0/)
3. [Announcing Apache Arrow DataFusion Comet, Apache Arrow Blog (6 March 2024)](https://arrow.apache.org/blog/2024/03/06/comet-donation/)
4. [Frequently Asked Questions, Apache DataFusion Comet documentation](https://datafusion.apache.org/comet/about/faq.html)
5. [Spark Operator Support, Apache DataFusion Comet documentation](https://apache.googlesource.com/datafusion-comet/%2B/refs/heads/main/docs/source/user-guide/latest/operators.md)
6. [spark-datafusion-comet-benchmark, Data on EKS](https://awslabs.github.io/data-on-eks/docs/benchmarks/spark-datafusion-comet-benchmark)
7. [Index of /dist/datafusion, Apache archive](https://archive.apache.org/dist/datafusion/)
8. [Comparison of Comet and Gluten, Apache DataFusion Comet documentation](https://datafusion.apache.org/comet/about/gluten_comparison.html)
9. [Apache DataFusion Comet 0.17.0 Release, Apache DataFusion Blog (20 June 2026)](https://datafusion.apache.org/blog/2026/06/20/datafusion-comet-0.17.0/)
10. [Compatibility Guide, Apache DataFusion Comet documentation](https://datafusion.apache.org/comet/user-guide/latest/compatibility/index.html)
11. [Supported Data Sources (datasources.md), apache/datafusion-comet on GitHub](https://github.com/apache/datafusion-comet/blob/main/docs/source/user-guide/latest/datasources.md)
12. [PR: docs: update TPC-DS benchmark results for Comet 1.1.0 on Spark 4.2, datafusion-comet mailing list](https://www.mail-archive.com/github%40datafusion.apache.org/msg171826.html)
13. [What two months with the Comet community got our Spark workload on Amazon EKS, Apache DataFusion Blog (3 June 2026)](https://datafusion.apache.org/blog/output/2026/06/03/comet-eks/)

---
*Initially written Oct 26, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Databases and data systems › Data mining, warehousing, and big data › Big data platforms and frameworks

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/apache-datafusion-comet

English original: https://www.edgepedia.org/apache-datafusion-comet
