From b43edcf5aafdf03d7ef6c84163c7562118506b9a Mon Sep 17 00:00:00 2001 From: TCeason Date: Wed, 4 Dec 2024 10:27:04 +0800 Subject: [PATCH] fix some todo --- src/common/native/src/write/serialize.rs | 5 +++-- src/query/expression/src/converts/arrow/from.rs | 3 --- src/query/expression/src/converts/arrow/to.rs | 4 +--- src/query/expression/src/kernels/concat.rs | 9 ++++++++- src/query/expression/src/kernels/take_chunks.rs | 9 +++++++-- src/query/expression/src/utils/visitor.rs | 8 ++++++-- src/query/formats/src/field_decoder/fast_values.rs | 1 - 7 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/common/native/src/write/serialize.rs b/src/common/native/src/write/serialize.rs index 00ca5c0be1974..3bd5e0c112fef 100644 --- a/src/common/native/src/write/serialize.rs +++ b/src/common/native/src/write/serialize.rs @@ -16,6 +16,7 @@ use std::io::Write; use databend_common_column::buffer::Buffer; use databend_common_column::types::i256; +use databend_common_column::types::months_days_ns; use databend_common_expression::types::DecimalColumn; use databend_common_expression::types::GeographyColumn; use databend_common_expression::types::NumberColumn; @@ -67,8 +68,8 @@ pub fn write( Column::Date(column) => { write_primitive::(w, &column, validity, write_options, scratch) } - Column::Interval(_column) => { - todo!() + Column::Interval(column) => { + write_primitive::(w, &column, validity, write_options, scratch) } Column::Binary(b) | Column::Bitmap(b) diff --git a/src/query/expression/src/converts/arrow/from.rs b/src/query/expression/src/converts/arrow/from.rs index ad6bf60545aa5..250ba6bfc2742 100644 --- a/src/query/expression/src/converts/arrow/from.rs +++ b/src/query/expression/src/converts/arrow/from.rs @@ -260,9 +260,6 @@ impl Column { } DataType::Interval => { todo!() - // let array = arrow_cast::cast(array.as_ref(), &ArrowDataType::Interval(IntervalUnit::MonthDayNano))?; - // let buffer: Buffer = array.to_data().buffers()[0].clone().into(); - // Column::Interval(buffer) } DataType::Nullable(_) => { let validity = match array.nulls() { diff --git a/src/query/expression/src/converts/arrow/to.rs b/src/query/expression/src/converts/arrow/to.rs index 7823787b70bf0..416a87a4e2238 100644 --- a/src/query/expression/src/converts/arrow/to.rs +++ b/src/query/expression/src/converts/arrow/to.rs @@ -295,9 +295,7 @@ impl From<&Column> for ArrayData { Column::String(col) => col.clone().into(), Column::Timestamp(col) => buffer_to_array_data((col.clone(), arrow_type)), Column::Date(col) => buffer_to_array_data((col.clone(), arrow_type)), - Column::Interval(_) => { - todo!() - } + Column::Interval(col) => buffer_to_array_data((col.clone(), arrow_type)), Column::Array(col) => { let child_data = ArrayData::from(&col.values); let builder = ArrayDataBuilder::new(arrow_type) diff --git a/src/query/expression/src/kernels/concat.rs b/src/query/expression/src/kernels/concat.rs index 53649e1e5cdbd..031ddc5aca3a0 100644 --- a/src/query/expression/src/kernels/concat.rs +++ b/src/query/expression/src/kernels/concat.rs @@ -35,6 +35,7 @@ use crate::types::BooleanType; use crate::types::DataType; use crate::types::DateType; use crate::types::DecimalType; +use crate::types::IntervalType; use crate::types::MapType; use crate::types::NumberType; use crate::types::TimestampType; @@ -166,6 +167,13 @@ impl Column { ); Column::Date(buffer) } + Column::Interval(_) => { + let buffer = Self::concat_primitive_types( + columns.map(|col| IntervalType::try_downcast_column(&col).unwrap()), + capacity, + ); + Column::Interval(buffer) + } Column::Array(col) => { let mut offsets = Vec::with_capacity(capacity + 1); offsets.push(0); @@ -215,7 +223,6 @@ impl Column { .collect::>()?; Column::Tuple(fields) } - Column::Interval(_) => todo!(), Column::Variant(_) | Column::Geometry(_) | Column::Geography(_) diff --git a/src/query/expression/src/kernels/take_chunks.rs b/src/query/expression/src/kernels/take_chunks.rs index bab5706f8ece1..ffb9a4a6a5e44 100644 --- a/src/query/expression/src/kernels/take_chunks.rs +++ b/src/query/expression/src/kernels/take_chunks.rs @@ -694,8 +694,13 @@ impl Column { .unwrap(); Column::Date(d) } - ColumnVec::Interval(_columns) => { - todo!() + ColumnVec::Interval(columns) => { + let builder = Self::take_block_vec_primitive_types(columns, indices); + let i = + ::upcast_column(::column_from_vec(builder, &[])) + .into_interval() + .unwrap(); + Column::Interval(i) } ColumnVec::Array(columns) => { let data_type = data_type.as_array().unwrap(); diff --git a/src/query/expression/src/utils/visitor.rs b/src/query/expression/src/utils/visitor.rs index 00e75116dac40..90f52ca132d50 100755 --- a/src/query/expression/src/utils/visitor.rs +++ b/src/query/expression/src/utils/visitor.rs @@ -14,6 +14,7 @@ use databend_common_column::bitmap::Bitmap; use databend_common_column::buffer::Buffer; +use databend_common_column::types::months_days_ns; use databend_common_exception::Result; use decimal::DecimalType; use geometry::GeometryType; @@ -79,6 +80,10 @@ pub trait ValueVisitor { self.visit_typed_column::(buffer) } + fn visit_interval(&mut self, buffer: Buffer) -> Result<()> { + self.visit_typed_column::(buffer) + } + fn visit_array(&mut self, column: Box>) -> Result<()> { self.visit_typed_column::(Column::Array(column)) } @@ -132,8 +137,7 @@ pub trait ValueVisitor { Column::String(column) => self.visit_string(column), Column::Timestamp(buffer) => self.visit_timestamp(buffer), Column::Date(buffer) => self.visit_date(buffer), - // TODO: impl visitor - Column::Interval(_) => unimplemented!(), + Column::Interval(buffer) => self.visit_interval(buffer), Column::Array(column) => self.visit_array(column), Column::Map(column) => self.visit_map(column), Column::Tuple(columns) => self.visit_tuple(columns), diff --git a/src/query/formats/src/field_decoder/fast_values.rs b/src/query/formats/src/field_decoder/fast_values.rs index 6be4c0999a981..6204df7f6499a 100644 --- a/src/query/formats/src/field_decoder/fast_values.rs +++ b/src/query/formats/src/field_decoder/fast_values.rs @@ -157,7 +157,6 @@ impl FastFieldDecoderValues { ColumnBuilder::Geometry(c) => self.read_geometry(c, reader, positions), ColumnBuilder::Geography(c) => self.read_geography(c, reader, positions), ColumnBuilder::Binary(_) => Err(ErrorCode::Unimplemented("binary literal")), - // TODO ColumnBuilder::Interval(c) => self.read_interval(c, reader, positions), ColumnBuilder::EmptyArray { .. } | ColumnBuilder::EmptyMap { .. } => { Err(ErrorCode::Unimplemented("empty array/map literal"))