This commit is contained in:
Anthony Miyaguchi 2019-01-22 16:49:44 -08:00
Родитель 42412c52e6
Коммит afc3edb982
7 изменённых файлов: 265 добавлений и 195 удалений

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

@ -110,7 +110,7 @@ fn generate_tests(input: PathBuf, output: &Path) {
let bq_dst = output.join(format!("bigquery_{}.rs", suite.name));
let bq_file = File::create(&bq_dst).unwrap();
write_avro_tests(bq_file, &suite);
write_bigquery_tests(bq_file, &suite);
}
fn main() {

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_allof_object() {
fn bigquery_test_allof_object() {
let input_data = r#"
{
"allOf": [
@ -37,23 +37,26 @@ fn avro_test_allof_object() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "string"
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "field_3",
"type": "boolean"
"type": "BOOLEAN"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_array_with_atomics() {
fn bigquery_test_array_with_atomics() {
let input_data = r#"
{
"items": {
@ -14,20 +14,17 @@ fn avro_test_array_with_atomics() {
"#;
let expected_data = r#"
{
"items": {
"type": "int"
},
"name": "root",
"type": "array"
"mode": "REPEATED",
"type": "INTEGER"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_array_with_complex() {
fn bigquery_test_array_with_complex() {
let input_data = r#"
{
"items": {
@ -46,25 +43,23 @@ fn avro_test_array_with_complex() {
"#;
let expected_data = r#"
{
"items": {
"fields": [
{
"name": "field_1",
"type": "string"
},
{
"name": "field_2",
"type": "int"
}
],
"name": "TODO: ???",
"type": "record"
},
"name": "root",
"type": "array"
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "STRING"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "INTEGER"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_atomic() {
fn bigquery_test_atomic() {
let input_data = r#"
{
"type": "integer"
@ -11,17 +11,17 @@ fn avro_test_atomic() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "int"
"mode": "REQUIRED",
"type": "INTEGER"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_atomic_with_null() {
fn bigquery_test_atomic_with_null() {
let input_data = r#"
{
"type": [
@ -32,20 +32,17 @@ fn avro_test_atomic_with_null() {
"#;
let expected_data = r#"
{
"name": "root",
"type": [
"int",
"null"
]
"mode": "NULLABLE",
"type": "INTEGER"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_atomic_multitype() {
fn bigquery_test_incompatible_atomic_multitype() {
let input_data = r#"
{
"type": [
@ -56,16 +53,17 @@ fn avro_test_incompatible_atomic_multitype() {
"#;
let expected_data = r#"
{
"type": "string"
"mode": "REQUIRED",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_atomic_multitype_with_null() {
fn bigquery_test_incompatible_atomic_multitype_with_null() {
let input_data = r#"
{
"type": [
@ -77,10 +75,11 @@ fn avro_test_incompatible_atomic_multitype_with_null() {
"#;
let expected_data = r#"
{
"type": "string"
"mode": "NULLABLE",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_map_with_atomics() {
fn bigquery_test_map_with_atomics() {
let input_data = r#"
{
"additionalProperties": {
@ -14,20 +14,29 @@ fn avro_test_map_with_atomics() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"type": "int"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "value",
"type": "INTEGER"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_map_with_complex() {
fn bigquery_test_map_with_complex() {
let input_data = r#"
{
"additionalProperties": {
@ -46,31 +55,41 @@ fn avro_test_map_with_complex() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"fields": [
{
"name": "field_1",
"type": "string"
},
{
"name": "field_2",
"type": "int"
}
],
"name": "TODO: ???",
"type": "record"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "STRING"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "INTEGER"
}
],
"mode": "REQUIRED",
"name": "value",
"type": "RECORD"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_map_with_pattern_properties() {
fn bigquery_test_map_with_pattern_properties() {
let input_data = r#"
{
"additionalProperties": false,
@ -84,20 +103,29 @@ fn avro_test_map_with_pattern_properties() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"type": "int"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "value",
"type": "INTEGER"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_map_with_pattern_and_additional_properties() {
fn bigquery_test_map_with_pattern_and_additional_properties() {
let input_data = r#"
{
"additionalProperties": {
@ -113,20 +141,29 @@ fn avro_test_map_with_pattern_and_additional_properties() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"type": "int"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "value",
"type": "INTEGER"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_map_with_pattern_properties() {
fn bigquery_test_incompatible_map_with_pattern_properties() {
let input_data = r#"
{
"additionalProperties": false,
@ -143,20 +180,29 @@ fn avro_test_incompatible_map_with_pattern_properties() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"type": "string"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "value",
"type": "STRING"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_map_with_pattern_and_additional_properties() {
fn bigquery_test_incompatible_map_with_pattern_and_additional_properties() {
let input_data = r#"
{
"additionalProperties": {
@ -172,14 +218,23 @@ fn avro_test_incompatible_map_with_pattern_and_additional_properties() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "map",
"values": {
"type": "string"
}
"fields": [
{
"mode": "REQUIRED",
"name": "key",
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "value",
"type": "STRING"
}
],
"mode": "REPEATED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_object_with_atomics_is_sorted() {
fn bigquery_test_object_with_atomics_is_sorted() {
let input_data = r#"
{
"properties": {
@ -27,33 +27,37 @@ fn avro_test_object_with_atomics_is_sorted() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "string"
"type": "STRING"
},
{
"mode": "NULLABLE",
"name": "field_3",
"type": "boolean"
"type": "BOOLEAN"
},
{
"mode": "NULLABLE",
"name": "field_4",
"type": "float"
"type": "FLOAT"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_object_with_atomics_required() {
fn bigquery_test_object_with_atomics_required() {
let input_data = r#"
{
"properties": {
@ -78,29 +82,32 @@ fn avro_test_object_with_atomics_required() {
{
"fields": [
{
"mode": "REQUIRED",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "string"
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "field_3",
"type": "boolean"
"type": "BOOLEAN"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_object_with_atomics_required_with_null() {
fn bigquery_test_object_with_atomics_required_with_null() {
let input_data = r#"
{
"properties": {
@ -128,29 +135,32 @@ fn avro_test_object_with_atomics_required_with_null() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "string"
"type": "STRING"
},
{
"mode": "REQUIRED",
"name": "field_3",
"type": "boolean"
"type": "BOOLEAN"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_object_with_complex() {
fn bigquery_test_object_with_complex() {
let input_data = r#"
{
"properties": {
@ -175,23 +185,26 @@ fn avro_test_object_with_complex() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "string"
"type": "STRING"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "int"
"type": "INTEGER"
}
],
"mode": "NULLABLE",
"name": "namespace_1",
"type": "record"
"type": "RECORD"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}

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

@ -1,9 +1,9 @@
use converter::convert_avro_direct;
use converter::convert_bigquery_direct;
use serde_json::Value;
#[test]
fn avro_test_oneof_atomic() {
fn bigquery_test_oneof_atomic() {
let input_data = r#"
{
"oneOf": [
@ -18,17 +18,17 @@ fn avro_test_oneof_atomic() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "int"
"mode": "REQUIRED",
"type": "INTEGER"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_oneof_atomic_with_null() {
fn bigquery_test_oneof_atomic_with_null() {
let input_data = r#"
{
"oneOf": [
@ -43,20 +43,17 @@ fn avro_test_oneof_atomic_with_null() {
"#;
let expected_data = r#"
{
"name": "root",
"type": [
"null",
"int"
]
"mode": "NULLABLE",
"type": "INTEGER"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_oneof_atomic() {
fn bigquery_test_incompatible_oneof_atomic() {
let input_data = r#"
{
"oneOf": [
@ -71,17 +68,17 @@ fn avro_test_incompatible_oneof_atomic() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "string"
"mode": "REQUIRED",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_oneof_atomic_with_null() {
fn bigquery_test_incompatible_oneof_atomic_with_null() {
let input_data = r#"
{
"oneOf": [
@ -99,20 +96,17 @@ fn avro_test_incompatible_oneof_atomic_with_null() {
"#;
let expected_data = r#"
{
"name": "root",
"type": [
"null",
"string"
]
"mode": "NULLABLE",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_oneof_object_with_atomics() {
fn bigquery_test_oneof_object_with_atomics() {
let input_data = r#"
{
"oneOf": [
@ -145,25 +139,27 @@ fn avro_test_oneof_object_with_atomics() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "int"
"type": "INTEGER"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_oneof_object_merge() {
fn bigquery_test_oneof_object_merge() {
let input_data = r#"
{
"oneOf": [
@ -196,29 +192,32 @@ fn avro_test_oneof_object_merge() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "boolean"
"type": "BOOLEAN"
},
{
"mode": "NULLABLE",
"name": "field_3",
"type": "float"
"type": "FLOAT"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_oneof_object_merge_with_complex() {
fn bigquery_test_oneof_object_merge_with_complex() {
let input_data = r#"
{
"oneOf": [
@ -272,43 +271,49 @@ fn avro_test_oneof_object_merge_with_complex() {
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_4",
"type": "int"
"type": "BOOLEAN"
},
{
"mode": "NULLABLE",
"name": "field_5",
"type": "boolean"
"type": "FLOAT"
},
{
"fields": [
{
"mode": "NULLABLE",
"name": "field_1",
"type": "int"
"type": "INTEGER"
},
{
"mode": "NULLABLE",
"name": "field_2",
"type": "boolean"
"type": "BOOLEAN"
},
{
"mode": "NULLABLE",
"name": "field_3",
"type": "float"
"type": "FLOAT"
}
],
"mode": "NULLABLE",
"name": "namespace_1",
"type": "record"
"type": "RECORD"
}
],
"name": "root",
"type": "record"
"mode": "REQUIRED",
"type": "RECORD"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_oneof_atomic_and_object() {
fn bigquery_test_incompatible_oneof_atomic_and_object() {
let input_data = r#"
{
"oneOf": [
@ -328,17 +333,17 @@ fn avro_test_incompatible_oneof_atomic_and_object() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "string"
"mode": "REQUIRED",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_oneof_object() {
fn bigquery_test_incompatible_oneof_object() {
let input_data = r#"
{
"oneOf": [
@ -363,17 +368,17 @@ fn avro_test_incompatible_oneof_object() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "string"
"mode": "REQUIRED",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}
#[test]
fn avro_test_incompatible_oneof_object_with_complex() {
fn bigquery_test_incompatible_oneof_object_with_complex() {
let input_data = r#"
{
"oneOf": [
@ -414,11 +419,11 @@ fn avro_test_incompatible_oneof_object_with_complex() {
"#;
let expected_data = r#"
{
"name": "root",
"type": "string"
"mode": "REQUIRED",
"type": "STRING"
}
"#;
let input: Value = serde_json::from_str(input_data).unwrap();
let expected: Value = serde_json::from_str(expected_data).unwrap();
assert_eq!(expected, convert_avro_direct(&input, "root".to_string()));
assert_eq!(expected, convert_bigquery_direct(&input, "root".to_string()));
}