MCPcopy Create free account
hub / github.com/apache/datafusion / gen_data

Method gen_data

test-utils/src/array_gen/boolean.rs:33–67  ·  view source on GitHub ↗

Generate BooleanArray with bit-packed values

(&mut self)

Source from the content-addressed store, hash-verified

31impl BooleanArrayGenerator {
32 /// Generate BooleanArray with bit-packed values
33 pub fn gen_data<D>(&mut self) -> ArrayRef {
34 // Table of booleans from which to draw (distinct means 1 or 2)
35 let distinct_booleans: BooleanArray = match self.num_distinct_booleans {
36 1 => {
37 let value = self.rng.random::<bool>();
38 let mut builder = BooleanBuilder::with_capacity(1);
39 builder.append_value(value);
40 builder.finish()
41 }
42 2 => {
43 let mut builder = BooleanBuilder::with_capacity(2);
44 builder.append_value(true);
45 builder.append_value(false);
46 builder.finish()
47 }
48 _ => unreachable!(),
49 };
50
51 // Generate indices to select from the distinct booleans
52 let indices: UInt32Array = (0..self.num_booleans)
53 .map(|_| {
54 if self.rng.random::<f64>() < self.null_pct {
55 None
56 } else if self.num_distinct_booleans > 1 {
57 Some(self.rng.random_range(0..self.num_distinct_booleans as u32))
58 } else {
59 Some(0)
60 }
61 })
62 .collect();
63
64 let options = None;
65
66 take(&distinct_booleans, &indices, options).unwrap()
67 }
68}

Callers

nothing calls this directly

Calls 4

collectMethod · 0.80
append_valueMethod · 0.45
finishMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected