-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add boolean column to aggregate queries for fuzz testing (#13331)
* add bool col * clippy fix * remove change * fmt fix * typo fix
- Loading branch information
1 parent
f894c7d
commit 5467a28
Showing
4 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use arrow::array::{ArrayRef, BooleanArray, BooleanBuilder, UInt32Array}; | ||
use arrow::compute::take; | ||
use rand::rngs::StdRng; | ||
use rand::Rng; | ||
|
||
/// Randomly generate boolean arrays | ||
pub struct BooleanArrayGenerator { | ||
pub num_booleans: usize, | ||
pub num_distinct_booleans: usize, | ||
pub null_pct: f64, | ||
pub rng: StdRng, | ||
} | ||
|
||
impl BooleanArrayGenerator { | ||
/// Generate BooleanArray with bit-packed values | ||
pub fn gen_data<D>(&mut self) -> ArrayRef { | ||
// Table of booleans from which to draw (distinct means 1 or 2) | ||
let distinct_booleans: BooleanArray = match self.num_distinct_booleans { | ||
1 => { | ||
let value = self.rng.gen::<bool>(); | ||
let mut builder = BooleanBuilder::with_capacity(1); | ||
builder.append_value(value); | ||
builder.finish() | ||
} | ||
2 => { | ||
let mut builder = BooleanBuilder::with_capacity(2); | ||
builder.append_value(true); | ||
builder.append_value(false); | ||
builder.finish() | ||
} | ||
_ => unreachable!(), | ||
}; | ||
|
||
// Generate indices to select from the distinct booleans | ||
let indices: UInt32Array = (0..self.num_booleans) | ||
.map(|_| { | ||
if self.rng.gen::<f64>() < self.null_pct { | ||
None | ||
} else if self.num_distinct_booleans > 1 { | ||
Some(self.rng.gen_range(0..self.num_distinct_booleans as u32)) | ||
} else { | ||
Some(0) | ||
} | ||
}) | ||
.collect(); | ||
|
||
let options = None; | ||
|
||
take(&distinct_booleans, &indices, options).unwrap() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters