Skip to content

Commit 9876921

Browse files
connortsui20claude
andauthored
Replace ScalarFnVTable::is_fallible with is_infallible (#9511)
## Rationale for this change Flips the polarity of the fallibility hook so the conservative answer is the default. A scalar function now opts in to being infallible by overriding `is_infallible` to return `true`, instead of opting out of the fallible default. ## What changes are included in this PR? Renames `ScalarFnVTable::is_fallible` to `is_infallible` along with the `DynScalarFn` and `ScalarFnSignature` mirrors, and inverts every implementation and call site (dictionary push-down, the dict layout pushdown split, and `ExpressionTakeRule`). Also renames the `label_is_fallible` expression analysis to `label_infallible` so it matches `label_strict`, and inverts its tests in place. ## What APIs are changed? Are there any user-facing changes? `ScalarFnSignature::is_fallible` becomes `is_infallible` and `label_is_fallible` becomes `label_infallible`, both with flipped return values. Out-of-tree `ScalarFnVTable` implementations must rename their `is_fallible` override and invert the result, and an override that returned `true` can now rely on the default. --- _Generated by [Claude Code](https://claude.ai/code/session_011DaVCc8ZmJ13JtPGQYMM3o)_ --------- Signed-off-by: Claude <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 80cb044 commit 9876921

44 files changed

Lines changed: 130 additions & 128 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎vortex-array/src/arrays/dict/compute/rules.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl ArrayParentReduceRule<Dict> for DictionaryScalarFnValuesPushDownRule {
130130

131131
// If the scalar function is fallible, we cannot push it down since it may fail over a
132132
// value that isn't referenced by any code.
133-
if !array.all_values_referenced && sig.is_fallible() {
133+
if !array.all_values_referenced && !sig.is_infallible() {
134134
tracing::trace!(
135135
"Not pushing down fallible scalar function {} over dictionary with sparse codes {}",
136136
parent.scalar_fn(),

vortex-array/src/expr/analysis/fallible.rs renamed to vortex-array/src/expr/analysis/infallible.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@ use crate::expr::Expression;
55
use crate::expr::analysis::BooleanLabels;
66
use crate::expr::label_tree;
77

8-
pub fn label_is_fallible(expr: &Expression) -> BooleanLabels<'_> {
8+
/// Label each expression with whether its entire subtree is infallible.
9+
///
10+
/// A subtree is infallible only when the node's scalar function and every child subtree are
11+
/// infallible. See [`crate::scalar_fn::ScalarFnVTable::is_infallible`] for the scalar-function
12+
/// contract.
13+
pub fn label_infallible(expr: &Expression) -> BooleanLabels<'_> {
914
label_tree(
1015
expr,
1116
|expr| match expr {
12-
Expression::Scalar { scalar_fn, .. } => scalar_fn.signature().is_fallible(),
17+
Expression::Scalar { scalar_fn, .. } => scalar_fn.signature().is_infallible(),
1318
// The scope itself cannot fail.
14-
Expression::Root => false,
19+
Expression::Root => true,
1520
},
16-
|acc, &child| acc | child,
21+
|acc, &child| acc & child,
1722
)
1823
}
1924

@@ -30,55 +35,55 @@ mod tests {
3035
use crate::scalar_fn::fns::merge::DuplicateHandling;
3136

3237
#[test]
33-
fn not_is_not_fallible() {
38+
fn not_is_infallible() {
3439
let expr = not(col("x"));
35-
let labels = label_is_fallible(&expr);
36-
assert_eq!(labels.get(&expr), Some(&false));
40+
let labels = label_infallible(&expr);
41+
assert_eq!(labels.get(&expr), Some(&true));
3742
}
3843

3944
#[test]
4045
fn checked_add_defaults_to_fallible() {
4146
let expr = checked_add(col("a"), col("b"));
42-
let labels = label_is_fallible(&expr);
43-
assert_eq!(labels.get(&expr), Some(&true));
47+
let labels = label_infallible(&expr);
48+
assert_eq!(labels.get(&expr), Some(&false));
4449
}
4550

4651
#[test]
47-
fn eq_not_fallible() {
52+
fn eq_is_infallible() {
4853
let expr = eq(col("a"), lit(5));
49-
let labels = label_is_fallible(&expr);
50-
assert_eq!(labels.get(&expr), Some(&false));
54+
let labels = label_infallible(&expr);
55+
assert_eq!(labels.get(&expr), Some(&true));
5156
}
5257

5358
#[test]
5459
fn merge_with_error_handling_is_fallible() {
5560
let expr = merge_opts([col("a"), col("b")], DuplicateHandling::Error);
56-
let labels = label_is_fallible(&expr);
57-
assert_eq!(labels.get(&expr), Some(&true));
61+
let labels = label_infallible(&expr);
62+
assert_eq!(labels.get(&expr), Some(&false));
5863
}
5964

6065
#[test]
61-
fn merge_with_rightmost_handling_is_not_fallible() {
66+
fn merge_with_rightmost_handling_is_infallible() {
6267
let expr = merge_opts([col("a"), col("b")], DuplicateHandling::RightMost);
63-
let labels = label_is_fallible(&expr);
64-
assert_eq!(labels.get(&expr), Some(&false));
68+
let labels = label_infallible(&expr);
69+
assert_eq!(labels.get(&expr), Some(&true));
6570
}
6671

6772
#[test]
6873
fn nested_with_fallible_child() {
6974
let child = checked_add(col("a"), col("b"));
7075
let expr = not(child.clone());
71-
let labels = label_is_fallible(&expr);
72-
assert_eq!(labels.get(&child), Some(&true));
73-
assert_eq!(labels.get(&expr), Some(&true));
76+
let labels = label_infallible(&expr);
77+
assert_eq!(labels.get(&child), Some(&false));
78+
assert_eq!(labels.get(&expr), Some(&false));
7479
}
7580

7681
#[test]
7782
fn nested_without_fallible_child() {
7883
let child = is_null(col("x"));
7984
let expr = not(child.clone());
80-
let labels = label_is_fallible(&expr);
81-
assert_eq!(labels.get(&child), Some(&false));
82-
assert_eq!(labels.get(&expr), Some(&false));
85+
let labels = label_infallible(&expr);
86+
assert_eq!(labels.get(&child), Some(&true));
87+
assert_eq!(labels.get(&expr), Some(&true));
8388
}
8489
}

‎vortex-array/src/expr/analysis/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
pub mod annotation;
5-
mod fallible;
65
pub mod immediate_access;
6+
mod infallible;
77
mod labeling;
88
mod referenced_field_paths;
99
mod strict;
1010

1111
pub use annotation::*;
12-
pub use fallible::label_is_fallible;
1312
pub use immediate_access::*;
13+
pub use infallible::label_infallible;
1414
pub use labeling::*;
1515
pub use referenced_field_paths::referenced_field_paths;
1616
pub use strict::label_strict;

‎vortex-array/src/scalar_fn/fns/between/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ impl ScalarFnVTable for Between {
344344
false
345345
}
346346

347-
fn is_fallible(&self, _options: &Self::Options) -> bool {
348-
false
347+
fn is_infallible(&self, _options: &Self::Options) -> bool {
348+
true
349349
}
350350
}
351351

‎vortex-array/src/scalar_fn/fns/binary/mod.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,9 @@ impl ScalarFnVTable for Binary {
274274
!matches!(operator, Operator::And | Operator::Or)
275275
}
276276

277-
fn is_fallible(&self, operator: &Operator) -> bool {
278-
// Opt-in not out for fallibility.
277+
fn is_infallible(&self, operator: &Operator) -> bool {
279278
// Arithmetic operations could be better modelled here.
280-
let infallible = matches!(
279+
matches!(
281280
operator,
282281
Operator::Eq
283282
| Operator::NotEq
@@ -287,9 +286,7 @@ impl ScalarFnVTable for Binary {
287286
| Operator::Lte
288287
| Operator::And
289288
| Operator::Or
290-
);
291-
292-
!infallible
289+
)
293290
}
294291
}
295292

‎vortex-array/src/scalar_fn/fns/byte_length.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ impl ScalarFnVTable for ByteLength {
135135
true
136136
}
137137

138-
fn is_fallible(&self, _options: &Self::Options) -> bool {
139-
false
138+
fn is_infallible(&self, _options: &Self::Options) -> bool {
139+
true
140140
}
141141
}
142142

‎vortex-array/src/scalar_fn/fns/case_when.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ impl ScalarFnVTable for CaseWhen {
306306
false
307307
}
308308

309-
fn is_fallible(&self, _options: &Self::Options) -> bool {
310-
false
309+
fn is_infallible(&self, _options: &Self::Options) -> bool {
310+
true
311311
}
312312
}
313313

‎vortex-array/src/scalar_fn/fns/ext_storage.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ impl ScalarFnVTable for ExtStorage {
9797
true
9898
}
9999

100-
fn is_fallible(&self, _options: &Self::Options) -> bool {
101-
false
100+
fn is_infallible(&self, _options: &Self::Options) -> bool {
101+
true
102102
}
103103
}
104104

‎vortex-array/src/scalar_fn/fns/fill_null/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ impl ScalarFnVTable for FillNull {
150150
false
151151
}
152152

153-
fn is_fallible(&self, _options: &Self::Options) -> bool {
154-
false
153+
fn is_infallible(&self, _options: &Self::Options) -> bool {
154+
true
155155
}
156156
}
157157

‎vortex-array/src/scalar_fn/fns/get_item.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl ScalarFnVTable for GetItem {
199199
true
200200
}
201201

202-
fn is_fallible(&self, _field_name: &FieldName) -> bool {
203-
// If this type-checks its infallible.
204-
false
202+
fn is_infallible(&self, _field_name: &FieldName) -> bool {
203+
// If this type-checks, it is infallible.
204+
true
205205
}
206206
}
207207

0 commit comments

Comments
 (0)