diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2024-10-05 18:45:50 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-10-05 18:45:50 +0200 |
| commit | c9d2a58c94e30ea615376fbd10d8c6299470e6ea (patch) | |
| tree | 12dd9ebae4f007d0b935b34b2bcbebfbf3b417ca /src/common.rs | |
| parent | f69622209297111bedb6633af3d973164a4f6d93 (diff) | |
Handle Null values properly, refactor schema creation to support nullable fields
Diffstat (limited to 'src/common.rs')
| -rw-r--r-- | src/common.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs index 2f0f942..c2af766 100644 --- a/src/common.rs +++ b/src/common.rs @@ -107,6 +107,48 @@ pub enum RecordFieldType { } #[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, Int(i64), |
