Visorgood commented on code in PR #221:
URL: https://github.com/apache/datafusion-site/pull/221#discussion_r4679642223


##########
content/blog/2026-11-22-comet-spark-comparison.md:
##########
@@ -0,0 +1,391 @@
+---
+layout: post
+title: Where Apache Spark loses time, and how Apache DataFusion Comet gets it 
back
+date: 2026-11-22
+author: Viacheslav Inozemtsev
+categories: [performance, subprojects]
+---
+
+<!--
+{% comment %}
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to you under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+{% endcomment %}
+-->
+
+[TOC]
+
+## Introduction
+
+[Apache DataFusion Comet](https://datafusion.apache.org/comet/) is an 
accelerator for [Apache Spark](https://spark.apache.org/) that can also read 
and write [Apache Iceberg](https://iceberg.apache.org/) tables natively. It is 
built on top of [Apache DataFusion](https://datafusion.apache.org/), a query 
engine written in Rust on [Apache Arrow](https://arrow.apache.org/). Comet 
plugs into Spark without changes to the jobs: it takes the physical plan that 
Spark has built and executes the operators it supports in native code. The 
promise is better performance thanks to two things: Comet processes data in 
columnar Arrow batches instead of one row at a time, and it runs in native code 
outside the JVM, without JVM objects and their overhead. The project's README 
states a speedup of about 1.8 times on TPC-DS at 1 TB, which translates into 
roughly 45% lower cost.
+
+Numbers like these are useful, but they don't explain where the gain comes 
from. The usual answer – "Comet is columnar and native" – is true, but it 
explains less than it seems, because Spark's own Iceberg reader already decodes 
Parquet into Arrow vectors. If both engines start from columnar batches, where 
exactly does Spark lose time, and what does Comet do differently? I wanted to 
see this in detail, step by step, on a real job.
+
+In this post, I will take one ordinary ETL job – read an Iceberg table, filter 
it, compute a value, aggregate it, and write the result into another Iceberg 
table – and run it with plain Spark and with Spark + Comet. We will follow a 
few rows through every step of the job in both engines, look at the CPU 
profiles, and estimate how much CPU each step costs. On 8 cores, plain Spark 
took 38.7 seconds and 295 CPU-seconds, and Spark with Comet took 10.5 seconds 
and 76 CPU-seconds, with the same output. Then we will look at the opposite 
case: how one unsupported expression takes most of this gain away. I will 
finish with a practical guide on checking and tuning Comet for your own jobs.
+
+Everything in this post is reproducible with two commands, `docker build` and 
`docker run`, from the repository 
[Visorgood/spark-comet-iceberg-bench](https://github.com/Visorgood/spark-comet-iceberg-bench).
 All numbers come from Spark 4.1.3, Iceberg 1.11.0 and Comet 1.2.0.
+
+## The benchmark job
+
+For the data, I use TPC-H – a standard decision-support benchmark with a 
synthetic dataset of customers, orders, parts and suppliers, which can be 
generated at any size set by a scale factor. Its largest table is `lineitem`, 
with one row per line of a customer order: the order key, the part, the 
quantity, the price, the discount, the ship date, and other attributes. At 
scale factor 100, `lineitem` has 600 million rows.
+
+The job computes the revenue of each order from the lines shipped since 1995 – 
a typical ETL step that touches every part of the engine, from the scan to the 
write:
+
+```sql
+INSERT INTO lake.tpch.order_revenue
+SELECT l_orderkey,
+       sum(l_extendedprice * (1 - l_discount)) AS revenue,
+       count(*)                                AS lines
+FROM   lake.tpch.lineitem
+WHERE  l_shipdate >= DATE '1995-01-01'
+GROUP  BY l_orderkey
+```
+
+A few details of this setup matter for the results:
+
+- **Source.** `lineitem` at scale factor 100 is stored in an Iceberg table 
with Iceberg's defaults: Parquet data files with zstd compression, 15.1 GiB in 
206 files. The query needs only four of the 16 columns, and Comet's scan 
metrics show 3.5 GiB read from these files.
+- **Target.** An unpartitioned Iceberg table with no sort order and default 
properties. In this case, Iceberg asks Spark for no extra shuffle or sort 
before the write, and the write stays eligible for Comet's native Iceberg 
writer.
+- **Shape.** An order has about four lines, so the partial aggregate shrinks 
the data only about four times, and the shuffle still carries 87 million rows. 
A query with few groups, like TPC-H Q1, would hide the shuffle.
+- **Types.** The money columns are `decimal(15,2)`. The product 
`l_extendedprice * (1 - l_discount)` is `decimal(32,4)`, and the sum is 
`decimal(38,4)`, both wider than 18 digits. As we will see later, this matters 
more than anything else in this job.
+- **`INSERT INTO` rather than `CREATE TABLE AS SELECT`.** Comet's native 
Iceberg write covers append, overwrite and copy-on-write DML, but not CTAS.

Review Comment:
   Thanks, you're right: on Spark 3.5+ the CTAS inner append goes through the 
native writer. Fixed in f898c10: the post now says that Comet handles CTAS too, 
and gives keeping the whole job in one plan as the reason for `INSERT INTO`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to