rtyler
04/05/2023, 5:10 PMCreateBuilder
compared to some patterns we have floating around which use JSON for schema definition such as in kafka-delta-ingestYousry Mohamed
04/05/2023, 5:42 PMCreateBuilder
has the benefit of being statically typed code supported by IDE checks and auto-completion specially if primitive data types are declared as enums or something.
Both are testable but JSON has the benefit of treating the schema as data that can be stored in files or databases and sent around which is more flexible than the builder method.
For people new to Rust, JSON is more readable as Rust code can be sometimes scary. But because I come from C# background, I still prefer the builder due to its fluent API nature.rtyler
04/05/2023, 5:43 PMYousry Mohamed
04/05/2023, 5:50 PMdenny.g.lee
Yousry Mohamed
04/10/2023, 7:08 AMwith_column(
"complex",
SchemaDataType::r#struct(SchemaTypeStruct::new(vec![
SchemaField::new(
"f1".to_string(),
SchemaDataType::primitive(String::from("integer")),
false,
HashMap::new() as HashMap<String, Value>,
),
SchemaField::new(
"f2".to_string(),
SchemaDataType::primitive(String::from("string")),
false,
HashMap::new() as HashMap<String, Value>,
),
])),
false,
Default::default(),
)
The above is for table creation (schema definition) side of things. Writing to the table using Rust follows a similar pattern but much more verbose. It includes adding the complex type to ArrowSchema
as DataType::Struct
and then feeding the data via a StructArray