diff --git a/src/handlers/http/ingest.rs b/src/handlers/http/ingest.rs index b8e056cac..e0ab36889 100644 --- a/src/handlers/http/ingest.rs +++ b/src/handlers/http/ingest.rs @@ -395,7 +395,6 @@ mod tests { use crate::{ event::format::{json, EventFormat}, metadata::SchemaVersion, - utils::json::{convert_array_to_object, flatten::convert_to_array}, }; trait TestExt { @@ -560,21 +559,6 @@ mod tests { assert_eq!(rb.num_columns(), 1); } - #[test] - fn non_object_arr_is_err() { - let json = json!([1]); - - assert!(convert_array_to_object( - json, - None, - None, - None, - SchemaVersion::V0, - &crate::event::format::LogSource::default() - ) - .is_err()) - } - #[test] fn array_into_recordbatch_inffered_schema() { let json = json!([ @@ -770,28 +754,17 @@ mod tests { { "a": 1, "b": "hello", - "c": [{"a": 1}] + "c_a": [1], }, { "a": 1, "b": "hello", - "c": [{"a": 1, "b": 2}] + "c_a": [1], + "c_b": [2], }, ]); - let flattened_json = convert_to_array( - convert_array_to_object( - json, - None, - None, - None, - SchemaVersion::V0, - &crate::event::format::LogSource::default(), - ) - .unwrap(), - ) - .unwrap(); - let (rb, _) = json::Event::new(flattened_json) + let (rb, _) = json::Event::new(json) .into_recordbatch( &HashMap::default(), false, @@ -859,28 +832,17 @@ mod tests { { "a": 1, "b": "hello", - "c": [{"a": 1}] + "c_a": 1, }, { "a": 1, "b": "hello", - "c": [{"a": 1, "b": 2}] + "c_a": 1, + "c_b": 2, }, ]); - let flattened_json = convert_to_array( - convert_array_to_object( - json, - None, - None, - None, - SchemaVersion::V1, - &crate::event::format::LogSource::default(), - ) - .unwrap(), - ) - .unwrap(); - let (rb, _) = json::Event::new(flattened_json) + let (rb, _) = json::Event::new(json) .into_recordbatch( &HashMap::default(), false, diff --git a/src/utils/json/mod.rs b/src/utils/json/mod.rs index efa9cb2e2..4eeb7465f 100644 --- a/src/utils/json/mod.rs +++ b/src/utils/json/mod.rs @@ -278,4 +278,138 @@ mod tests { assert_eq!(deserialized.value, original.value); assert_eq!(deserialized.other_field, original.other_field); } + + #[test] + fn non_object_arr_is_err() { + let json = json!([1]); + + assert!(flatten_json_body( + json, + None, + None, + None, + SchemaVersion::V0, + false, + &crate::event::format::LogSource::default() + ) + .is_err()) + } + + #[test] + fn arr_obj_with_nested_type() { + let json = json!([ + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + "c": [{"a": 1}] + }, + { + "a": 1, + "b": "hello", + "c": [{"a": 1, "b": 2}] + }, + ]); + let flattened_json = flatten_json_body( + json, + None, + None, + None, + SchemaVersion::V0, + false, + &crate::event::format::LogSource::default(), + ) + .unwrap(); + + assert_eq!( + json!([ + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + "c_a": [1], + }, + { + "a": 1, + "b": "hello", + "c_a": [1], + "c_b": [2], + }, + ]), + flattened_json + ); + } + + #[test] + fn arr_obj_with_nested_type_v1() { + let json = json!([ + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + "c": [{"a": 1}] + }, + { + "a": 1, + "b": "hello", + "c": [{"a": 1, "b": 2}] + }, + ]); + let flattened_json = flatten_json_body( + json, + None, + None, + None, + SchemaVersion::V1, + false, + &crate::event::format::LogSource::default(), + ) + .unwrap(); + + assert_eq!( + json!([ + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + }, + { + "a": 1, + "b": "hello", + "c_a": 1, + }, + { + "a": 1, + "b": "hello", + "c_a": 1, + "c_b": 2, + }, + ]), + flattened_json + ); + } }