diff --git a/Cargo.lock b/Cargo.lock index 3cb97461ba..a8876a3e34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2084,6 +2084,7 @@ dependencies = [ "approx", "num-traits", "rstar", + "serde", ] [[package]] diff --git a/src/datatypes/Cargo.toml b/src/datatypes/Cargo.toml index fbd6ae9576..f9ae340b05 100644 --- a/src/datatypes/Cargo.toml +++ b/src/datatypes/Cargo.toml @@ -20,7 +20,7 @@ paste = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" snafu = { version = "0.7", features = ["backtraces"] } -geo = { version = "0.23.0", features = ["serde"] } +geo = { version = "0.23.0", features = ["use-serde"] } [dependencies.arrow] package = "arrow2" diff --git a/src/datatypes/src/value.rs b/src/datatypes/src/value.rs index 1d55797281..78e551c385 100644 --- a/src/datatypes/src/value.rs +++ b/src/datatypes/src/value.rs @@ -308,14 +308,14 @@ impl Ord for ListValue { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize,)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq)] pub enum GeometryValue { - Point(f64, f64), + Point(geo::Point), } impl Default for GeometryValue { fn default() -> Self { - GeometryValue::Point(0.0, 0.0) + todo!() } } /// Reference to [Value]. diff --git a/src/datatypes/src/vectors/geometry.rs b/src/datatypes/src/vectors/geometry.rs index 94085ca92d..05b5a6e086 100644 --- a/src/datatypes/src/vectors/geometry.rs +++ b/src/datatypes/src/vectors/geometry.rs @@ -1,5 +1,7 @@ +use arrow::array::Array; use snafu::ensure; +use self::point::PointVector; use super::{MutableVector, Vector}; use crate::{ error, @@ -10,7 +12,9 @@ use crate::{ mod point; #[derive(Debug, Clone, PartialEq)] -pub enum GeometryVector {} +pub enum GeometryVector { + PointVector(PointVector), +} impl Vector for GeometryVector { fn data_type(&self) -> crate::data_type::ConcreteDataType { @@ -42,11 +46,15 @@ impl Vector for GeometryVector { } fn memory_size(&self) -> usize { - todo!() + match self { + GeometryVector::PointVector(point_vector) => point_vector.memory_size(), + } } fn is_null(&self, row: usize) -> bool { - todo!() + match self { + GeometryVector::PointVector(point_vector) => point_vector.array.is_null(row), + } } fn slice(&self, offset: usize, length: usize) -> super::VectorRef { @@ -60,37 +68,6 @@ impl Vector for GeometryVector { fn get_ref(&self, index: usize) -> crate::value::ValueRef { todo!() } - - fn is_empty(&self) -> bool { - self.len() == 0 - } - - fn null_count(&self) -> usize { - match self.validity() { - super::Validity::Slots(bitmap) => bitmap.null_count(), - super::Validity::AllValid => 0, - super::Validity::AllNull => self.len(), - } - } - - fn is_const(&self) -> bool { - false - } - - fn only_null(&self) -> bool { - self.null_count() == self.len() - } - - fn try_get(&self, index: usize) -> crate::Result { - ensure!( - index < self.len(), - error::BadArrayAccessSnafu { - index, - size: self.len() - } - ); - Ok(self.get(index)) - } } impl ScalarVector for GeometryVector { @@ -122,7 +99,9 @@ impl<'a> Iterator for GeometryVectorIter<'a> { } } -pub enum GeometryVectorBuilder {} +pub enum GeometryVectorBuilder { + +} impl MutableVector for GeometryVectorBuilder { fn data_type(&self) -> crate::data_type::ConcreteDataType { diff --git a/src/datatypes/src/vectors/geometry/point.rs b/src/datatypes/src/vectors/geometry/point.rs index 7c820234cd..3a83ce4631 100644 --- a/src/datatypes/src/vectors/geometry/point.rs +++ b/src/datatypes/src/vectors/geometry/point.rs @@ -1,174 +1,22 @@ -// use arrow::array::{FixedSizeListArray, MutableFixedSizeListArray}; -// use geo::Point; +use arrow::array::{Array, FixedSizeListArray, ListArray, MutableFixedSizeListArray, StructArray}; +use arrow::datatypes::DataType::List; +use geo::Point; -// use crate::{ -// prelude::{ScalarVector, ScalarVectorBuilder, Vector}, -// vectors::MutableVector, -// }; -// #[derive(Debug, Clone, PartialEq)] -// struct PointVector { -// array: FixedSizeListArray, -// } +use crate::{ + prelude::{ScalarVector, ScalarVectorBuilder, Vector}, + vectors::MutableVector, +}; +#[derive(Debug, Clone, PartialEq)] +pub struct PointVector { + pub array: StructArray, +} -// impl Vector for PointVector { -// fn data_type(&self) -> crate::data_type::ConcreteDataType { -// todo!() -// } +impl PointVector { + pub fn memory_size(&self) -> usize { + 2 * self.array.len() * std::mem::size_of::() + } +} -// fn vector_type_name(&self) -> String { -// todo!() -// } - -// fn as_any(&self) -> &dyn std::any::Any { -// todo!() -// } - -// fn len(&self) -> usize { -// todo!() -// } - -// fn to_arrow_array(&self) -> arrow::array::ArrayRef { -// todo!() -// } - -// fn to_boxed_arrow_array(&self) -> Box { -// todo!() -// } - -// fn validity(&self) -> crate::vectors::Validity { -// todo!() -// } - -// fn memory_size(&self) -> usize { -// todo!() -// } - -// fn is_null(&self, row: usize) -> bool { -// todo!() -// } - -// fn slice(&self, offset: usize, length: usize) -> crate::vectors::VectorRef { -// todo!() -// } - -// fn get(&self, index: usize) -> crate::value::Value { -// todo!() -// } - -// fn get_ref(&self, index: usize) -> crate::value::ValueRef { -// todo!() -// } - -// fn is_empty(&self) -> bool { -// self.len() == 0 -// } - -// fn null_count(&self) -> usize { -// match self.validity() { -// crate::vectors::Validity::Slots(bitmap) => bitmap.null_count(), -// crate::vectors::Validity::AllValid => 0, -// crate::vectors::Validity::AllNull => self.len(), -// } -// } - -// fn is_const(&self) -> bool { -// false -// } - -// fn only_null(&self) -> bool { -// self.null_count() == self.len() -// } - -// fn try_get(&self, index: usize) -> crate::Result { -// ensure!( -// index < self.len(), -// error::BadArrayAccessSnafu { -// index, -// size: self.len() -// } -// ); -// Ok(self.get(index)) -// } -// } - -// impl ScalarVector for PointVector { -// type OwnedItem; - -// type RefItem<'a> -// where -// Self: 'a; - -// type Iter<'a> -// where -// Self: 'a; - -// type Builder; - -// fn get_data(&self, idx: usize) -> Option> { -// todo!() -// } - -// fn iter_data(&self) -> Self::Iter<'_> { -// todo!() -// } - -// fn from_slice(data: &[Self::RefItem<'_>]) -> Self { -// let mut builder = Self::Builder::with_capacity(data.len()); -// for item in data { -// builder.push(Some(*item)); -// } -// builder.finish() -// } - -// fn from_iterator<'a>(it: impl Iterator>) -> Self { -// let mut builder = Self::Builder::with_capacity(get_iter_capacity(&it)); -// for item in it { -// builder.push(Some(item)); -// } -// builder.finish() -// } - -// fn from_owned_iterator(it: impl Iterator>) -> Self { -// let mut builder = Self::Builder::with_capacity(get_iter_capacity(&it)); -// for item in it { -// match item { -// Some(item) => builder.push(Some(item.as_scalar_ref())), -// None => builder.push(None), -// } -// } -// builder.finish() -// } - -// fn from_vec>(values: Vec) -> Self { -// let it = values.into_iter(); -// let mut builder = Self::Builder::with_capacity(get_iter_capacity(&it)); -// for item in it { -// builder.push(Some(item.into().as_scalar_ref())); -// } -// builder.finish() -// } -// } - -// struct PointVectorBuilder { -// buffer: MutableFixedSizeListArray, -// } - -// impl MutableVector for PointVectorBuilder {} - -// impl ScalarVectorBuilder for PointVectorBuilder { -// type VectorType = PointVector; - -// fn with_capacity(capacity: usize) -> Self { -// todo!() -// } - -// fn push( -// &mut self, -// value: Option<::RefItem<'_>>, -// ) { -// } - -// fn finish(&mut self) -> Self::VectorType { -// todo!() -// } -// } +pub struct PointVectorBuilder { + //pub array: MutableFixedSizeListArray, +}