datatypes/types/
null_type.rs1use std::sync::Arc;
16
17use arrow::datatypes::DataType as ArrowDataType;
18use serde::{Deserialize, Serialize};
19
20use crate::data_type::{DataType, DataTypeRef};
21use crate::type_id::LogicalTypeId;
22use crate::value::Value;
23use crate::vectors::{MutableVector, NullVectorBuilder};
24
25#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
26pub struct NullType;
27
28impl NullType {
29 pub fn arc() -> DataTypeRef {
30 Arc::new(NullType)
31 }
32}
33
34impl DataType for NullType {
35 fn name(&self) -> String {
36 "Null".to_string()
37 }
38
39 fn logical_type_id(&self) -> LogicalTypeId {
40 LogicalTypeId::Null
41 }
42
43 fn default_value(&self) -> Value {
44 Value::Null
45 }
46
47 fn as_arrow_type(&self) -> ArrowDataType {
48 ArrowDataType::Null
49 }
50
51 fn create_mutable_vector(&self, _capacity: usize) -> Box<dyn MutableVector> {
52 Box::<NullVectorBuilder>::default()
53 }
54
55 fn try_cast(&self, _from: Value) -> Option<Value> {
57 Some(Value::Null)
58 }
59}