[SPARK-59024][SQL] Support sequential cached name for anonymous cached tables - #58314
[SPARK-59024][SQL] Support sequential cached name for anonymous cached tables#58314pan3793 wants to merge 3 commits into
Conversation
…d tables Add spark.sql.useSequentialCacheName. When it is true and the cached table has no name, CachedRDDBuilder uses a sequential number like 'CachedRDD 1' as the cached name instead of the abbreviated plan tree string. Rendering the plan tree string can be expensive for large plans. Assisted-by: Qwen3.8 Max
Remove .internal() from spark.sql.useSequentialCacheName, and pin the disabled case in the test with an explicit conf value instead of relying on the default.
|
Thanks for working on this — the underlying problem is real, and defaulting the config to 1. Part of this can be fixed without a config
So for anonymous caches, Making it lazy val cachedName: String = tableName.map(n => s"In-memory table $n").getOrElse { ... }One thing to confirm if you take this: This would also narrow what the new config has to justify, down to "large anonymous caches that are materialized". 2. Off-by-one between the doc and the behaviorprivate val _nextCachedRDDId = new AtomicLong(0)
def nextCachedRDDId(): Long = _nextCachedRDDId.getAndIncrement
Minor: the closest precedent in this area is private val nextPlanId = new AtomicInteger(0)
private[execution] def newPlanId(): Int = nextPlanId.getAndIncrement()
3. The config should be
|
What changes were proposed in this pull request?
Add a new SQL config
spark.sql.useSequentialCacheName(defaultfalse). When it is true and the cached table has no name,CachedRDDBuilderuses a sequential number likeCachedRDD 1as the cached name instead of the abbreviated plan tree string:Why are the changes needed?
For anonymous cached tables, the cached name is built from the plan's tree string (
cachedPlan.toString, abbreviated to 1024 chars). Rendering the plan tree string can be expensive for large plans, so caching unnamed large DataFrames pays this cost even though the name is only used for display.This is another spot, besides the SQL event plan description addressed in SPARK-59023, that hurts the same customer job: it constructs a huge plan whose
treeStringexceeds 280,000 lines, and rendering the plan tree string takes minutes per iteration and contributes to driver OOM.Does this PR introduce any user-facing change?
Yes. A new config
spark.sql.useSequentialCacheNameis available. When it is enabled, anonymous cached tables get sequential names likeCachedRDD 1instead of the abbreviated plan tree string. The default behavior is unchanged.How was this patch tested?
A new unit test in
InMemoryRelationSuite(sequential cached name for anonymous cached tables) verifies:CachedRDD <n>names when the config is enabledIn-memory table <name>nameWas this patch authored or co-authored using generative AI tooling?
Generated-by: Qwen3.8 Max