fix: hierarchical json flattening restriction#1058
Merged
nitisht merged 7 commits intoJan 5, 2025
Conversation
Pull Request Test Coverage Report for Build 12618356442Details
💛 - Coveralls |
de-sh
reviewed
Dec 30, 2024
| /// 5. `{"a":{"b":{"c":{"d":{"e":["a","b"]}}}}}` ~> returns error - heavily nested, cannot flatten this JSON | ||
| pub fn flatten_json(value: &Value) -> Result<Vec<Value>, anyhow::Error> { | ||
| if has_more_than_four_levels(value, 1) { | ||
| return Err(anyhow!("heavily nested, cannot flatten this JSON")); |
Contributor
There was a problem hiding this comment.
Why error out? Why not just not flatten upto a certain extent and keep the type as is afterwards?
Contributor
There was a problem hiding this comment.
i.e. {"a": [{"b":{"c":{"d":["e","f"]}}}, "c": {}]} ~> [{"a":{"b":{"c":{"d":["e","f"]}}}}, {"a":{"c": {}}}]
get the level of hierarchy from the json perform generic flattening only if level of nesting is <=4
78e24a2 to
adf87dd
Compare
perf: test nesting level only once
3 tasks
de-sh
reviewed
Jan 5, 2025
Comment on lines
+76
to
+100
| let size: usize = body.len(); | ||
| let mut parsed_timestamp = Utc::now().naive_utc(); | ||
| if time_partition.is_none() { | ||
| if custom_partition.is_none() { | ||
| let size = size as u64; | ||
| create_process_record_batch( | ||
| stream_name, | ||
| req, | ||
| body_val, | ||
| static_schema_flag.as_ref(), | ||
| None, | ||
| parsed_timestamp, | ||
| &HashMap::new(), | ||
| size, | ||
| schema_version, | ||
| ) | ||
| .await?; | ||
| } else { | ||
| let data = convert_array_to_object( | ||
| body_val, | ||
| None, | ||
| None, | ||
| custom_partition.as_ref(), | ||
| schema_version, | ||
| )?; |
Contributor
There was a problem hiding this comment.
Would the following fix the issue of not wanting to convert array to object?
let data = if time_partition.is_some() || custom_partition.is_some() {
convert_array_to_object(
body_val,
time_partition.as_ref(),
time_partition_limit,
custom_partition.as_ref(),
schema_version,
)?
} else {
vec![body_val]
};
Contributor
Author
There was a problem hiding this comment.
I need to test out all the scenarios before I can confirm the changes, as discussed, lets take the optimisation of this one as separate issue.
de-sh
approved these changes
Jan 5, 2025
parmesant
pushed a commit
to parmesant/parseable
that referenced
this pull request
Jan 13, 2025
hierarchical json flattening restriction get the level of hierarchy from the json perform generic flattening only if level of nesting is <=4 --------- Co-authored-by: Devdutt Shenoi <devdutt@parseable.com>
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.
get the level of hierarchy from the json
perform generic flattening only if level of nesting is <=4