fix: support to_json on Spark 4.0#4036
Merged
mbutrovich merged 1 commit intoapache:mainfrom Apr 22, 2026
Merged
Conversation
In Spark 4.0, StructsToJson is a RuntimeReplaceable whose replacement is Invoke(Literal(StructsToJsonEvaluator), "evaluate", ...). Comet's serde saw the post-replacement Invoke and fell back with "invoke is not supported". Add a Spark 4-only matcher in CometExprShim that detects this specific Invoke shape, reconstructs StructsToJson from the evaluator's options, child, and timeZoneId, and recurses through exprToProtoInternal so support-level checks still apply. Re-enable the four to_json tests that were skipped on Spark 4. Closes apache#3920
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Closes #3920.
Rationale for this change
In Spark 4.0,
StructsToJsonwas changed to extendRuntimeReplaceable. Its replacement isInvoke(Literal(StructsToJsonEvaluator), "evaluate", ...), so by the time Comet's serde walks the optimized plan it only sees theInvokenode. Comet has noInvokehandler, so the fourto_jsontests fell back withCOMET: invoke is not supportedand were skipped viaassume(!isSpark40Plus).What changes are included in this PR?
CometExprShim.versionSpecificExprToProtoInternalthat detectsInvoke(Literal(_: StructsToJsonEvaluator, _), "evaluate", Seq(child)), reconstructs the originalStructsToJson(options, child, timeZoneId)from the evaluator's accessors, and recurses throughexprToProtoInternalsoCometStructsToJson's incompat / support-level checks still apply.to_jsontests inCometExpressionSuiteandCometJsonExpressionSuite.How are these changes tested?
The four tests that were guarded by
assume(!isSpark40Plus)now run and pass on Spark 4.0:CometExpressionSuite:to_jsonCometExpressionSuite:to_json escaping of field names and string valuesCometExpressionSuite:to_json unicodeCometJsonExpressionSuite:to_json - all supported typesAlso verified the same tests still pass on Spark 3.5 (default profile) and that the rest of
CometJsonExpressionSuite(thefrom_jsontests) is unaffected on Spark 4.