mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-03 20:02:54 +00:00
fix: fix some error
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
use std::process::id;
|
||||
|
||||
use arrow::array::{
|
||||
self, Array, BinaryArray as ArrowBinaryArray, MutableBinaryArray as ArrowMutableBinaryArray,
|
||||
MutableUtf8Array, PrimitiveArray, StructArray, Utf8Array,
|
||||
@@ -11,8 +9,6 @@ use snafu::OptionExt;
|
||||
use crate::error::{ConversionSnafu, Result};
|
||||
use crate::prelude::ConcreteDataType;
|
||||
use crate::value::Value;
|
||||
use crate::vectors::all::GeometryVector;
|
||||
use crate::vectors::Vector;
|
||||
|
||||
pub type BinaryArray = ArrowBinaryArray<i64>;
|
||||
pub type MutableBinaryArray = ArrowMutableBinaryArray<i64>;
|
||||
|
||||
@@ -145,7 +145,7 @@ impl TryFrom<&ArrowDataType> for ConcreteDataType {
|
||||
ArrowDataType::List(field) => Self::List(ListType::new(
|
||||
ConcreteDataType::from_arrow_type(&field.data_type),
|
||||
)),
|
||||
ArrowDataType::Struct(_) => ConcreteDataType::geometry_datatype(),
|
||||
ArrowDataType::Struct(_) => ConcreteDataType::geometry_datatype(GeometryType::Point),
|
||||
_ => {
|
||||
return error::UnsupportedArrowTypeSnafu {
|
||||
arrow_type: dt.clone(),
|
||||
@@ -190,8 +190,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
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
use std::any::Any;
|
||||
use std::default;
|
||||
|
||||
use common_time::{Date, DateTime, Timestamp};
|
||||
|
||||
@@ -367,7 +366,7 @@ impl<'a> ScalarRef<'a> for GeometryValueRef<'a> {
|
||||
Value::Geometry(value) => value,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
GeometryValueRef::Ref { val } => (*val).clone(),
|
||||
GeometryValueRef::Ref { val } => **val,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ impl LogicalTypeId {
|
||||
#[cfg(any(test, feature = "test"))]
|
||||
pub fn data_type(&self) -> crate::data_type::ConcreteDataType {
|
||||
use crate::data_type::ConcreteDataType;
|
||||
use crate::types::GeometryType;
|
||||
|
||||
match self {
|
||||
LogicalTypeId::Null => ConcreteDataType::null_datatype(),
|
||||
@@ -66,7 +67,7 @@ impl LogicalTypeId {
|
||||
LogicalTypeId::List => {
|
||||
ConcreteDataType::list_datatype(ConcreteDataType::null_datatype())
|
||||
}
|
||||
LogicalTypeId::Geometry => ConcreteDataType::geometry_datatype(),
|
||||
LogicalTypeId::Geometry => ConcreteDataType::geometry_datatype(GeometryType::default()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::arrow::datatypes::DataType::Float64;
|
||||
use crate::data_type::DataType;
|
||||
use crate::prelude::{DataTypeRef, LogicalTypeId, Value};
|
||||
use crate::prelude::LogicalTypeId;
|
||||
use crate::value::GeometryValue;
|
||||
use crate::vectors::geometry::GeometryVectorBuilder;
|
||||
|
||||
@@ -14,6 +14,12 @@ pub enum GeometryType {
|
||||
Point,
|
||||
}
|
||||
|
||||
impl Default for GeometryType {
|
||||
fn default() -> Self {
|
||||
Self::Point
|
||||
}
|
||||
}
|
||||
|
||||
impl DataType for GeometryType {
|
||||
fn name(&self) -> &str {
|
||||
GEOMETRY_TYPE_NAME
|
||||
@@ -29,6 +35,7 @@ impl DataType for GeometryType {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: check if unreachable
|
||||
fn as_arrow_type(&self) -> arrow::datatypes::DataType {
|
||||
let fields = vec![
|
||||
Field::new("x", Float64, true),
|
||||
|
||||
@@ -17,6 +17,7 @@ use wkt::Wkt;
|
||||
|
||||
use crate::error::{self, Result};
|
||||
use crate::prelude::*;
|
||||
use crate::types::GeometryType;
|
||||
use crate::vectors::all::GeometryVector;
|
||||
use crate::vectors::ListVector;
|
||||
|
||||
@@ -81,7 +82,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()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,6 +358,12 @@ impl GeometryValue {
|
||||
GeometryValue::Point(p) => p.wkt_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subtype(&self) -> GeometryType {
|
||||
match self {
|
||||
Self::Point(_) => GeometryType::Point,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for GeometryValue {
|
||||
@@ -598,7 +605,7 @@ impl<'a> GeometryValueRef<'a> {
|
||||
fn to_value(self) -> Value {
|
||||
match self {
|
||||
GeometryValueRef::Indexed { vector, idx } => vector.get(idx),
|
||||
GeometryValueRef::Ref { val } => Value::Geometry(val.clone()),
|
||||
GeometryValueRef::Ref { val } => Value::Geometry(*val),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -612,7 +619,7 @@ impl<'a> PartialEq for GeometryValueRef<'a> {
|
||||
impl<'a> Eq for GeometryValueRef<'a> {}
|
||||
|
||||
impl<'a> Ord for GeometryValueRef<'a> {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
fn cmp(&self, _other: &Self) -> Ordering {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use arrow::array::{Array, MutableArray, StructArray};
|
||||
use snafu::{ensure, OptionExt, ResultExt};
|
||||
use snafu::{OptionExt, ResultExt};
|
||||
|
||||
use self::point::{PointVector, PointVectorBuilder};
|
||||
use super::{MutableVector, Validity, Value, Vector};
|
||||
use super::{MutableVector, 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::{
|
||||
data_type::ConcreteDataType,
|
||||
error,
|
||||
prelude::{ScalarVector, ScalarVectorBuilder},
|
||||
serialize::Serializable,
|
||||
value::GeometryValue,
|
||||
@@ -25,7 +24,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 {
|
||||
@@ -131,7 +134,7 @@ impl<'a> Iterator for GeometryVectorIter<'a> {
|
||||
type Item = Option<GeometryValueRef<'a>>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let pos = self.pos;
|
||||
self.pos = self.pos + 1;
|
||||
self.pos += 1;
|
||||
|
||||
if self.vector.len() <= pos {
|
||||
return None;
|
||||
@@ -161,7 +164,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 {
|
||||
@@ -221,7 +228,7 @@ impl MutableVector for GeometryVectorBuilder {
|
||||
impl ScalarVectorBuilder for GeometryVectorBuilder {
|
||||
type VectorType = GeometryVector;
|
||||
|
||||
fn with_capacity(capacity: usize) -> Self {
|
||||
fn with_capacity(_capacity: usize) -> Self {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -295,14 +302,17 @@ 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;
|
||||
|
||||
for i in iter {
|
||||
assert_eq!(i, vector.get_data(cnt));
|
||||
cnt = cnt + 1;
|
||||
cnt += 1;
|
||||
}
|
||||
assert_eq!(cnt, vector.len());
|
||||
|
||||
|
||||
@@ -1,19 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use arrow::array::{
|
||||
Array, FixedSizeListArray, Float64Vec, ListArray, MutableArray, MutableFixedSizeListArray,
|
||||
PrimitiveArray, StructArray,
|
||||
};
|
||||
use arrow::datatypes::DataType::{self, Float64, List};
|
||||
use arrow::array::{Array, Float64Vec, MutableArray, PrimitiveArray, StructArray};
|
||||
use arrow::datatypes::DataType::{self, Float64};
|
||||
use arrow::datatypes::Field;
|
||||
use geo::Point;
|
||||
|
||||
use crate::value::{GeometryValue, GeometryValueRef, OrderedF64, Value, ValueRef};
|
||||
use crate::prelude::Validity;
|
||||
use crate::value::{GeometryValue, Value};
|
||||
use crate::vectors::impl_validity_for_vector;
|
||||
use crate::{
|
||||
prelude::{ScalarVector, ScalarVectorBuilder, Validity, Vector},
|
||||
vectors::MutableVector,
|
||||
};
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct PointVector {
|
||||
pub array: StructArray,
|
||||
@@ -29,9 +20,9 @@ impl PointVector {
|
||||
}
|
||||
|
||||
pub fn slice(&self, offset: usize, length: usize) -> Self {
|
||||
return Self {
|
||||
Self {
|
||||
array: self.array.slice(offset, length),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, index: usize) -> Value {
|
||||
@@ -67,13 +58,19 @@ pub struct PointVectorBuilder {
|
||||
pub array_y: Float64Vec,
|
||||
}
|
||||
|
||||
impl PointVectorBuilder {
|
||||
pub fn new() -> Self {
|
||||
impl Default for PointVectorBuilder {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
array_x: Float64Vec::new(),
|
||||
array_y: Float64Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PointVectorBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
Self {
|
||||
@@ -102,7 +99,7 @@ impl PointVectorBuilder {
|
||||
Field::new("x", Float64, true),
|
||||
Field::new("y", Float64, true),
|
||||
];
|
||||
let validity = x.validity().map(|validity| validity.clone());
|
||||
let validity = x.validity().cloned();
|
||||
let array = StructArray::new(DataType::Struct(fields), vec![x, y], validity);
|
||||
|
||||
PointVector { array }
|
||||
|
||||
@@ -122,11 +122,11 @@ where
|
||||
}
|
||||
}
|
||||
impl VectorOp for GeometryVector {
|
||||
fn replicate(&self, offsets: &[usize]) -> VectorRef {
|
||||
fn replicate(&self, _offsets: &[usize]) -> VectorRef {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn dedup(&self, selected: &mut MutableBitmap, prev_vector: Option<&dyn Vector>) {
|
||||
fn dedup(&self, _selected: &mut MutableBitmap, _prev_vector: Option<&dyn Vector>) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +258,7 @@ fn sql_data_type_to_concrete_data_type(data_type: &SqlDataType) -> Result<Concre
|
||||
if type_name.value.eq_ignore_ascii_case(DateTimeType::name()) {
|
||||
Ok(ConcreteDataType::datetime_datatype())
|
||||
} else if type_name.value.eq_ignore_ascii_case(GeometryType::name()) {
|
||||
Ok(ConcreteDataType::geometry_datatype())
|
||||
Ok(ConcreteDataType::geometry_datatype(GeometryType::Point))
|
||||
} else {
|
||||
error::SqlTypeNotSupportedSnafu {
|
||||
t: data_type.clone(),
|
||||
|
||||
Reference in New Issue
Block a user