Skip to content

Commit 43f201a

Browse files
authored
chore: Add new_expr to all built-in expressions in the name of consistency (#3847)
Signed-off-by: Adam Gutglick <[email protected]>
1 parent 08ece05 commit 43f201a

File tree

11 files changed

+49
-17
lines changed

11 files changed

+49
-17
lines changed

vortex-dtype/src/field.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl FieldPath {
9393
}
9494

9595
/// Returns the sequence of field selectors that make up this path
96-
pub fn path(&self) -> &[Field] {
96+
pub fn parts(&self) -> &[Field] {
9797
&self.0
9898
}
9999

@@ -177,7 +177,7 @@ impl FieldPath {
177177
}
178178

179179
/// Does the field referenced by the field path exist in the given dtype?
180-
pub fn exists(&self, dtype: DType) -> bool {
180+
pub fn exists_in(&self, dtype: DType) -> bool {
181181
// Indexing a struct type always allocates anyway.
182182
self.resolve(dtype).is_some()
183183
}
@@ -244,7 +244,7 @@ mod tests {
244244
.into_iter()
245245
.map(Field::from)
246246
.collect_vec();
247-
assert_eq!(path.path(), &fields);
247+
assert_eq!(path.parts(), &fields);
248248

249249
let vec_path = FieldPath::from(fields);
250250
assert_eq!(vec_path.to_string(), "$A.$B.$C");
@@ -260,7 +260,7 @@ mod tests {
260260
);
261261
let path = FieldPath::from_name("a");
262262
assert_eq!(a_type, path.resolve(dtype.clone()).unwrap());
263-
assert!(path.exists(dtype));
263+
assert!(path.exists_in(dtype));
264264
}
265265

266266
#[test]
@@ -282,7 +282,7 @@ mod tests {
282282
let dtype = path.resolve(outer.clone()).unwrap();
283283

284284
assert_eq!(dtype, DType::Primitive(PType::U8, NonNullable));
285-
assert!(path.exists(outer));
285+
assert!(path.exists_in(outer));
286286
}
287287

288288
#[test]
@@ -314,40 +314,40 @@ mod tests {
314314
let dtype = path.resolve(level1.clone()).unwrap();
315315

316316
assert_eq!(dtype, DType::Primitive(PType::F64, Nullable));
317-
assert!(path.exists(level1.clone()));
317+
assert!(path.exists_in(level1.clone()));
318318

319319
let path = FieldPath::from_name("a")
320320
.push("b")
321321
.push("c")
322322
.push(Field::ElementType);
323323
assert!(path.resolve(level1.clone()).is_none());
324-
assert!(!path.exists(level1.clone()));
324+
assert!(!path.exists_in(level1.clone()));
325325

326326
let path = FieldPath::from_name("a")
327327
.push(Field::ElementType)
328328
.push("b")
329329
.push("c");
330330
assert!(path.resolve(level1.clone()).is_none());
331-
assert!(!path.exists(level1.clone()));
331+
assert!(!path.exists_in(level1.clone()));
332332

333333
let path = FieldPath::from_name(Field::ElementType)
334334
.push("a")
335335
.push("b")
336336
.push("c");
337337
assert!(path.resolve(level1.clone()).is_none());
338-
assert!(!path.exists(level1));
338+
assert!(!path.exists_in(level1));
339339
}
340340

341341
#[test]
342342
fn nested_field_not_found() {
343343
let dtype = DType::struct_([("a", DType::Bool(NonNullable))], NonNullable);
344344
let path = FieldPath::from_name("b");
345345
assert!(path.resolve(dtype.clone()).is_none());
346-
assert!(!path.exists(dtype.clone()));
346+
assert!(!path.exists_in(dtype.clone()));
347347

348348
let path = FieldPath::from(Field::ElementType);
349349
assert!(path.resolve(dtype.clone()).is_none());
350-
assert!(!path.exists(dtype));
350+
assert!(!path.exists_in(dtype));
351351
}
352352

353353
#[test]
@@ -358,10 +358,10 @@ mod tests {
358358
);
359359
let path = FieldPath::from_name("a").push("b");
360360
assert!(path.resolve(dtype.clone()).is_none());
361-
assert!(!path.exists(dtype.clone()));
361+
assert!(!path.exists_in(dtype.clone()));
362362

363363
let path = FieldPath::from_name("a").push(Field::ElementType);
364364
assert!(path.resolve(dtype.clone()).is_none());
365-
assert!(!path.exists(dtype));
365+
assert!(!path.exists_in(dtype));
366366
}
367367
}

vortex-dtype/src/field_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl FieldMask {
4949
match self {
5050
FieldMask::All => vortex_bail!("Cannot get starting field from All mask"),
5151
// We know that fp is non-empty
52-
FieldMask::Prefix(fp) | FieldMask::Exact(fp) => Ok(fp.path().first()),
52+
FieldMask::Prefix(fp) | FieldMask::Exact(fp) => Ok(fp.parts().first()),
5353
}
5454
}
5555

vortex-expr/src/exprs/cast.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ impl CastExpr {
9494
pub fn new(child: ExprRef, target: DType) -> Self {
9595
Self { target, child }
9696
}
97+
98+
pub fn new_expr(child: ExprRef, target: DType) -> ExprRef {
99+
Self::new(child, target).into_expr()
100+
}
97101
}
98102

99103
impl Display for CastExpr {

vortex-expr/src/exprs/get_item.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ impl GetItemExpr {
111111
}
112112
}
113113

114+
pub fn new_expr(field: impl Into<FieldName>, child: ExprRef) -> ExprRef {
115+
Self::new(field, child).into_expr()
116+
}
117+
114118
pub fn field(&self) -> &FieldName {
115119
&self.field
116120
}

vortex-expr/src/exprs/is_null.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ impl IsNullExpr {
8282
pub fn new(child: ExprRef) -> Self {
8383
Self { child }
8484
}
85+
86+
pub fn new_expr(child: ExprRef) -> ExprRef {
87+
Self::new(child).into_expr()
88+
}
8589
}
8690

8791
impl Display for IsNullExpr {

vortex-expr/src/exprs/list_contains.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ impl ListContainsExpr {
9696
Self { list, value }
9797
}
9898

99+
pub fn new_expr(list: ExprRef, value: ExprRef) -> ExprRef {
100+
Self::new(list, value).into_expr()
101+
}
102+
99103
pub fn value(&self) -> &ExprRef {
100104
&self.value
101105
}

vortex-expr/src/exprs/merge.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ impl MergeExpr {
162162
}
163163
}
164164

165+
pub fn new_expr(values: Vec<ExprRef>, nullability: Nullability) -> ExprRef {
166+
Self::new(values, nullability).into_expr()
167+
}
168+
165169
pub fn nullability(&self) -> Nullability {
166170
self.nullability
167171
}

vortex-expr/src/exprs/pack.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ impl PackExpr {
145145
})
146146
}
147147

148+
pub fn try_new_expr(
149+
names: FieldNames,
150+
values: Vec<ExprRef>,
151+
nullability: Nullability,
152+
) -> VortexResult<ExprRef> {
153+
Self::try_new(names, values, nullability).map(|v| v.into_expr())
154+
}
155+
148156
pub fn names(&self) -> &FieldNames {
149157
&self.names
150158
}

vortex-expr/src/exprs/select.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ impl SelectExpr {
122122
Self { fields, child }
123123
}
124124

125+
pub fn new_expr(fields: SelectField, child: ExprRef) -> ExprRef {
126+
Self::new(fields, child).into_expr()
127+
}
128+
125129
pub fn include_expr(columns: FieldNames, child: ExprRef) -> ExprRef {
126130
Self::new(SelectField::Include(columns), child).into_expr()
127131
}

vortex-expr/src/pruning/pruning_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl StatsCatalog for AnyStatsCatalog {
4949

5050
pub fn field_path_stat_field_name(field_path: &FieldPath, stat: Stat) -> FieldName {
5151
field_path
52-
.path()
52+
.parts()
5353
.iter()
5454
.map(|f| match f {
5555
Field::Name(n) => n.as_ref(),

0 commit comments

Comments
 (0)