datafusion-comet icon indicating copy to clipboard operation
datafusion-comet copied to clipboard

feat: Add Native Support for In-Memory Cache

Open pchintar opened this issue 6 months ago • 2 comments

Which issue does this PR close?

Closes #2391 .

Rationale for this change

Comet currently has limited support for Spark's in-memory cache.

When a table is cached and later read, the cached data cannot be consumed directly by Comet operators. Instead, the execution plan falls back to Spark's cache scan path and introduces an additional CometSparkColumnarToColumnar conversion before execution can continue in Comet.

This extra conversion adds overhead to cached table scans and prevents cached data from remaining on a native Comet execution path.

This PR adds native support for in-memory cached tables so that cached data written in a Comet-compatible format can be read directly by Comet operators.

What changes are included in this PR?

This PR introduces a native cache path for in-memory cached tables behind a new configuration:

spark.comet.exec.inMemoryCache.enabled

When enabled:

  • Cached data is stored using a Comet-specific cache serializer.
  • Cached data is represented as CometCachedBatch.
  • Cached tables are scanned using CometInMemoryTableScanExec.
  • Cached data can be consumed directly by Comet operators without introducing a CometSparkColumnarToColumnar conversion.

When disabled:

  • Spark's existing cache serializer continues to be used.
  • Existing cache scan behavior is preserved.

How are these changes tested?

Added CometInMemoryCacheSuite covering:

  • Comet-native cache scan over CometCachedBatch
  • Fallback behavior when native cache support is disabled
  • Multi-partition cached tables
  • Empty cached tables
  • Projection-only cache reads
  • Shuffle execution after cached table scans

Verified with:

./mvnw -pl spark -DskipTests test-compile

./mvnw test -pl spark \
  -DwildcardSuites=org.apache.comet.exec.CometInMemoryCacheSuite

pchintar avatar Jun 04 '26 13:06 pchintar

Hello, @pchintar Could you, please, merge the current main? I would love to test out the .cache() implementation on our pipelines

Or can you merge the currently opened #4982? cc @mbutrovich (regarding perf regression due to .cache() method being absent in the Comet)

sandugood avatar Jul 22 '26 12:07 sandugood

Or can you merge the currently opened #4982? cc @mbutrovich (regarding perf regression due to .cache() method being absent in the Comet)

I suspect #4982 will merge today, and then I can look at trying to fix the merge conflicts in this one.

mbutrovich avatar Jul 22 '26 13:07 mbutrovich