pub fn populate_schema_and_serialize(
    schema: &Schema,
    records: &HashMap<String, SchemaValue>
) -> Result<Vec<u8>, AvroError>
Expand description

Function to populate a given schema with data and return serialized record.

Remarks

  • record is the record to be written as HashMap<String, SchemaValue> where SchemaValue is common types

Examples

use common_helpers::avro;
use common_helpers::types::*;
use std::{collections::HashMap};
let raw_schema = r#"
{
    "type": "record",
    "name": "test",
    "fields": [
        {"name": "a", "type": "long", "default": 42},
        {"name": "b", "type": "string"}
    ]
}
"#;
let schema_fingerprint = avro::fingerprint_raw_schema(raw_schema);
let mut hashmap_data = HashMap::new();
let mut name = "name".to_string();
let mut name_field = SchemaValue::String("John".to_string());
hashmap_data.insert("a".to_string(), SchemaValue::Long(27i64));
hashmap_data.insert("b".to_string(), SchemaValue::String("foo".to_string()));
assert!(schema_fingerprint.is_ok());
let data_schema = schema_fingerprint.unwrap().0;
let serialized_record = avro::populate_schema_and_serialize(&data_schema, &hashmap_data);
assert!(serialized_record.is_ok());