Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,10 @@ object CollapseProject extends Rule[LogicalPlan] with AliasHelper {
}
// Alias and ExtractValue are very cheap.
case _: Alias | _: ExtractValue => e.children.forall(isCheap)
// `Collate` only re-tags the collation in the type; at runtime it is a pass-through
// (eval/genCode delegate to the child) and never evaluates its collation argument, so it is
// as cheap to duplicate as its value child.
case c: Collate => isCheap(c.child)
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.apache.spark.api.python.PythonEvalType
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
import org.apache.spark.sql.catalyst.dsl.expressions._
import org.apache.spark.sql.catalyst.dsl.plans._
import org.apache.spark.sql.catalyst.expressions.{Alias, CreateArray, Expression, GetArrayItem, PythonUDF, Rand, UpdateFields}
import org.apache.spark.sql.catalyst.expressions.{Alias, Collate, CreateArray, Expression, GetArrayItem, Literal, PythonUDF, Rand, ResolvedCollation, Substring, UpdateFields}
import org.apache.spark.sql.catalyst.plans.PlanTest
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.catalyst.rules.RuleExecutor
Expand Down Expand Up @@ -364,4 +364,17 @@ class CollapseProjectSuite extends PlanTest {

comparePlans(optimized, expected)
}

test("SPARK-59413: Collate is cheap when its value child is cheap") {
// `Collate` is a pure passthrough: `eval` delegates to the child and the collation argument
// is never evaluated, so `isCheap` mirrors the value child's cheapness.
val col = $"s".string
assert(CollapseProject.isCheap(col))
assert(CollapseProject.isCheap(Collate(col, ResolvedCollation("UTF8_LCASE"))))

// A non-cheap value child stays non-cheap through `Collate` (the SPARK-40228 guard is intact).
val nonCheap = Substring(col, Literal(1), Literal(5))
assert(!CollapseProject.isCheap(nonCheap))
assert(!CollapseProject.isCheap(Collate(nonCheap, ResolvedCollation("UTF8_LCASE"))))
}
}