Skip to content

Commit 07feef3

Browse files
authored
chore: Add docs to the stand alone expr creation functions (#4253)
Signed-off-by: Adam Gutglick <[email protected]>
1 parent a23a730 commit 07feef3

File tree

19 files changed

+192
-90
lines changed

19 files changed

+192
-90
lines changed

vortex-cxx/src/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) struct Expr {
1212

1313
pub(crate) fn literal(scalar: Box<Scalar>) -> Box<Expr> {
1414
Box::new(Expr {
15-
inner: vortex::expr::literal::lit(scalar.inner),
15+
inner: vortex::expr::lit(scalar.inner),
1616
})
1717
}
1818

vortex-expr/src/analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait AnalysisExpr {
2929
/// necessarily true: even if the falsification evaluates to false, `e` need not evaluate to
3030
/// true on all records.
3131
///
32-
/// The `StatsCatalog` can be used to constrain or rename stats used in the final expr.
32+
/// The [`StatsCatalog`] can be used to constrain or rename stats used in the final expr.
3333
///
3434
/// # Examples
3535
///

vortex-expr/src/dyn_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::any::Any;
55

66
// TODO(adam): Look into having a similar setup as dyn-hash that will allow deriving `PartialEq` for structs
77
// that have `Arc<dyn Trait>` fields.
8-
/// Allows comparing dyn-compatible objects, like [`ExprRef`].
8+
/// Allows comparing dyn-compatible objects, like [`ExprRef`](crate::ExprRef).
99
pub trait DynEq {
1010
fn dyn_eq(&self, other: &dyn Any) -> bool;
1111
}

vortex-expr/src/exprs/between.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,21 @@ impl Display for BetweenExpr {
177177

178178
impl AnalysisExpr for BetweenExpr {}
179179

180+
/// Creates an expression that checks if values are between two bounds.
181+
///
182+
/// Returns a boolean array indicating which values fall within the specified range.
183+
/// The comparison strictness is controlled by the options parameter.
184+
///
185+
/// ```rust
186+
/// # use vortex_array::compute::BetweenOptions;
187+
/// # use vortex_array::compute::StrictComparison;
188+
/// # use vortex_expr::{between, lit, root};
189+
/// let opts = BetweenOptions {
190+
/// lower_strict: StrictComparison::NonStrict,
191+
/// upper_strict: StrictComparison::NonStrict,
192+
/// };
193+
/// let expr = between(root(), lit(10), lit(20), opts);
194+
/// ```
180195
pub fn between(arr: ExprRef, lower: ExprRef, upper: ExprRef, options: BetweenOptions) -> ExprRef {
181196
BetweenExpr::new(arr, lower, upper, options).into_expr()
182197
}

vortex-expr/src/exprs/binary.rs

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,16 @@ impl AnalysisExpr for BinaryExpr {
268268
}
269269
}
270270

271-
/// Create a new `BinaryExpr` using the `Eq` operator.
271+
/// Create a new [`BinaryExpr`] using the [`Eq`](crate::Operator::Eq) operator.
272272
///
273273
/// ## Example usage
274274
///
275275
/// ```
276-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
277-
/// use vortex_array::{Array, IntoArray, ToCanonical};
278-
/// use vortex_array::validity::Validity;
279-
/// use vortex_buffer::buffer;
280-
/// use vortex_expr::{eq, root, lit, Scope};
281-
///
276+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
277+
/// # use vortex_array::{Array, IntoArray, ToCanonical};
278+
/// # use vortex_array::validity::Validity;
279+
/// # use vortex_buffer::buffer;
280+
/// # use vortex_expr::{eq, root, lit, Scope};
282281
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
283282
/// let result = eq(root(), lit(3)).evaluate(&Scope::new(xs.to_array())).unwrap();
284283
///
@@ -291,17 +290,16 @@ pub fn eq(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
291290
BinaryExpr::new(lhs, Operator::Eq, rhs).into_expr()
292291
}
293292

294-
/// Create a new `BinaryExpr` using the `NotEq` operator.
293+
/// Create a new [`BinaryExpr`] using the [`NotEq`](crate::Operator::NotEq) operator.
295294
///
296295
/// ## Example usage
297296
///
298297
/// ```
299-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
300-
/// use vortex_array::{IntoArray, ToCanonical};
301-
/// use vortex_array::validity::Validity;
302-
/// use vortex_buffer::buffer;
303-
/// use vortex_expr::{root, lit, not_eq, Scope};
304-
///
298+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
299+
/// # use vortex_array::{IntoArray, ToCanonical};
300+
/// # use vortex_array::validity::Validity;
301+
/// # use vortex_buffer::buffer;
302+
/// # use vortex_expr::{root, lit, not_eq, Scope};
305303
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
306304
/// let result = not_eq(root(), lit(3)).evaluate(&Scope::new(xs.to_array())).unwrap();
307305
///
@@ -314,17 +312,16 @@ pub fn not_eq(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
314312
BinaryExpr::new(lhs, Operator::NotEq, rhs).into_expr()
315313
}
316314

317-
/// Create a new `BinaryExpr` using the `Gte` operator.
315+
/// Create a new [`BinaryExpr`] using the [`Gte`](crate::Operator::Gte) operator.
318316
///
319317
/// ## Example usage
320318
///
321319
/// ```
322-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
323-
/// use vortex_array::{IntoArray, ToCanonical};
324-
/// use vortex_array::validity::Validity;
325-
/// use vortex_buffer::buffer;
326-
/// use vortex_expr::{gt_eq, root, lit, Scope};
327-
///
320+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
321+
/// # use vortex_array::{IntoArray, ToCanonical};
322+
/// # use vortex_array::validity::Validity;
323+
/// # use vortex_buffer::buffer;
324+
/// # use vortex_expr::{gt_eq, root, lit, Scope};
328325
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
329326
/// let result = gt_eq(root(), lit(3)).evaluate(&Scope::new(xs.to_array())).unwrap();
330327
///
@@ -337,17 +334,16 @@ pub fn gt_eq(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
337334
BinaryExpr::new(lhs, Operator::Gte, rhs).into_expr()
338335
}
339336

340-
/// Create a new `BinaryExpr` using the `Gt` operator.
337+
/// Create a new [`BinaryExpr`] using the [`Gt`](crate::Operator::Gt) operator.
341338
///
342339
/// ## Example usage
343340
///
344341
/// ```
345-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
346-
/// use vortex_array::{IntoArray, ToCanonical};
347-
/// use vortex_array::validity::Validity;
348-
/// use vortex_buffer::buffer;
349-
/// use vortex_expr::{gt, root, lit, Scope};
350-
///
342+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
343+
/// # use vortex_array::{IntoArray, ToCanonical};
344+
/// # use vortex_array::validity::Validity;
345+
/// # use vortex_buffer::buffer;
346+
/// # use vortex_expr::{gt, root, lit, Scope};
351347
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
352348
/// let result = gt(root(), lit(2)).evaluate(&Scope::new(xs.to_array())).unwrap();
353349
///
@@ -360,17 +356,16 @@ pub fn gt(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
360356
BinaryExpr::new(lhs, Operator::Gt, rhs).into_expr()
361357
}
362358

363-
/// Create a new `BinaryExpr` using the `Lte` operator.
359+
/// Create a new [`BinaryExpr`] using the [`Lte`](crate::Operator::Lte) operator.
364360
///
365361
/// ## Example usage
366362
///
367363
/// ```
368-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
369-
/// use vortex_array::{IntoArray, ToCanonical};
370-
/// use vortex_array::validity::Validity;
371-
/// use vortex_buffer::buffer;
372-
/// use vortex_expr::{root, lit, lt_eq, Scope};
373-
///
364+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
365+
/// # use vortex_array::{IntoArray, ToCanonical};
366+
/// # use vortex_array::validity::Validity;
367+
/// # use vortex_buffer::buffer;
368+
/// # use vortex_expr::{root, lit, lt_eq, Scope};
374369
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
375370
/// let result = lt_eq(root(), lit(2)).evaluate(&Scope::new(xs.to_array())).unwrap();
376371
///
@@ -383,17 +378,16 @@ pub fn lt_eq(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
383378
BinaryExpr::new(lhs, Operator::Lte, rhs).into_expr()
384379
}
385380

386-
/// Create a new `BinaryExpr` using the `Lt` operator.
381+
/// Create a new [`BinaryExpr`] using the [`Lt`](crate::Operator::Lt) operator.
387382
///
388383
/// ## Example usage
389384
///
390385
/// ```
391-
/// use vortex_array::arrays::{BoolArray, PrimitiveArray };
392-
/// use vortex_array::{IntoArray, ToCanonical};
393-
/// use vortex_array::validity::Validity;
394-
/// use vortex_buffer::buffer;
395-
/// use vortex_expr::{root, lit, lt, Scope};
396-
///
386+
/// # use vortex_array::arrays::{BoolArray, PrimitiveArray };
387+
/// # use vortex_array::{IntoArray, ToCanonical};
388+
/// # use vortex_array::validity::Validity;
389+
/// # use vortex_buffer::buffer;
390+
/// # use vortex_expr::{root, lit, lt, Scope};
397391
/// let xs = PrimitiveArray::new(buffer![1i32, 2i32, 3i32], Validity::NonNullable);
398392
/// let result = lt(root(), lit(3)).evaluate(&Scope::new(xs.to_array())).unwrap();
399393
///
@@ -406,15 +400,14 @@ pub fn lt(lhs: ExprRef, rhs: ExprRef) -> ExprRef {
406400
BinaryExpr::new(lhs, Operator::Lt, rhs).into_expr()
407401
}
408402

409-
/// Create a new `BinaryExpr` using the `Or` operator.
403+
/// Create a new [`BinaryExpr`] using the [`Or`](crate::Operator::Or) operator.
410404
///
411405
/// ## Example usage
412406
///
413407
/// ```
414-
/// use vortex_array::arrays::BoolArray;
415-
/// use vortex_array::{IntoArray, ToCanonical};
416-
/// use vortex_expr::{root, lit, or, Scope};
417-
///
408+
/// # use vortex_array::arrays::BoolArray;
409+
/// # use vortex_array::{IntoArray, ToCanonical};
410+
/// # use vortex_expr::{root, lit, or, Scope};
418411
/// let xs = BoolArray::from_iter(vec![true, false, true]);
419412
/// let result = or(root(), lit(false)).evaluate(&Scope::new(xs.to_array())).unwrap();
420413
///
@@ -439,15 +432,14 @@ where
439432
Some(iter.rfold(first, |acc, elem| or(elem, acc)))
440433
}
441434

442-
/// Create a new `BinaryExpr` using the `And` operator.
435+
/// Create a new [`BinaryExpr`] using the [`And`](crate::Operator::And) operator.
443436
///
444437
/// ## Example usage
445438
///
446439
/// ```
447-
/// use vortex_array::arrays::BoolArray;
448-
/// use vortex_array::{IntoArray, ToCanonical};
449-
/// use vortex_expr::{and, root, lit, Scope};
450-
///
440+
/// # use vortex_array::arrays::BoolArray;
441+
/// # use vortex_array::{IntoArray, ToCanonical};
442+
/// # use vortex_expr::{and, root, lit, Scope};
451443
/// let xs = BoolArray::from_iter(vec![true, false, true]);
452444
/// let result = and(root(), lit(true)).evaluate(&Scope::new(xs.to_array())).unwrap();
453445
///
@@ -482,16 +474,15 @@ where
482474
iter.reduce(and)
483475
}
484476

485-
/// Create a new `BinaryExpr` using the `CheckedAdd` operator.
477+
/// Create a new [`BinaryExpr`] using the [`Add`](crate::Operator::Add) operator.
486478
///
487479
/// ## Example usage
488480
///
489481
/// ```
490-
/// use vortex_array::IntoArray;
491-
/// use vortex_array::arrow::IntoArrowArray as _;
492-
/// use vortex_buffer::buffer;
493-
/// use vortex_expr::{Scope, checked_add, lit, root};
494-
///
482+
/// # use vortex_array::IntoArray;
483+
/// # use vortex_array::arrow::IntoArrowArray as _;
484+
/// # use vortex_buffer::buffer;
485+
/// # use vortex_expr::{Scope, checked_add, lit, root};
495486
/// let xs = buffer![1, 2, 3].into_array();
496487
/// let result = checked_add(root(), lit(5))
497488
/// .evaluate(&Scope::new(xs.to_array()))

vortex-expr/src/exprs/cast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ impl Display for CastExpr {
108108

109109
impl AnalysisExpr for CastExpr {}
110110

111+
/// Creates an expression that casts values to a target data type.
112+
///
113+
/// Converts the input expression's values to the specified target type.
114+
///
115+
/// ```rust
116+
/// # use vortex_dtype::{DType, Nullability, PType};
117+
/// # use vortex_expr::{cast, root};
118+
/// let expr = cast(root(), DType::Primitive(PType::I64, Nullability::NonNullable));
119+
/// ```
111120
pub fn cast(child: ExprRef, target: DType) -> ExprRef {
112121
CastExpr::new(child, target).into_expr()
113122
}

vortex-expr/src/exprs/get_item.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,26 @@ impl GetItemExpr {
128128
}
129129
}
130130

131+
/// Creates an expression that accesses a field from the root array.
132+
///
133+
/// Equivalent to `get_item(field, root())` - extracts a named field from the input array.
134+
///
135+
/// ```rust
136+
/// # use vortex_expr::col;
137+
/// let expr = col("name");
138+
/// ```
131139
pub fn col(field: impl Into<FieldName>) -> ExprRef {
132140
GetItemExpr::new(field, root()).into_expr()
133141
}
134142

143+
/// Creates an expression that extracts a named field from a struct expression.
144+
///
145+
/// Accesses the specified field from the result of the child expression.
146+
///
147+
/// ```rust
148+
/// # use vortex_expr::{get_item, root};
149+
/// let expr = get_item("user_id", root());
150+
/// ```
135151
pub fn get_item(field: impl Into<FieldName>, child: ExprRef) -> ExprRef {
136152
GetItemExpr::new(field, child).into_expr()
137153
}

vortex-expr/src/exprs/is_null.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ impl Display for IsNullExpr {
9696

9797
impl AnalysisExpr for IsNullExpr {}
9898

99+
/// Creates an expression that checks for null values.
100+
///
101+
/// Returns a boolean array indicating which positions contain null values.
102+
///
103+
/// ```rust
104+
/// # use vortex_expr::{is_null, root};
105+
/// let expr = is_null(root());
106+
/// ```
99107
pub fn is_null(child: ExprRef) -> ExprRef {
100108
IsNullExpr::new(child).into_expr()
101109
}

vortex-expr/src/exprs/list_contains.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ impl ListContainsExpr {
105105
}
106106
}
107107

108+
/// Creates an expression that checks if a value is contained in a list.
109+
///
110+
/// Returns a boolean array indicating whether the value appears in each list.
111+
///
112+
/// ```rust
113+
/// # use vortex_expr::{list_contains, lit, root};
114+
/// let expr = list_contains(root(), lit(42));
115+
/// ```
108116
pub fn list_contains(list: ExprRef, value: ExprRef) -> ExprRef {
109117
ListContainsExpr::new(list, value).into_expr()
110118
}

vortex-expr/src/exprs/merge.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ impl MergeExpr {
171171
}
172172
}
173173

174+
/// Creates an expression that merges struct expressions into a single struct.
175+
///
176+
/// Combines fields from all input expressions. If field names are duplicated,
177+
/// later expressions win. Fields are not recursively merged.
178+
///
179+
/// ```rust
180+
/// # use vortex_dtype::Nullability;
181+
/// # use vortex_expr::{merge, get_item, root};
182+
/// let expr = merge([get_item("a", root()), get_item("b", root())], Nullability::NonNullable);
183+
/// ```
174184
pub fn merge(
175185
elements: impl IntoIterator<Item = impl Into<ExprRef>>,
176186
nullability: Nullability,

0 commit comments

Comments
 (0)