Skip to content

[GLUTEN-13003][CORE] Move version-independent helpers out of SparkShims into utils - #13006

Open
LuciferYang wants to merge 5 commits into
apache:mainfrom
LuciferYang:spark33-residue-shim-dedup
Open

LuciferYang wants to merge 5 commits into
apache:mainfrom
LuciferYang:spark33-residue-shim-dedup

Conversation

@LuciferYang

@LuciferYang LuciferYang commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Three helpers on SparkShims no longer vary across the supported versions ({3.4, 3.5, 4.0, 4.1}), so they no longer need to live on the version-shim trait.

structFromAttributes and attributesFromStruct move to ExpressionUtils. They were abstract on the trait with four identical overrides (spark34 hand-written; 3.5/4.0/4.1 delegating to DataTypeUtils, whose body is spark34's verbatim). Since they don't depend on the Spark version, SparkShims is the wrong home, and ExpressionUtils in gluten-substrait is reachable from every caller. The call sites move from SparkShimLoader.getSparkShims.structFromAttributes(x) to ExpressionUtils.structFromAttributes(x), and the trait declarations and the four overrides are gone.

invalidBucketFile was a private def copied into all four shims; it moves to org.apache.gluten.utils.ExceptionUtils, the shared exception helper in shims/common, and the four shims call ExceptionUtils.invalidBucketFile(...). It builds SparkException(INVALID_BUCKET_FILE, path=..., cause=null) by hand rather than calling Spark's QueryExecutionErrors.invalidBucketFile, because that object is private[sql] and cannot be reached from Gluten's own packages. Only Gluten classes placed under org.apache.spark.sql.*, such as AbstractFileSourceScanExec, can call it. A comment records that.

Thanks to @jackylee-ch for the review that prompted moving all three off the trait.

How was this patch tested?

clean test-compile on Spark 3.4, 3.5, 4.0 and 4.1 with -Pbackends-velox -Pspark-ut -Piceberg -Pdelta, Scala 2.13; the 3.5 run adds -Pbackends-clickhouse, the only profile it builds on. spotless:apply clean. This is code motion with unchanged signatures, so no suite was run.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude claude-opus-5

Related issue: #13003

Copilot AI lite review requested due to automatic review settings September 12, 2026 06:51
@github-actions github-actions Bot added the CORE works for Gluten Core label Sep 12, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments remain.

Pull request overview

This pull request centralizes shared Spark shim implementations across Spark 3.4–4.1, reducing duplication while preserving compatibility.

Changes:

  • Centralizes struct/attribute conversion methods.
  • Moves invalidBucketFile into the common trait.
  • Removes redundant per-version methods and imports.
File summaries
File Description
shims/spark41/src/main/scala/org/apache/gluten/sql/shims/spark41/Spark41Shims.scala Removes duplicated overrides and imports.
shims/spark40/src/main/scala/org/apache/gluten/sql/shims/spark40/Spark40Shims.scala Removes duplicated overrides and imports.
shims/spark35/src/main/scala/org/apache/gluten/sql/shims/spark35/Spark35Shims.scala Removes duplicated overrides and imports.
shims/spark34/src/main/scala/org/apache/gluten/sql/shims/spark34/Spark34Shims.scala Removes duplicated overrides.
shims/common/src/main/scala/org/apache/gluten/sql/shims/SparkShims.scala Adds shared implementations.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 14, 2026 02:47
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments; changes were compile-tested across Spark 3.4–4.1.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@LuciferYang

Copy link
Copy Markdown
Contributor Author

cc @jackylee-ch

metadata: Map[String, Any] = Map.empty): Seq[PartitionedFile]

def structFromAttributes(attrs: Seq[Attribute]): StructType
def structFromAttributes(attrs: Seq[Attribute]): StructType =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this func out of SparkShims? We can defined it in ExpressionUtils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — moved both to ExpressionUtils and repointed the call sites. They don't vary across the supported versions, so you're right that SparkShims was the wrong home.

StructType(attrs.map(a => StructField(a.name, a.dataType, a.nullable, a.metadata)))

def attributesFromStruct(structType: StructType): Seq[Attribute]
def attributesFromStruct(structType: StructType): Seq[Attribute] =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

field => AttributeReference(field.name, field.dataType, field.nullable, field.metadata)()
}

// https://issues.apache.org/jira/browse/SPARK-40400

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SPARK-40400 is fixed in Spark 3.4.0, can we also remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this and it doesn't compile from here: QueryExecutionErrors is private[sql], so object QueryExecutionErrors ... cannot be accessed ... from class Spark34Shims in package spark34. Only Gluten classes placed under org.apache.spark.sql.*, like AbstractFileSourceScanExec, can reach it, which is the actual reason for the local copy; SPARK-40400 fixing the error framework doesn't change the visibility. I did dedup the four copies into one protected def on the trait.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification. Since invalidBucketFile is no longer version-specific, maybe we can move it out of SparkShims as well.

How about putting it in GlutenExceptionUtils for now? It seems a better fit for shared exception construction logic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Moved it to the existing org.apache.gluten.utils.ExceptionUtils in shims/common (there is no GlutenExceptionUtils in the tree, and that is where the shared exception helpers already live, e.g. hasCause). The four shims now call ExceptionUtils.invalidBucketFile(...), and it is off the trait entirely.

Copilot AI review requested due to automatic review settings September 14, 2026 07:32
@LuciferYang LuciferYang changed the title [GLUTEN-13003][CORE] Move two more SparkShims methods onto the trait [GLUTEN-13003][CORE] Move version-independent shim helpers to ExpressionUtils and dedup invalidBucketFile Sep 14, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments remain, and the reviewed changes are ready for approval.

Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 14, 2026 09:57
@LuciferYang LuciferYang changed the title [GLUTEN-13003][CORE] Move version-independent shim helpers to ExpressionUtils and dedup invalidBucketFile [GLUTEN-13003][CORE] Move version-independent helpers out of SparkShims into utils Sep 14, 2026
@github-actions

Copy link
Copy Markdown

Run Gluten Clickhouse CI on x86

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review issues remain.

Review details
  • Files reviewed: 18/18 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLICKHOUSE CORE works for Gluten Core VELOX

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants