object metric: Add a test for nested fields

This commit is contained in:
Jan-Erik Rediger 2024-02-05 16:46:01 +01:00 коммит произвёл Jan-Erik Rediger
Родитель 43733c1352
Коммит a47640cd86
3 изменённых файлов: 134 добавлений и 0 удалений

Просмотреть файл

@ -67,6 +67,46 @@
"json_object_path_regex": "an_object_name"
}
}
},
{
"name": "test_json_object_nested",
"compatible": true,
"test": {
"avro": null,
"bigquery": [
{
"fields": [
{
"mode": "NULLABLE",
"name": "an_object_name",
"type": "JSON"
}
],
"mode": "NULLABLE",
"name": "object",
"type": "RECORD"
}
],
"json": {
"properties": {
"object": {
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
},
"type": "object"
}
}
},
"context": {
"json_object_path_regex": "object\\..*"
}
}
}
]
}

Просмотреть файл

@ -556,6 +556,45 @@ fn avro_test_json_object_no_avro_support() {
convert_avro(&input, context);
}
#[test]
fn avro_test_json_object_nested() {
let input_data = r#"
{
"properties": {
"object": {
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
},
"type": "object"
}
}
}
"#;
let expected_data = r#"
null
"#;
let mut context = Context {
..Default::default()
};
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
if expected.is_null() {
// No expected data = no avro support
return;
}
assert_eq!(expected, convert_avro(&input, context.clone()));
context.resolve_method = ResolveMethod::Panic;
convert_avro(&input, context);
}
#[test]
fn avro_test_map_with_atomics() {
let input_data = r#"

Просмотреть файл

@ -558,6 +558,61 @@ fn bigquery_test_json_object_no_avro_support() {
convert_bigquery(&input, context);
}
#[test]
fn bigquery_test_json_object_nested() {
let input_data = r#"
{
"properties": {
"object": {
"properties": {
"an_object_name": {
"items": {},
"type": [
"object",
"array"
]
}
},
"type": "object"
}
}
}
"#;
let expected_data = r#"
[
{
"fields": [
{
"mode": "NULLABLE",
"name": "an_object_name",
"type": "JSON"
}
],
"mode": "NULLABLE",
"name": "object",
"type": "RECORD"
}
]
"#;
let context_data = r#"
{
"json_object_path_regex": "object\\..*"
}
"#;
let context: Value = serde_json::from_str(context_data).unwrap();
let mut context: Context = if context.is_null() {
Default::default()
} else {
serde_json::from_value(context).unwrap()
};
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_bigquery(&input, context.clone()));
context.resolve_method = ResolveMethod::Panic;
convert_bigquery(&input, context);
}
#[test]
fn bigquery_test_map_with_atomics() {
let input_data = r#"