From c9d2a58c94e30ea615376fbd10d8c6299470e6ea Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 5 Oct 2024 18:45:50 +0200 Subject: Handle Null values properly, refactor schema creation to support nullable fields --- src/common.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/common.rs') diff --git a/src/common.rs b/src/common.rs index 2f0f942..c2af766 100644 --- a/src/common.rs +++ b/src/common.rs @@ -106,6 +106,48 @@ pub enum RecordFieldType { Bytes, } +#[derive(Debug, Clone)] +pub struct RecordField { + pub field_type: RecordFieldType, + pub nullable: bool, +} + +impl RecordField { + pub fn int() -> Self { + RecordField { + field_type: RecordFieldType::Int, + nullable: false, + } + } + + pub fn float() -> Self { + RecordField { + field_type: RecordFieldType::Float, + nullable: false, + } + } + + pub fn string() -> Self { + RecordField { + field_type: RecordFieldType::String, + nullable: false, + } + } + + pub fn bytes() -> Self { + RecordField { + field_type: RecordFieldType::Bytes, + nullable: false, + } + } + + pub fn nullable(&mut self) -> Self { + let mut new = self.clone(); + new.nullable = true; + new + } +} + #[derive(Debug, Clone)] pub enum RecordValue { Null, -- cgit v1.3