Fix excess nesting for nested lists in avro schemas

This commit is contained in:
Anthony Miyaguchi 2019-10-01 13:53:27 -07:00
Родитель 4b53c6852a
Коммит 27b0da53e3
4 изменённых файлов: 32 добавлений и 49 удалений

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

@ -34,7 +34,6 @@ def format_key(key):
def convert(data, schema):
if schema.type == "string":
if not isinstance(data, str):
return json.dumps(data)
@ -100,13 +99,14 @@ with open(f"data/{document}.ndjson", "r") as f:
data = f.readlines()
try:
out = {}
orig = None
for line in data:
out = convert(json.loads(line), schema)
orig = json.loads(line)
out = convert(orig, schema)
writer.append(out)
except:
with open("test.json", "w") as f:
json.dump(out, f)
json.dump(orig, f)
with open("test-schema.json", "w") as f:
json.dump(schema.to_json(), f, indent=2)
validation.validate(out, parse_schema(schema.to_json()))

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

@ -246,9 +246,7 @@ impl TranslateFrom<ast::Tag> for Type {
},
fields: vec![Field {
name: "list".into(),
data_type: Type::Complex(Complex::Array(Array {
items: Box::new(data_type),
})),
data_type,
..Default::default()
}],
}))),
@ -667,10 +665,7 @@ mod tests {
"type": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "long"
}
"type": "long"
}
}
}

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

@ -114,26 +114,20 @@
"name": "list",
"type": {
"items": {
"items": {
"fields": [
{
"name": "list",
"type": {
"items": {
"items": {
"type": "long"
},
"type": "array"
},
"type": "array"
}
"fields": [
{
"name": "list",
"type": {
"items": {
"type": "long"
},
"type": "array"
}
],
"name": "list",
"namespace": "root.array",
"type": "record"
},
"type": "array"
}
],
"name": "list",
"namespace": "root.array",
"type": "record"
},
"type": "array"
}

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

@ -133,26 +133,20 @@ fn avro_test_array_of_array() {
"name": "list",
"type": {
"items": {
"items": {
"fields": [
{
"name": "list",
"type": {
"items": {
"items": {
"type": "long"
},
"type": "array"
},
"type": "array"
}
"fields": [
{
"name": "list",
"type": {
"items": {
"type": "long"
},
"type": "array"
}
],
"name": "list",
"namespace": "root.array",
"type": "record"
},
"type": "array"
}
],
"name": "list",
"namespace": "root.array",
"type": "record"
},
"type": "array"
}