Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed Oct 15, 2024
1 parent 0c1473b commit 2e2e5f6
Show file tree
Hide file tree
Showing 34 changed files with 52 additions and 202 deletions.
3 changes: 1 addition & 2 deletions src/query/expression/src/converts/arrow2/from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use super::ARROW_EXT_TYPE_EMPTY_MAP;
use super::ARROW_EXT_TYPE_GEOMETRY;
use super::ARROW_EXT_TYPE_VARIANT;
use crate::types::array::ArrayColumn;
use crate::types::binary;
use crate::types::binary::BinaryColumn;
use crate::types::binary::BinaryColumnBuilder;
use crate::types::decimal::DecimalColumn;
Expand Down Expand Up @@ -365,7 +364,7 @@ impl Column {
);
Column::Binary(binary_array_to_binary_column(arrow_col))
}
(DataType::Binary, ArrowDataType::FixedSizeBinary(size)) => {
(DataType::Binary, ArrowDataType::FixedSizeBinary(_)) => {
let arrow_col = arrow_col
.as_any()
.downcast_ref::<databend_common_arrow::arrow::array::FixedSizeBinaryArray>()
Expand Down
2 changes: 1 addition & 1 deletion src/query/expression/src/filter/filter_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl FilterExecutor {
if self.keep_order && self.has_or {
self.true_selection[0..result_count].sort();
}
data_block.take(&self.true_selection[0..result_count], &mut None)
data_block.take(&self.true_selection[0..result_count])
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ impl<'a> Selector<'a> {
for idx in 0u32..count as u32 {
let ret = if NOT {
validity.get_bit_unchecked(idx as usize)
&& !searcher
&& searcher
.search(column.index_unchecked_bytes(idx as usize))
.is_some()
.is_none()
} else {
validity.get_bit_unchecked(idx as usize)
&& searcher
Expand Down Expand Up @@ -273,9 +273,9 @@ impl<'a> Selector<'a> {
if let LikePattern::SurroundByPercent(searcher) = like_pattern {
for idx in 0u32..count as u32 {
let ret = if NOT {
!searcher
searcher
.search(column.index_unchecked_bytes(idx as usize))
.is_some()
.is_none()
} else {
searcher
.search(column.index_unchecked_bytes(idx as usize))
Expand Down
1 change: 0 additions & 1 deletion src/query/expression/src/kernels/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use itertools::Itertools;

use crate::copy_continuous_bits;
use crate::kernels::take::BIT_MASK;
use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::store_advance_aligned;
use crate::types::array::ArrayColumnBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

use databend_common_arrow::arrow::array::BinaryViewArray;
use databend_common_arrow::arrow::buffer::Buffer;
use databend_common_exception::Result;
use databend_common_hashtable::hash_join_fast_string_hash;

Expand Down
2 changes: 0 additions & 2 deletions src/query/expression/src/kernels/group_by_hash/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use ethnum::i256;

use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::kernels::utils::store_advance;
use crate::kernels::utils::store_advance_aligned;
use crate::types::binary::BinaryColumn;
use crate::types::binary::BinaryColumnBuilder;
use crate::types::decimal::DecimalColumn;
Expand Down
17 changes: 1 addition & 16 deletions src/query/expression/src/kernels/scatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,9 @@ impl DataBlock {

let scatter_indices = Self::divide_indices_by_scatter_size(indices, scatter_size);

let has_string_column = self
.columns()
.iter()
.any(|col| col.data_type.is_string_column());
let mut string_items_buf = if has_string_column {
let max_num_rows = scatter_indices
.iter()
.map(|indices| indices.len())
.max()
.unwrap();
Some(vec![(0, 0); max_num_rows])
} else {
None
};

let mut results = Vec::with_capacity(scatter_size);
for indices in scatter_indices.iter().take(scatter_size) {
let block = self.take(indices, &mut string_items_buf)?;
let block = self.take(indices)?;
results.push(block);
}

Expand Down
2 changes: 1 addition & 1 deletion src/query/expression/src/kernels/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl DataBlock {
}

let permutations = sort_compare.take_permutation();
DataBlock::take(block, &permutations, &mut None)
DataBlock::take(block, &permutations)
}
}

Expand Down
18 changes: 4 additions & 14 deletions src/query/expression/src/kernels/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use databend_common_arrow::arrow::bitmap::Bitmap;
use databend_common_arrow::arrow::buffer::Buffer;
use databend_common_exception::Result;

use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::types::binary::BinaryColumn;
use crate::types::nullable::NullableColumn;
use crate::types::string::StringColumn;
Expand All @@ -34,19 +32,13 @@ use crate::Value;
pub const BIT_MASK: [u8; 8] = [1, 2, 4, 8, 16, 32, 64, 128];

impl DataBlock {
pub fn take<I>(
&self,
indices: &[I],
string_items_buf: &mut Option<Vec<(u64, usize)>>,
) -> Result<Self>
where
I: databend_common_arrow::arrow::types::Index,
{
pub fn take<I>(&self, indices: &[I]) -> Result<Self>
where I: databend_common_arrow::arrow::types::Index {
if indices.is_empty() {
return Ok(self.slice(0..0));
}

let mut taker = TakeVisitor::new(indices, string_items_buf);
let mut taker = TakeVisitor::new(indices);

let after_columns = self
.columns()
Expand All @@ -73,17 +65,15 @@ struct TakeVisitor<'a, I>
where I: databend_common_arrow::arrow::types::Index
{
indices: &'a [I],
string_items_buf: &'a mut Option<Vec<(u64, usize)>>,
result: Option<Value<AnyType>>,
}

impl<'a, I> TakeVisitor<'a, I>
where I: databend_common_arrow::arrow::types::Index
{
fn new(indices: &'a [I], string_items_buf: &'a mut Option<Vec<(u64, usize)>>) -> Self {
fn new(indices: &'a [I]) -> Self {
Self {
indices,
string_items_buf,
result: None,
}
}
Expand Down
55 changes: 18 additions & 37 deletions src/query/expression/src/kernels/take_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ use databend_common_hashtable::RowPtr;
use itertools::Itertools;

use crate::kernels::take::BIT_MASK;
use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::types::array::ArrayColumnBuilder;
use crate::types::binary::BinaryColumn;
use crate::types::bitmap::BitmapType;
Expand Down Expand Up @@ -112,7 +110,6 @@ impl DataBlock {
build_columns_data_type: &[DataType],
indices: &[RowPtr],
result_size: usize,
binary_items_buf: &mut Option<Vec<(u64, usize)>>,
) -> Self {
let num_columns = build_columns.len();
let result_columns = (0..num_columns)
Expand All @@ -123,7 +120,6 @@ impl DataBlock {
data_type.clone(),
indices,
result_size,
binary_items_buf,
);
BlockEntry::new(data_type.clone(), Value::Column(column))
})
Expand Down Expand Up @@ -632,7 +628,6 @@ impl Column {
data_type: DataType,
indices: &[RowPtr],
result_size: usize,
binary_items_buf: &mut Option<Vec<(u64, usize)>>,
) -> Column {
match &columns {
ColumnVec::Null { .. } => Column::Null { len: result_size },
Expand All @@ -656,12 +651,12 @@ impl Column {
ColumnVec::Boolean(columns) => {
Column::Boolean(Self::take_block_vec_boolean_types(columns, indices))
}
ColumnVec::Binary(columns) => BinaryType::upcast_column(
Self::take_block_vec_binary_types(columns, indices, binary_items_buf.as_mut()),
),
ColumnVec::String(columns) => StringType::upcast_column(
Self::take_block_vec_string_types(columns, indices, binary_items_buf.as_mut()),
),
ColumnVec::Binary(columns) => {
BinaryType::upcast_column(Self::take_block_vec_binary_types(columns, indices))
}
ColumnVec::String(columns) => {
StringType::upcast_column(Self::take_block_vec_string_types(columns, indices))
}
ColumnVec::Timestamp(columns) => {
let builder = Self::take_block_vec_primitive_types(columns, indices);
let ts = <NumberType<i64>>::upcast_column(<NumberType<i64>>::column_from_vec(
Expand Down Expand Up @@ -714,25 +709,23 @@ impl Column {
columns, builder, indices,
)
}
ColumnVec::Bitmap(columns) => BitmapType::upcast_column(
Self::take_block_vec_binary_types(columns, indices, binary_items_buf.as_mut()),
),
ColumnVec::Bitmap(columns) => {
BitmapType::upcast_column(Self::take_block_vec_binary_types(columns, indices))
}
ColumnVec::Nullable(columns) => {
let inner_data_type = data_type.as_nullable().unwrap();
let inner_column = Self::take_column_vec_indices(
&columns.column,
*inner_data_type.clone(),
indices,
result_size,
binary_items_buf,
);

let inner_bitmap = Self::take_column_vec_indices(
&columns.validity,
DataType::Boolean,
indices,
result_size,
binary_items_buf,
);

NullableColumn::new_column(
Expand All @@ -751,25 +744,22 @@ impl Column {
ty.clone(),
indices,
result_size,
binary_items_buf,
)
})
.collect();

Column::Tuple(fields)
}
ColumnVec::Variant(columns) => VariantType::upcast_column(
Self::take_block_vec_binary_types(columns, indices, binary_items_buf.as_mut()),
),
ColumnVec::Geometry(columns) => GeometryType::upcast_column(
Self::take_block_vec_binary_types(columns, indices, binary_items_buf.as_mut()),
),
ColumnVec::Variant(columns) => {
VariantType::upcast_column(Self::take_block_vec_binary_types(columns, indices))
}
ColumnVec::Geometry(columns) => {
GeometryType::upcast_column(Self::take_block_vec_binary_types(columns, indices))
}
ColumnVec::Geography(columns) => {
let columns = columns.iter().map(|x| x.0.clone()).collect::<Vec<_>>();
GeographyType::upcast_column(GeographyColumn(Self::take_block_vec_binary_types(
&columns,
indices,
binary_items_buf.as_mut(),
&columns, indices,
)))
}
}
Expand All @@ -785,11 +775,7 @@ impl Column {
builder
}

pub fn take_block_vec_binary_types(
col: &[BinaryColumn],
indices: &[RowPtr],
binary_items_buf: Option<&mut Vec<(u64, usize)>>,
) -> BinaryColumn {
pub fn take_block_vec_binary_types(col: &[BinaryColumn], indices: &[RowPtr]) -> BinaryColumn {
let mut builder = BinaryColumnBuilder::with_capacity(indices.len(), 0);
for row_ptr in indices {
unsafe {
Expand All @@ -802,11 +788,7 @@ impl Column {
builder.build()
}

pub fn take_block_vec_string_types(
cols: &[StringColumn],
indices: &[RowPtr],
binary_items_buf: Option<&mut Vec<(u64, usize)>>,
) -> StringColumn {
pub fn take_block_vec_string_types(cols: &[StringColumn], indices: &[RowPtr]) -> StringColumn {
let binary_cols = cols
.iter()
.map(|col| col.clone().into())
Expand All @@ -815,7 +797,6 @@ impl Column {
StringColumn::from_binary_unchecked(Self::take_block_vec_binary_types(
&binary_cols,
indices,
binary_items_buf,
))
}
}
Expand Down
1 change: 0 additions & 1 deletion src/query/expression/src/kernels/take_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use databend_common_exception::Result;

use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::kernels::utils::store_advance_aligned;
use crate::types::binary::BinaryColumn;
use crate::types::nullable::NullableColumn;
use crate::types::string::StringColumn;
Expand Down
1 change: 0 additions & 1 deletion src/query/expression/src/kernels/take_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use databend_common_exception::Result;

use crate::copy_continuous_bits;
use crate::kernels::take::BIT_MASK;
use crate::kernels::utils::copy_advance_aligned;
use crate::kernels::utils::set_vec_len_by_ptr;
use crate::kernels::utils::store_advance_aligned;
use crate::types::binary::BinaryColumn;
Expand Down
6 changes: 0 additions & 6 deletions src/query/expression/src/types/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,11 @@

use std::cmp::Ordering;
use std::iter::once;
use std::marker::PhantomData;
use std::ops::Range;

use databend_common_arrow::arrow::array::Array;
use databend_common_arrow::arrow::array::BinaryViewArray;
use databend_common_arrow::arrow::array::MutableBinaryViewArray;
use databend_common_arrow::arrow::buffer::Buffer;
use databend_common_arrow::arrow::trusted_len::TrustedLen;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use serde::Deserialize;
use serde::Serialize;

Expand All @@ -33,7 +28,6 @@ use crate::types::DataType;
use crate::types::DecimalSize;
use crate::types::GenericMap;
use crate::types::ValueType;
use crate::utils::arrow::buffer_into_mut;
use crate::values::Column;
use crate::values::Scalar;
use crate::ColumnBuilder;
Expand Down
2 changes: 0 additions & 2 deletions src/query/expression/src/types/geography.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
use std::cmp::Ordering;
use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
use std::ops::Range;

use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use databend_common_arrow::arrow::trusted_len::TrustedLen;
use databend_common_arrow::parquet::encoding::plain_byte_array::BinaryIter;
use databend_common_exception::Result;
use databend_common_io::geography::*;
use databend_common_io::wkb::make_point;
Expand Down
4 changes: 0 additions & 4 deletions src/query/expression/src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
// limitations under the License.

use std::cmp::Ordering;
use std::iter::once;
use std::ops::Range;

use databend_common_arrow::arrow::array::Array;
use databend_common_arrow::arrow::array::BinaryViewArray;
use databend_common_arrow::arrow::buffer::Buffer;
use databend_common_arrow::arrow::trusted_len::TrustedLen;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
Expand All @@ -34,7 +31,6 @@ use crate::types::DataType;
use crate::types::DecimalSize;
use crate::types::GenericMap;
use crate::types::ValueType;
use crate::utils::arrow::buffer_into_mut;
use crate::values::Column;
use crate::values::Scalar;
use crate::ColumnBuilder;
Expand Down
Loading

0 comments on commit 2e2e5f6

Please sign in to comment.