feat: support Spark expression json_array_length#4365
Open
kazantsev-maksim wants to merge 47 commits into
Open
feat: support Spark expression json_array_length#4365kazantsev-maksim wants to merge 47 commits into
kazantsev-maksim wants to merge 47 commits into
Conversation
This reverts commit 768b3e9.
andygrove
reviewed
May 20, 2026
| classOf[Cast] -> CometCast) | ||
|
|
||
| private val jsonExpressions: Map[Class[_ <: Expression], CometExpressionSerde[_]] = Map( | ||
| classOf[LengthOfJsonArray] -> CometScalarFunction("json_array_length")) |
Member
There was a problem hiding this comment.
Spark's JsonExpressionUtils.lengthOfJsonArray uses a Jackson parser configured with
ALLOW_SINGLE_QUOTES and ALLOW_UNESCAPED_CONTROL_CHARS, and uses streaming parsing that ignores trailing content after the array's closing bracket. serde_json::from_str::<Value> is much stricter. Could you mark getSupportLevel as Incompatible(Some("...")) and add getIncompatibleReasons() so that the auto-generated compat doc surfaces the limitation to users, and the function is gated behind spark.comet.expression.LengthOfJsonArray.allowIncompatible=true.
andygrove
reviewed
May 20, 2026
| SELECT json_array_length('not an array') | ||
|
|
||
| query | ||
| SELECT json_array_length('{"key":"value"}') |
Member
There was a problem hiding this comment.
could you also add examples for incompatible behavior, such as using single quotes around keys and values
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 #.
Rationale for this change
Add native support for Spark's json_array_length(jsonArray) expression so it runs on Comet instead of falling back to Spark.
What changes are included in this PR?
How are these changes tested?
New SQL test file spark/src/test/resources/sql-tests/expressions/json/json_array_length.sql