Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use std::sync::Arc;

use crate::aggregates::group_values::multi_group_by::Nulls;
use crate::aggregates::group_values::multi_group_by::{nulls_equal_to, GroupColumn};
use crate::aggregates::group_values::null_builder::MaybeNullBufferBuilder;
use arrow::array::{Array as _, ArrayRef, AsArray, BooleanArray, BooleanBufferBuilder};
Expand Down Expand Up @@ -115,15 +116,15 @@ impl<const NULLABLE: bool> GroupColumn for BooleanGroupValueBuilder<NULLABLE> {
let null_count = array.null_count();
let num_rows = array.len();
let all_null_or_non_null = if null_count == 0 {
Some(true)
Nulls::None
} else if null_count == num_rows {
Some(false)
Nulls::All
} else {
None
Nulls::Some
};

match (NULLABLE, all_null_or_non_null) {
(true, None) => {
(true, Nulls::Some) => {
for &row in rows {
if array.is_null(row) {
self.nulls.append(true);
Expand All @@ -135,14 +136,14 @@ impl<const NULLABLE: bool> GroupColumn for BooleanGroupValueBuilder<NULLABLE> {
}
}

(true, Some(true)) => {
(true, Nulls::None) => {
self.nulls.append_n(rows.len(), false);
for &row in rows {
self.buffer.append(arr.value(row));
}
}

(true, Some(false)) => {
(true, Nulls::All) => {
self.nulls.append_n(rows.len(), true);
self.buffer.append_n(rows.len(), bool::default());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// specific language governing permissions and limitations
// under the License.

use crate::aggregates::group_values::multi_group_by::{nulls_equal_to, GroupColumn};
use crate::aggregates::group_values::multi_group_by::{
nulls_equal_to, GroupColumn, Nulls,
};
use crate::aggregates::group_values::null_builder::MaybeNullBufferBuilder;
use arrow::array::{
types::GenericStringType, Array, ArrayRef, AsArray, BufferBuilder,
Expand Down Expand Up @@ -138,28 +140,28 @@ where
let null_count = array.null_count();
let num_rows = array.len();
let all_null_or_non_null = if null_count == 0 {
Some(true)
Nulls::None
} else if null_count == num_rows {
Some(false)
Nulls::All
} else {
None
Nulls::Some
};

match all_null_or_non_null {
None => {
Nulls::Some => {
for &row in rows {
self.append_val_inner::<B>(array, row)?
}
}

Some(true) => {
Nulls::None => {
self.nulls.append_n(rows.len(), false);
for &row in rows {
self.do_append_val_inner(arr, row)?;
}
}

Some(false) => {
Nulls::All => {
self.nulls.append_n(rows.len(), true);

let new_len = self.offsets.len() + rows.len();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// specific language governing permissions and limitations
// under the License.

use crate::aggregates::group_values::multi_group_by::{nulls_equal_to, GroupColumn};
use crate::aggregates::group_values::multi_group_by::{
nulls_equal_to, GroupColumn, Nulls,
};
use crate::aggregates::group_values::null_builder::MaybeNullBufferBuilder;
use arrow::array::{make_view, Array, ArrayRef, AsArray, ByteView, GenericByteViewArray};
use arrow::buffer::{Buffer, ScalarBuffer};
Expand Down Expand Up @@ -145,28 +147,28 @@ impl<B: ByteViewType> ByteViewGroupValueBuilder<B> {
let null_count = array.null_count();
let num_rows = array.len();
let all_null_or_non_null = if null_count == 0 {
Some(true)
Nulls::None
} else if null_count == num_rows {
Some(false)
Nulls::All
} else {
None
Nulls::Some
};

match all_null_or_non_null {
None => {
Nulls::Some => {
for &row in rows {
self.append_val_inner(array, row);
}
}

Some(true) => {
Nulls::None => {
self.nulls.append_n(rows.len(), false);
for &row in rows {
self.do_append_val_inner(arr, row);
}
}

Some(false) => {
Nulls::All => {
self.nulls.append_n(rows.len(), true);
let new_len = self.views.len() + rows.len();
self.views.resize(new_len, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,16 @@ fn supported_type(data_type: &DataType) -> bool {
)
}

///Shows how many `null`s there are in an array
enum Nulls {
/// All array items are `null`s
All,
/// There are both `null`s and non-`null`s in the array items
Some,
/// There are no `null`s in the array items
None,
}

#[cfg(test)]
mod tests {
use std::{collections::HashMap, sync::Arc};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// specific language governing permissions and limitations
// under the License.

use crate::aggregates::group_values::multi_group_by::{nulls_equal_to, GroupColumn};
use crate::aggregates::group_values::multi_group_by::{
nulls_equal_to, GroupColumn, Nulls,
};
use crate::aggregates::group_values::null_builder::MaybeNullBufferBuilder;
use arrow::array::ArrowNativeTypeOp;
use arrow::array::{cast::AsArray, Array, ArrayRef, ArrowPrimitiveType, PrimitiveArray};
Expand Down Expand Up @@ -132,15 +134,15 @@ impl<T: ArrowPrimitiveType, const NULLABLE: bool> GroupColumn
let null_count = array.null_count();
let num_rows = array.len();
let all_null_or_non_null = if null_count == 0 {
Some(true)
Nulls::None
} else if null_count == num_rows {
Some(false)
Nulls::All
} else {
None
Nulls::Some
};

match (NULLABLE, all_null_or_non_null) {
(true, None) => {
(true, Nulls::Some) => {
for &row in rows {
if array.is_null(row) {
self.nulls.append(true);
Expand All @@ -152,14 +154,14 @@ impl<T: ArrowPrimitiveType, const NULLABLE: bool> GroupColumn
}
}

(true, Some(true)) => {
(true, Nulls::None) => {
self.nulls.append_n(rows.len(), false);
for &row in rows {
self.group_values.push(arr.value(row));
}
}

(true, Some(false)) => {
(true, Nulls::All) => {
self.nulls.append_n(rows.len(), true);
self.group_values
.extend(iter::repeat_n(T::default_value(), rows.len()));
Expand Down