refactor: set inner subtype to ConcreteDataType::Geometry

This commit is contained in:
Ning Sun
2022-10-18 11:16:14 +08:00
parent 2f159dbe22
commit 36ce08cb03
5 changed files with 37 additions and 9 deletions

View File

@@ -188,8 +188,9 @@ impl ConcreteDataType {
ConcreteDataType::Timestamp(TimestampType::new(TimeUnit::Millisecond))
}
pub fn geometry_datatype() -> Self {
ConcreteDataType::Geometry(GeometryType::Point)
// FIXME: specify inner type
pub fn geometry_datatype(inner_type: GeometryType) -> Self {
ConcreteDataType::Geometry(inner_type)
}
/// Converts from arrow timestamp unit to

View File

@@ -1,3 +1,5 @@
use crate::types::GeometryType;
/// Unique identifier for logical data type.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum LogicalTypeId {
@@ -66,7 +68,8 @@ impl LogicalTypeId {
LogicalTypeId::List => {
ConcreteDataType::list_datatype(ConcreteDataType::null_datatype())
}
LogicalTypeId::Geometry => ConcreteDataType::geometry_datatype(),
// FIXME(sunng87): check if default type works
LogicalTypeId::Geometry => ConcreteDataType::geometry_datatype(GeometryType::default()),
}
}
}

View File

@@ -10,6 +10,12 @@ pub enum GeometryType {
Point,
}
impl Default for GeometryType {
fn default() -> Self {
Self::Point
}
}
impl DataType for GeometryType {
fn name(&self) -> &str {
"Geometry"
@@ -25,6 +31,7 @@ impl DataType for GeometryType {
}
}
// TODO: check if unreachable
fn as_arrow_type(&self) -> arrow::datatypes::DataType {
unreachable!()
}

View File

@@ -12,6 +12,7 @@ use serde::{Deserialize, Serialize};
use crate::error::{self, Result};
use crate::prelude::*;
use crate::types::GeometryType;
use crate::vectors::all::GeometryVector;
use crate::vectors::ListVector;
@@ -76,7 +77,7 @@ impl Value {
Value::Date(_) => ConcreteDataType::date_datatype(),
Value::DateTime(_) => ConcreteDataType::date_datatype(),
Value::Timestamp(v) => ConcreteDataType::timestamp_datatype(v.unit()),
Value::Geometry(_) => ConcreteDataType::geometry_datatype(),
Value::Geometry(geom) => ConcreteDataType::geometry_datatype(geom.subtype()),
}
}
@@ -329,6 +330,12 @@ impl GeometryValue {
pub fn to_value(self) -> Value {
Value::Geometry(self)
}
pub fn subtype(&self) -> GeometryType {
match self {
Self::Point(_) => GeometryType::Point,
}
}
}
impl Default for GeometryValue {

View File

@@ -7,6 +7,7 @@ use self::point::{PointVector, PointVectorBuilder};
use super::{MutableVector, Validity, Value, Vector};
use crate::error::SerializeSnafu;
use crate::prelude::ScalarRef;
use crate::types::GeometryType;
use crate::value::{GeometryValueRef, ValueRef};
use crate::vectors::{impl_try_from_arrow_array_for_vector, impl_validity_for_vector};
use crate::{
@@ -25,7 +26,11 @@ pub enum GeometryVector {
impl Vector for GeometryVector {
fn data_type(&self) -> crate::data_type::ConcreteDataType {
ConcreteDataType::geometry_datatype()
let subtype = match self {
Self::PointVector(_) => GeometryType::Point,
};
ConcreteDataType::geometry_datatype(subtype)
}
fn vector_type_name(&self) -> String {
@@ -161,7 +166,11 @@ impl GeometryVectorBuilder {
impl MutableVector for GeometryVectorBuilder {
fn data_type(&self) -> crate::data_type::ConcreteDataType {
ConcreteDataType::geometry_datatype()
let subtype = match self {
Self::PointVectorBuilder(_) => GeometryType::Point,
};
ConcreteDataType::geometry_datatype(subtype)
}
fn len(&self) -> usize {
@@ -276,7 +285,10 @@ mod tests {
assert_eq!(vector.get(0), value.to_value());
assert_eq!(vector.get_data(0).unwrap().to_owned_scalar(), value);
assert_eq!(vector.data_type(), ConcreteDataType::geometry_datatype());
assert_eq!(
vector.data_type(),
ConcreteDataType::geometry_datatype(GeometryType::Point)
);
let iter = vector.iter_data();
let mut cnt: usize = 0;
@@ -301,11 +313,9 @@ mod tests {
assert_eq!(vector.memory_size(), 32); //2 elements (f64,f64)=2*2*8
assert_eq!(
format!("{:?}",vector.serialize_to_json().unwrap()),
"[Object {\"Point\": Object {\"type\": String(\"Point\"), \"coordinates\": Array [Number(2.0), Number(1.0)]}}, Null]".to_string()
)
}
}