use crate::array::{CoordBuffer, CoordType};
use crate::datatypes::GeoDataType;
use arrow_array::{Array, ArrayRef};
use arrow_buffer::{NullBuffer, NullBufferBuilder};
use arrow_schema::{DataType, Field};
use std::any::Any;
use std::sync::Arc;
pub trait GeometryArrayTrait<'a>: std::fmt::Debug + Send + Sync {
fn as_any(&self) -> &dyn Any;
fn data_type(&self) -> &GeoDataType;
fn storage_type(&self) -> DataType;
fn extension_field(&self) -> Arc<Field>;
fn extension_name(&self) -> &str;
fn into_array_ref(self) -> ArrayRef;
fn with_coords(self, coords: CoordBuffer) -> Self;
fn coord_type(&self) -> CoordType;
fn into_coord_type(self, coord_type: CoordType) -> Self;
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn validity(&self) -> Option<&NullBuffer>;
fn nulls(&self) -> Option<&NullBuffer> {
self.validity()
}
fn logical_nulls(&self) -> Option<NullBuffer> {
self.nulls().cloned()
}
#[inline]
fn null_count(&self) -> usize {
self.nulls().map(|x| x.null_count()).unwrap_or(0)
}
#[inline]
fn is_null(&self, i: usize) -> bool {
self.nulls().map(|x| x.is_null(i)).unwrap_or(false)
}
#[inline]
fn is_valid(&self, i: usize) -> bool {
!self.is_null(i)
}
#[must_use]
fn slice(&self, offset: usize, length: usize) -> Self;
#[must_use]
fn owned_slice(&self, offset: usize, length: usize) -> Self;
}
pub trait GeoArrayAccessor<'a>: GeometryArrayTrait<'a> {
type Item: Send + Sync + GeometryScalarTrait<'a>;
type ItemGeo: From<Self::Item>;
fn value(&'a self, index: usize) -> Self::Item {
assert!(index <= self.len());
unsafe { self.value_unchecked(index) }
}
unsafe fn value_unchecked(&'a self, index: usize) -> Self::Item;
fn get(&'a self, index: usize) -> Option<Self::Item> {
if self.is_null(index) {
return None;
}
Some(self.value(index))
}
fn value_as_geo(&'a self, i: usize) -> Self::ItemGeo {
self.value(i).into()
}
fn get_as_geo(&'a self, i: usize) -> Option<Self::ItemGeo> {
if self.is_null(i) {
return None;
}
Some(self.value_as_geo(i))
}
}
pub trait IntoArrow {
type ArrowArray;
fn into_arrow(self) -> Self::ArrowArray;
}
pub trait GeometryScalarTrait<'a> {
type ScalarGeo;
fn to_geo(&self) -> Self::ScalarGeo;
}
pub trait MutableGeometryArray: std::fmt::Debug + Send + Sync {
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn validity(&self) -> &NullBufferBuilder;
fn as_any(&self) -> &dyn Any;
fn as_mut_any(&mut self) -> &mut dyn Any;
fn into_array_ref(self) -> Arc<dyn Array>;
}