Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions vortex-array/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::scalar_fn::fns::binary::Binary;
use crate::scalar_fn::fns::cast::Cast;
use crate::scalar_fn::fns::fill_null::FillNull;
use crate::scalar_fn::fns::get_item::GetItem;
use crate::scalar_fn::fns::is_not_null::IsNotNull;
use crate::scalar_fn::fns::is_null::IsNull;
use crate::scalar_fn::fns::list_contains::ListContains;
use crate::scalar_fn::fns::mask::Mask;
Expand All @@ -49,6 +50,9 @@ pub trait ExprBuiltins: Sized {
/// Is null check.
fn is_null(&self) -> VortexResult<Expression>;

/// Is not null check.
fn is_not_null(&self) -> VortexResult<Expression>;

/// Mask the expression using the given boolean mask.
/// The resulting expression's validity is the intersection of the original expression's
/// validity.
Expand Down Expand Up @@ -84,6 +88,10 @@ impl ExprBuiltins for Expression {
IsNull.try_new_expr(EmptyOptions, [self.clone()])
}

fn is_not_null(&self) -> VortexResult<Expression> {
IsNotNull.try_new_expr(EmptyOptions, [self.clone()])
}

fn mask(&self, mask: Expression) -> VortexResult<Expression> {
Mask.try_new_expr(EmptyOptions, [self.clone(), mask])
}
Expand Down Expand Up @@ -118,6 +126,9 @@ pub trait ArrayBuiltins: Sized {
/// Is null check.
fn is_null(&self) -> VortexResult<ArrayRef>;

/// Is not null check.
fn is_not_null(&self) -> VortexResult<ArrayRef>;

/// Mask the array using the given boolean mask.
/// The resulting array's validity is the intersection of the original array's validity
/// and the mask's validity.
Expand Down Expand Up @@ -182,6 +193,12 @@ impl ArrayBuiltins for ArrayRef {
.optimize()
}

fn is_not_null(&self) -> VortexResult<ArrayRef> {
IsNotNull
.try_new_array(self.len(), EmptyOptions, [self.clone()])?
.optimize()
}

fn mask(self, mask: ArrayRef) -> VortexResult<ArrayRef> {
Mask.try_new_array(self.len(), EmptyOptions, [self, mask])?
.optimize()
Expand Down
15 changes: 15 additions & 0 deletions vortex-array/src/expr/exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::scalar_fn::fns::dynamic::DynamicComparisonExpr;
use crate::scalar_fn::fns::dynamic::Rhs;
use crate::scalar_fn::fns::fill_null::FillNull;
use crate::scalar_fn::fns::get_item::GetItem;
use crate::scalar_fn::fns::is_not_null::IsNotNull;
use crate::scalar_fn::fns::is_null::IsNull;
use crate::scalar_fn::fns::like::Like;
use crate::scalar_fn::fns::like::LikeOptions;
Expand Down Expand Up @@ -547,6 +548,20 @@ pub fn is_null(child: Expression) -> Expression {
IsNull.new_expr(EmptyOptions, vec![child])
}

// ---- IsNotNull ----

/// Creates an expression that checks for non-null values.
///
/// Returns a boolean array indicating which positions contain non-null values.
///
/// ```rust
/// # use vortex_array::expr::{is_not_null, root};
/// let expr = is_not_null(root());
/// ```
pub fn is_not_null(child: Expression) -> Expression {
IsNotNull.new_expr(EmptyOptions, vec![child])
}

// ---- Like ----

/// Creates a SQL LIKE expression.
Expand Down
9 changes: 2 additions & 7 deletions vortex-array/src/scalar_fn/erased.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ use crate::scalar_fn::ScalarFnId;
use crate::scalar_fn::ScalarFnVTable;
use crate::scalar_fn::ScalarFnVTableExt;
use crate::scalar_fn::SimplifyCtx;
use crate::scalar_fn::fns::is_null::IsNull;
use crate::scalar_fn::fns::not::Not;
use crate::scalar_fn::fns::is_not_null::IsNotNull;
use crate::scalar_fn::options::ScalarFnOptions;
use crate::scalar_fn::signature::ScalarFnSignature;
use crate::scalar_fn::typed::DynScalarFn;
Expand Down Expand Up @@ -135,11 +134,7 @@ impl ScalarFnRef {
pub fn validity(&self, expr: &Expression) -> VortexResult<Expression> {
Ok(self.0.validity(expr)?.unwrap_or_else(|| {
// TODO(ngates): make validity a mandatory method on VTable to avoid this fallback.
// TODO(ngates): add an IsNotNull expression.
Not.new_expr(
EmptyOptions,
[IsNull.new_expr(EmptyOptions, [expr.clone()])],
)
IsNotNull.new_expr(EmptyOptions, [expr.clone()])
}))
}

Expand Down
Loading
Loading