Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 8 additions & 46 deletions src/handlers/http/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!([
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
134 changes: 134 additions & 0 deletions src/utils/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Loading