Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring boolean builder apis #2501

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow/benches/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn bench_bool(c: &mut Criterion) {
));
group.bench_function("bench_bool", |b| {
b.iter(|| {
let mut builder = BooleanBuilder::new(64);
let mut builder = BooleanBuilder::with_capacity(64);
for _ in 0..NUM_BATCHES {
builder.append_slice(&data[..]);
}
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/array/array_boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl BooleanArray {

// Returns a new boolean array builder
pub fn builder(capacity: usize) -> BooleanBuilder {
BooleanBuilder::new(capacity)
BooleanBuilder::with_capacity(capacity)
}

/// Returns a `Buffer` holding all the values of this array.
Expand Down
12 changes: 9 additions & 3 deletions arrow/src/array/builder/boolean_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use super::NullBufferBuilder;
/// ```
/// use arrow::array::{Array, BooleanArray, BooleanBuilder};
///
/// let mut b = BooleanBuilder::new(4);
/// let mut b = BooleanBuilder::new();
/// b.append_value(true);
/// b.append_null();
/// b.append_value(false);
Expand Down Expand Up @@ -67,8 +67,14 @@ pub struct BooleanBuilder {
}

impl BooleanBuilder {
/// Creates a new primitive array builder
pub fn new(capacity: usize) -> Self {
/// Creates a new boolean builder
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self::with_capacity(1024)
}

/// Creates a new boolean builder with capacity
pub fn with_capacity(capacity: usize) -> Self {
Self {
values_builder: BooleanBufferBuilder::new(capacity),
null_buffer_builder: NullBufferBuilder::new(capacity),
Expand Down
6 changes: 3 additions & 3 deletions arrow/src/array/builder/struct_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl ArrayBuilder for StructBuilder {
pub fn make_builder(datatype: &DataType, capacity: usize) -> Box<dyn ArrayBuilder> {
match datatype {
DataType::Null => unimplemented!(),
DataType::Boolean => Box::new(BooleanBuilder::new(capacity)),
DataType::Boolean => Box::new(BooleanBuilder::with_capacity(capacity)),
DataType::Int8 => Box::new(Int8Builder::new(capacity)),
DataType::Int16 => Box::new(Int16Builder::new(capacity)),
DataType::Int32 => Box::new(Int32Builder::new(capacity)),
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {
#[test]
fn test_struct_array_builder_finish() {
let int_builder = Int32Builder::new(10);
let bool_builder = BooleanBuilder::new(10);
let bool_builder = BooleanBuilder::new();

let mut fields = Vec::new();
let mut field_builders = Vec::new();
Expand Down Expand Up @@ -426,7 +426,7 @@ mod tests {
#[should_panic(expected = "StructBuilder and field_builders are of unequal lengths.")]
fn test_struct_array_builder_unequal_field_builders_lengths() {
let mut int_builder = Int32Builder::new(10);
let mut bool_builder = BooleanBuilder::new(10);
let mut bool_builder = BooleanBuilder::new();

int_builder.append_value(1);
int_builder.append_value(2);
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ mod tests {
],
vec![
Box::new(Int32Builder::new(5)),
Box::new(BooleanBuilder::new(5)),
Box::new(BooleanBuilder::with_capacity(5)),
],
);

Expand Down
2 changes: 1 addition & 1 deletion arrow/src/compute/kernels/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ fn numeric_to_bool_cast<T>(from: &PrimitiveArray<T>) -> Result<BooleanArray>
where
T: ArrowPrimitiveType + ArrowNumericType,
{
let mut b = BooleanBuilder::new(from.len());
let mut b = BooleanBuilder::with_capacity(from.len());

for i in 0..from.len() {
if from.is_null(i) {
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/compute/kernels/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ mod tests {
#[test]
fn test_filter_string_array_with_negated_boolean_array() {
let a = StringArray::from(vec!["hello", " ", "world", "!"]);
let mut bb = BooleanBuilder::new(2);
let mut bb = BooleanBuilder::with_capacity(2);
bb.append_value(false);
bb.append_value(true);
bb.append_value(false);
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/compute/kernels/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ mod tests {
Field::new("b", DataType::Int32, true),
],
vec![
Box::new(BooleanBuilder::new(values.len())),
Box::new(BooleanBuilder::with_capacity(values.len())),
Box::new(Int32Builder::new(values.len())),
],
);
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/json/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ impl Decoder {
}

fn build_boolean_array(&self, rows: &[Value], col_name: &str) -> Result<ArrayRef> {
let mut builder = BooleanBuilder::new(rows.len());
let mut builder = BooleanBuilder::with_capacity(rows.len());
for row in rows {
if let Some(value) = row.get(&col_name) {
if let Some(boolean) = value.as_bool() {
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/util/integration_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn array_from_json(
match field.data_type() {
DataType::Null => Ok(Arc::new(NullArray::new(json_col.count))),
DataType::Boolean => {
let mut b = BooleanBuilder::new(json_col.count);
let mut b = BooleanBuilder::with_capacity(json_col.count);
for (is_valid, value) in json_col
.validity
.as_ref()
Expand Down