Skip to content

Commit 96bbf63

Browse files
authored
docs: more docs around AnalysisExpr and boolean operators (#3508)
Signed-off-by: Daniel King <[email protected]>
1 parent 72c8258 commit 96bbf63

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

vortex-array/src/compute/boolean.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,42 @@ use crate::{Array, ArrayRef};
1414

1515
/// Point-wise logical _and_ between two Boolean arrays.
1616
///
17-
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics.
17+
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics. This
18+
/// semantics is also known as "Bochvar logic" and "weak Kleene logic".
19+
///
20+
/// See also [BooleanOperator::And]
1821
pub fn and(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult<ArrayRef> {
1922
boolean(lhs, rhs, BooleanOperator::And)
2023
}
2124

2225
/// Point-wise Kleene logical _and_ between two Boolean arrays.
26+
///
27+
/// See also [BooleanOperator::AndKleene]
2328
pub fn and_kleene(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult<ArrayRef> {
2429
boolean(lhs, rhs, BooleanOperator::AndKleene)
2530
}
2631

2732
/// Point-wise logical _or_ between two Boolean arrays.
2833
///
29-
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics.
34+
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics. This
35+
/// semantics is also known as "Bochvar logic" and "weak Kleene logic".
36+
///
37+
/// See also [BooleanOperator::Or]
3038
pub fn or(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult<ArrayRef> {
3139
boolean(lhs, rhs, BooleanOperator::Or)
3240
}
3341

3442
/// Point-wise Kleene logical _or_ between two Boolean arrays.
43+
///
44+
/// See also [BooleanOperator::OrKleene]
3545
pub fn or_kleene(lhs: &dyn Array, rhs: &dyn Array) -> VortexResult<ArrayRef> {
3646
boolean(lhs, rhs, BooleanOperator::OrKleene)
3747
}
3848

3949
/// Point-wise logical operator between two Boolean arrays.
4050
///
41-
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics.
51+
/// This method uses Arrow-style null propagation rather than the Kleene logic semantics. This
52+
/// semantics is also known as "Bochvar logic" and "weak Kleene logic".
4253
pub fn boolean(lhs: &dyn Array, rhs: &dyn Array, op: BooleanOperator) -> VortexResult<ArrayRef> {
4354
BOOLEAN_FN
4455
.invoke(&InvocationArgs {
@@ -181,11 +192,46 @@ impl ComputeFnVTable for Boolean {
181192
}
182193
}
183194

195+
/// Operations over the nullable Boolean values.
196+
///
197+
/// All three operators accept and produce values from the set {true, false, and null}.
184198
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
185199
pub enum BooleanOperator {
200+
/// Logical and, unless either value is null, in which case the result is null.
201+
///
202+
/// | A ∧ B | | **B** | | |
203+
/// |:-----:|:-----:|:-----:|:-----:|:-----:|
204+
/// | | | **F** | **U** | **T** |
205+
/// | **A** | **F** | F | U | F |
206+
/// | | **U** | U | U | U |
207+
/// | | **T** | F | U | T |
186208
And,
209+
/// [Kleene (three-valued) logical and](https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics).
210+
///
211+
/// | A ∧ B | | **B** | | |
212+
/// |:-----:|:-----:|:-----:|:-----:|:-----:|
213+
/// | | | **F** | **U** | **T** |
214+
/// | **A** | **F** | F | F | F |
215+
/// | | **U** | F | U | U |
216+
/// | | **T** | F | U | T |
187217
AndKleene,
218+
/// Logical or, unless either value is null, in which case the result is null.
219+
///
220+
/// | A ∨ B | | **B** | | |
221+
/// |:-----:|:-----:|:-----:|:-----:|:-----:|
222+
/// | | | **F** | **U** | **T** |
223+
/// | **A** | **F** | F | U | T |
224+
/// | | **U** | U | U | U |
225+
/// | | **T** | T | U | T |
188226
Or,
227+
/// [Kleene (three-valued) logical or](https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics).
228+
///
229+
/// | A ∨ B | | **B** | | |
230+
/// |:-----:|:-----:|:-----:|:-----:|:-----:|
231+
/// | | | **F** | **U** | **T** |
232+
/// | **A** | **F** | F | U | T |
233+
/// | | **U** | U | U | T |
234+
/// | | **T** | T | T | T |
189235
OrKleene,
190236
// AndNot,
191237
// AndNotKleene,

vortex-expr/src/analysis.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,20 @@ pub trait AnalysisExpr {
3535
None
3636
}
3737

38-
/// If an expression is returned, its value is an upper bound on the value of `expr`.
38+
/// An expression for the upper non-null bound of this expression, if available.
3939
///
40-
/// We may return `None` for values which have no upper bound or values for which knowing the
41-
/// upper bound is difficult.
40+
/// This function returns None if there is no upper bound or it is difficult to compute.
41+
///
42+
/// The returned expression evaluates to null if the maximum value is unknown. In that case, you
43+
/// _must not_ assume the array is empty _nor_ may you assume the array only contains non-null
44+
/// values.
4245
fn max(&self, _catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
4346
None
4447
}
45-
/// If an expression is returned, its value is an upper bound on the value of `expr`.
46-
/// see `AnalysisExpr::max`
48+
49+
/// An expression for the lower non-null bound of this expression, if available.
50+
///
51+
/// See [AnalysisExpr::max] for important details.
4752
fn min(&self, _catalog: &mut dyn StatsCatalog) -> Option<ExprRef> {
4853
None
4954
}

vortex-expr/src/exprs/operators.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ use std::fmt::{Display, Formatter};
33

44
use vortex_array::compute;
55

6+
/// Equalities, inequalities, and boolean operations over possibly null values.
7+
///
8+
/// For the equalities and inequalities, if either side is null, the result is null. The Boolean
9+
/// operators obey [Kleene (three-valued) logic](https://en.wikipedia.org/wiki/Three-valued_logic#Kleene_and_Priest_logics).
610
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
711
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
812
pub enum Operator {

vortex-layout/src/layouts/zoned/reader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,15 @@ impl LayoutReader for ZonedReader {
250250
struct ZoneMapPruningEvaluation {
251251
name: Arc<str>,
252252
expr: ExprRef,
253+
/// A mask indicating zones which have no matching values.
254+
///
255+
/// A false value indicates the corresponding zone may have a matching value.
253256
pruning_mask_future: SharedPruningResult,
254-
// The set of zone IDs that are available to the evaluation.
257+
/// The set of zone IDs that are available to the evaluation.
255258
zone_range: Range<u64>,
256-
// The lengths of each zone in the zone_range.
259+
/// The lengths of each zone in the zone_range.
257260
zone_lengths: Vec<usize>,
258-
// The evaluation of the data child.
261+
/// The evaluation of the data child.
259262
data_eval: Box<dyn PruningEvaluation>,
260263
}
261264

0 commit comments

Comments
 (0)