Remove avro conversion for refactor
This commit is contained in:
Родитель
194e2dd1dd
Коммит
61e2bb6694
18
build.rs
18
build.rs
|
@ -87,16 +87,16 @@ fn bigquery_{name}() {{
|
|||
fn main() {
|
||||
let test_cases = "tests/resources";
|
||||
|
||||
let mut avro_fp = File::create("tests/avro.rs").unwrap();
|
||||
// let mut avro_fp = File::create("tests/avro.rs").unwrap();
|
||||
let mut bq_fp = File::create("tests/bigquery.rs").unwrap();
|
||||
|
||||
write!(
|
||||
avro_fp,
|
||||
r#"
|
||||
use converter::convert_avro_direct;
|
||||
use serde_json::Value;
|
||||
"#
|
||||
);
|
||||
// write!(
|
||||
// avro_fp,
|
||||
// r#"
|
||||
// use converter::convert_avro_direct;
|
||||
// use serde_json::Value;
|
||||
// "#
|
||||
// );
|
||||
|
||||
write!(
|
||||
bq_fp,
|
||||
|
@ -112,7 +112,7 @@ use serde_json::Value;
|
|||
let file = File::open(path).unwrap();
|
||||
let reader = BufReader::new(file);
|
||||
let suite: TestSuite = serde_json::from_reader(reader).unwrap();
|
||||
write_avro_tests(&avro_fp, &suite);
|
||||
// write_avro_tests(&avro_fp, &suite);
|
||||
write_bigquery_tests(&bq_fp, &suite)
|
||||
}
|
||||
}
|
||||
|
|
26
src/lib.rs
26
src/lib.rs
|
@ -7,32 +7,6 @@ use serde_json::{json, Map, Value};
|
|||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::iter::FromIterator;
|
||||
|
||||
// This uses the Value interface for converting values, which is not strongly typed.
|
||||
pub fn convert_avro_direct(input: &Value, name: String) -> Value {
|
||||
let element: Value = match &input["type"] {
|
||||
Value::String(dtype) => match dtype.as_ref() {
|
||||
"object" => {
|
||||
let mut fields = Vec::new();
|
||||
for (key, value) in input["properties"].as_object().unwrap().iter() {
|
||||
fields.push(convert_avro_direct(value, key.to_string()));
|
||||
}
|
||||
fields.sort_by_key(|obj| obj["name"].as_str().unwrap().to_string());
|
||||
json!({
|
||||
"type": "record",
|
||||
"name": name,
|
||||
"fields": fields,
|
||||
})
|
||||
}
|
||||
"integer" => json!({"name": name, "type": "int"}),
|
||||
"string" => json!({"name": name, "type": "string"}),
|
||||
"boolean" => json!({"name": name, "type": "boolean"}),
|
||||
_ => json!(null),
|
||||
},
|
||||
_ => json!(null),
|
||||
};
|
||||
json!(element)
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Clone, Copy)]
|
||||
enum JSONSchemaKind {
|
||||
Null,
|
||||
|
|
1006
tests/avro.rs
1006
tests/avro.rs
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче