You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When Spark decodes JSON data where values don't match the expected schema type, it silently coerces incompatible values to strings instead of failing or preserving the original structure.
When decoding the following JSON with a schema of map<string,string>: {"hello": [1,2,3]}, Spark automatically converts the array value to its string representation, resulting in {"hello": "[1,2,3]"}
I wonder if true spark compatibility might just require a custom JSON reader...
I agree -- if the goal is to have a json reader compatible with spark, and we can't do that with straightforward API extensions, making a custom JSON reader makes the most sense to me
I'm not sure the correct solution, but we're hitting this problem in delta-io/delta-kernel-rs#501. Since the bad entry is one field of one row of a potentially very large json parse, it's pretty painful. And implementing a full-blown custom json parser for everything -- just to deal with one field that might be bad sometimes -- is a super unpleasant workaround.
So far I'm aware of three alternatives to handle bad values without just walking away from arrow-json parsing:
This issue suggests converting bad values to strings (or rather, user can request string type for a column they're worried about, and it's their job to json-parse the resulting string if they want)
Add custom decoder in arrow-json #7442 proposes a custom decoder concept, tho it's type-based and probably needs to be path-based instead (specific fields in the schema have custom decoders, rather than specific data types)
Activity
tustvold commentedon Apr 29, 2025
Does it preserve the JSON data as is? If so this is incompatible with the destructive nature of possessing to a tape.
Whilst one could serialize the tape back to JSON the code to do this doesn't exist, would be complicated, and wouldn't reproduce the actual input...
I wonder if true spark compatibility might just require a custom JSON reader...
alamb commentedon Apr 29, 2025
I agree -- if the goal is to have a json reader compatible with spark, and we can't do that with straightforward API extensions, making a custom JSON reader makes the most sense to me
cht42 commentedon Apr 29, 2025
FYI, I'm using the following code to achieve this
tustvold commentedon Apr 29, 2025
That doesn't handle escaping correctly, correctly serializing the tape back to JSON is of similar complexity to parsing it in the first place.
scovich commentedon May 1, 2025
I'm not sure the correct solution, but we're hitting this problem in delta-io/delta-kernel-rs#501. Since the bad entry is one field of one row of a potentially very large json parse, it's pretty painful. And implementing a full-blown custom json parser for everything -- just to deal with one field that might be bad sometimes -- is a super unpleasant workaround.
So far I'm aware of three alternatives to handle bad values without just walking away from arrow-json parsing:
scovich commentedon May 1, 2025
Forgot a fourth option:
Variant is probably the best (most flexible with least knobs) solution, but could be a long ways off.
alamb commentedon May 5, 2025
You must be helping us fish for help 🎉
I am pretty stoked that we just landed some example variant data
So I think we can now proceed testing a Rust variant implementation