Skip to content

Commit a63d0ab

Browse files
feat[vortex-expr]: is_fallible expression analysis (#5531)
For now we put this on the VTable, but I think we should figure out a way to make this analysis extensible --------- Signed-off-by: Joe Isaacs <[email protected]>
1 parent e1581f8 commit a63d0ab

File tree

12 files changed

+96
-12
lines changed

12 files changed

+96
-12
lines changed

vortex-array/src/expr/analysis/labeling.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ where
6262
{
6363
type NodeTy = Expression;
6464

65+
fn visit_down(&mut self, _node: &'a Self::NodeTy) -> VortexResult<TraversalOrder> {
66+
Ok(TraversalOrder::Continue)
67+
}
68+
6569
fn visit_up(&mut self, node: &'a Expression) -> VortexResult<TraversalOrder> {
6670
let self_label = (self.self_label)(node);
6771

vortex-array/src/expr/expression.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ impl Expression {
238238
self.vtable.as_dyn().is_null_sensitive(self.data.as_ref())
239239
}
240240

241+
/// Returns whether this expression itself is fallible.
242+
/// See [`VTable::is_fallible`].
243+
pub fn is_fallible(&self) -> bool {
244+
self.vtable.as_dyn().is_fallible(self.data.as_ref())
245+
}
246+
241247
/// Format the expression as a compact string.
242248
///
243249
/// Since this is a recursive formatter, it is exposed on the public Expression type.

vortex-array/src/expr/exprs/get_item/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ impl VTable for GetItem {
155155
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
156156
true
157157
}
158+
159+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
160+
// If this type-checks its infallible.
161+
false
162+
}
158163
}
159164

160165
/// Creates an expression that accesses a field from the root array.

vortex-array/src/expr/exprs/is_null.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ impl VTable for IsNull {
106106
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
107107
true
108108
}
109+
110+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
111+
false
112+
}
109113
}
110114

111115
/// Creates an expression that checks for null values.

vortex-array/src/expr/exprs/literal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ impl VTable for Literal {
130130
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
131131
false
132132
}
133+
134+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
135+
false
136+
}
133137
}
134138

135139
/// Create a new `Literal` expression from a type that coerces to `Scalar`.

vortex-array/src/expr/exprs/merge/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,14 @@ impl VTable for Merge {
166166
.into_array(),
167167
)
168168
}
169+
170+
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
171+
true
172+
}
173+
174+
fn is_fallible(&self, instance: &Self::Instance) -> bool {
175+
matches!(instance, DuplicateHandling::Error)
176+
}
169177
}
170178

171179
/// What to do when merged structs share a field name.

vortex-array/src/expr/exprs/not.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl VTable for Not {
8585
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
8686
false
8787
}
88+
89+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
90+
false
91+
}
8892
}
8993

9094
/// Creates an expression that logically inverts boolean values.

vortex-array/src/expr/exprs/pack.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ impl VTable for Pack {
145145
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
146146
true
147147
}
148+
149+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
150+
false
151+
}
148152
}
149153

150154
impl ExpressionView<'_, Pack> {

vortex-array/src/expr/exprs/root.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ impl VTable for Root {
8585
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
8686
false
8787
}
88+
89+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
90+
false
91+
}
8892
}
8993

9094
/// Creates an expression that references the root scope.

vortex-array/src/expr/exprs/select/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ impl VTable for Select {
201201
.collect();
202202
Ok(unsafe { StructVector::new_unchecked(Arc::new(new_fields), mask) }.into())
203203
}
204+
205+
fn is_null_sensitive(&self, _instance: &Self::Instance) -> bool {
206+
true
207+
}
208+
209+
fn is_fallible(&self, _instance: &Self::Instance) -> bool {
210+
// If this type-checks its infallible.
211+
false
212+
}
204213
}
205214

206215
/// Creates an expression that selects (includes) specific fields from an array.

0 commit comments

Comments
 (0)