Skip to content

Commit 9718c47

Browse files
committed
Add Case-When Expression and tests (#12)
* fix: Ensure CastExpr/CastColumnExpr/ScalarFunctionExpr check children in can_be_pushed_down The can_be_pushed_down function was returning true for CastExpr and CastColumnExpr without checking if their child expressions are convertible. This caused runtime errors when the child contained expressions like CaseExpr that convert() cannot handle. Also fixed ScalarFunctionExpr to recursively check its arguments. Fixes spiceai/spiceai#9037 * Add Case-When Expression and tests * Implement execute() * Add additional tests and fix type issue * Fix toml lint * feat(case_when): implement lazy evaluation to avoid side effects in unevaluated branches This implements proper lazy evaluation in CaseWhen expression to ensure that THEN/ELSE branches are only evaluated for rows where they apply. This is critical for correctness when expressions have side effects like divide-by-zero panics. The implementation: 1. Evaluates conditions in order, tracking which rows have been matched 2. For each condition, computes an effective mask (condition AND NOT matched) 3. Uses filter() to create a scoped array with only matching rows 4. Evaluates THEN expression only on the filtered scope 5. Uses scatter_with_mask() to expand results back to original positions 6. Short-circuits when all rows are matched or all conditions fail This fixes TPC-DS Q73 which has a pattern like: CASE WHEN hd_vehicle_count > 0 THEN hd_dep_count/hd_vehicle_count ELSE NULL END Previously, the division would be evaluated for all rows including those where hd_vehicle_count=0, causing a divide-by-zero panic. Now the division is only evaluated for rows where the condition is true. Added test: test_evaluate_divide_by_zero_protected_by_case_when * Formatting
1 parent 4f0b50d commit 9718c47

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

vortex-io/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ parking_lot = { workspace = true }
3232
pin-project-lite = { workspace = true }
3333
# this is the maximum subset of fetaures that is safe for wasm32 targets
3434
handle = "1.0.2"
35+
log = { workspace = true }
3536
tokio = { workspace = true, features = ["io-util", "rt", "sync"] }
3637
tracing = { workspace = true }
3738
vortex-array = { workspace = true }
3839
vortex-buffer = { workspace = true }
39-
log = { workspace = true }
4040
vortex-error = { workspace = true }
4141
vortex-metrics = { workspace = true }
4242
vortex-session = { workspace = true }

vortex-session/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33

44
pub mod registry;
55

6-
use std::any::{Any, TypeId, type_name};
6+
use std::any::Any;
7+
use std::any::TypeId;
8+
use std::any::type_name;
79
use std::fmt::Debug;
8-
use std::hash::{BuildHasherDefault, Hasher};
9-
use std::ops::{Deref, DerefMut};
10+
use std::hash::BuildHasherDefault;
11+
use std::hash::Hasher;
12+
use std::ops::Deref;
13+
use std::ops::DerefMut;
1014
use std::sync::Arc;
1115

12-
use dashmap::{DashMap, Entry};
13-
use vortex_error::{VortexExpect, vortex_panic};
16+
use dashmap::DashMap;
17+
use dashmap::Entry;
18+
use vortex_error::VortexExpect;
19+
use vortex_error::vortex_panic;
1420

1521
/// A Vortex session encapsulates the set of extensible arrays, layouts, compute functions, dtypes,
1622
/// etc. that are available for use in a given context.

0 commit comments

Comments
 (0)