diff --git a/tests/resources/translate/json_column.json b/tests/resources/translate/json_column.json index 2594b04..c1be4fe 100644 --- a/tests/resources/translate/json_column.json +++ b/tests/resources/translate/json_column.json @@ -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\\..*" + } + } } ] } diff --git a/tests/transpile_avro.rs b/tests/transpile_avro.rs index 4d364ad..65580e9 100644 --- a/tests/transpile_avro.rs +++ b/tests/transpile_avro.rs @@ -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#" diff --git a/tests/transpile_bigquery.rs b/tests/transpile_bigquery.rs index e69c75b..a9d953a 100644 --- a/tests/transpile_bigquery.rs +++ b/tests/transpile_bigquery.rs @@ -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#"