Skip to content

Commit e6b27de

Browse files
committed
Expressions
Signed-off-by: Nicholas Gates <[email protected]>
1 parent 3daa075 commit e6b27de

File tree

1 file changed

+106
-64
lines changed

1 file changed

+106
-64
lines changed

vortex-array/src/expr/display.rs

Lines changed: 106 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -95,76 +95,111 @@ mod tests {
9595
}
9696

9797
#[test]
98-
fn test_display_tree() {
98+
fn test_display_tree_root() {
9999
use insta::assert_snapshot;
100-
101100
let root_expr = root();
102101
assert_snapshot!(root_expr.display_tree().to_string(), @"vortex.root()");
102+
}
103103

104+
#[test]
105+
fn test_display_tree_literal() {
106+
use insta::assert_snapshot;
104107
let lit_expr = lit(42);
105108
assert_snapshot!(lit_expr.display_tree().to_string(), @"vortex.literal(42i32)");
109+
}
106110

111+
#[test]
112+
fn test_display_tree_get_item() {
113+
use insta::assert_snapshot;
107114
let get_item_expr = get_item("my_field", root());
108-
assert_snapshot!(get_item_expr.display_tree().to_string(), @r#"
109-
vortex.get_item "my_field"
110-
└── input: vortex.root
111-
"#);
115+
assert_snapshot!(get_item_expr.display_tree().to_string(), @r"
116+
vortex.get_item(my_field)
117+
└── input: vortex.root()
118+
");
119+
}
112120

121+
#[test]
122+
fn test_display_tree_binary() {
123+
use insta::assert_snapshot;
113124
let binary_expr = gt(get_item("x", root()), lit(10));
114-
assert_snapshot!(binary_expr.display_tree().to_string(), @r#"
115-
vortex.binary >
116-
├── lhs: vortex.get_item "x"
117-
│ └── input: vortex.root
118-
└── rhs: vortex.literal 10i32
119-
"#);
125+
assert_snapshot!(binary_expr.display_tree().to_string(), @r"
126+
vortex.binary(>)
127+
├── lhs: vortex.get_item(x)
128+
│ └── input: vortex.root()
129+
└── rhs: vortex.literal(10i32)
130+
");
131+
}
120132

133+
#[test]
134+
fn test_display_tree_complex_binary() {
135+
use insta::assert_snapshot;
121136
let complex_binary = and(
122137
eq(get_item("name", root()), lit("alice")),
123138
gt(get_item("age", root()), lit(18)),
124139
);
125140
assert_snapshot!(complex_binary.display_tree().to_string(), @r#"
126-
vortex.binary and
127-
├── lhs: vortex.binary =
128-
│ ├── lhs: vortex.get_item "name"
129-
│ │ └── input: $
130-
│ └── rhs: vortex.literal "alice"
131-
└── rhs: vortex.binary >
132-
├── lhs: vortex.get_item "age"
133-
│ └── input: $
134-
└── rhs: vortex.literal 18i32
141+
vortex.binary(and)
142+
├── lhs: vortex.binary(=)
143+
│ ├── lhs: vortex.get_item(name)
144+
│ │ └── input: vortex.root()
145+
│ └── rhs: vortex.literal("alice")
146+
└── rhs: vortex.binary(>)
147+
├── lhs: vortex.get_item(age)
148+
│ └── input: vortex.root()
149+
└── rhs: vortex.literal(18i32)
135150
"#);
151+
}
136152

153+
#[test]
154+
fn test_display_tree_select() {
155+
use insta::assert_snapshot;
137156
let select_expr = select(["name", "age"], root());
138157
assert_snapshot!(select_expr.display_tree().to_string(), @r"
139-
vortex.select include={name, age}
140-
└── child: $
158+
vortex.select({name, age})
159+
└── child: vortex.root()
141160
");
161+
}
142162

163+
#[test]
164+
fn test_display_tree_select_exclude() {
165+
use insta::assert_snapshot;
143166
let select_exclude_expr = select_exclude(["internal_id", "metadata"], root());
144167
assert_snapshot!(select_exclude_expr.display_tree().to_string(), @r"
145-
vortex.select exclude={internal_id, metadata}
146-
└── child: $
168+
vortex.select(~{internal_id, metadata})
169+
└── child: vortex.root()
147170
");
171+
}
148172

173+
#[test]
174+
fn test_display_tree_cast() {
175+
use insta::assert_snapshot;
149176
let cast_expr = cast(
150177
get_item("value", root()),
151178
DType::Primitive(PType::I64, Nullability::NonNullable),
152179
);
153-
assert_snapshot!(cast_expr.display_tree().to_string(), @r#"
154-
vortex.cast i64
155-
└── input: vortex.get_item "value"
156-
└── input: $
157-
"#);
180+
assert_snapshot!(cast_expr.display_tree().to_string(), @r"
181+
vortex.cast(i64)
182+
└── input: vortex.get_item(value)
183+
└── input: vortex.root()
184+
");
185+
}
158186

187+
#[test]
188+
fn test_display_tree_not() {
189+
use insta::assert_snapshot;
159190
let not_expr = not(eq(get_item("active", root()), lit(true)));
160-
assert_snapshot!(not_expr.display_tree().to_string(), @r#"
161-
vortex.not
162-
└── input: vortex.binary =
163-
├── lhs: vortex.get_item "active"
164-
│ └── input: vortex.root
165-
└── rhs: vortex.literal true
166-
"#);
191+
assert_snapshot!(not_expr.display_tree().to_string(), @r"
192+
vortex.not()
193+
└── input: vortex.binary(=)
194+
├── lhs: vortex.get_item(active)
195+
│ └── input: vortex.root()
196+
└── rhs: vortex.literal(true)
197+
");
198+
}
167199

200+
#[test]
201+
fn test_display_tree_between() {
202+
use insta::assert_snapshot;
168203
let between_expr = between(
169204
get_item("score", root()),
170205
lit(0),
@@ -174,15 +209,18 @@ mod tests {
174209
upper_strict: StrictComparison::NonStrict,
175210
},
176211
);
177-
assert_snapshot!(between_expr.display_tree().to_string(), @r#"
178-
vortex.between BetweenOptions { lower_strict: NonStrict, upper_strict: NonStrict }
179-
├── array: vortex.get_item "score"
180-
│ └── input: vortex.root
181-
├── lower: vortex.literal 0i32
182-
└── upper: vortex.literal 100i32
183-
"#);
212+
assert_snapshot!(between_expr.display_tree().to_string(), @r"
213+
vortex.between(lower_strict: <=, upper_strict: <=)
214+
├── array: vortex.get_item(score)
215+
│ └── input: vortex.root()
216+
├── lower: vortex.literal(0i32)
217+
└── upper: vortex.literal(100i32)
218+
");
219+
}
184220

185-
// Test nested expression
221+
#[test]
222+
fn test_display_tree_nested() {
223+
use insta::assert_snapshot;
186224
let nested_expr = select(
187225
["result"],
188226
cast(
@@ -198,16 +236,20 @@ mod tests {
198236
DType::Bool(Nullability::NonNullable),
199237
),
200238
);
201-
assert_snapshot!(nested_expr.display_tree().to_string(), @r#"
202-
vortex.select include={result}
203-
└── child: vortex.cast bool
204-
└── input: vortex.between BetweenOptions { lower_strict: Strict, upper_strict: NonStrict }
205-
├── array: vortex.get_item "score"
206-
│ └── input: vortex.root
207-
├── lower: vortex.literal 50i32
208-
└── upper: vortex.literal 100i32
209-
"#);
239+
assert_snapshot!(nested_expr.display_tree().to_string(), @r"
240+
vortex.select({result})
241+
└── child: vortex.cast(bool)
242+
└── input: vortex.between(lower_strict: <, upper_strict: <=)
243+
├── array: vortex.get_item(score)
244+
│ └── input: vortex.root()
245+
├── lower: vortex.literal(50i32)
246+
└── upper: vortex.literal(100i32)
247+
");
248+
}
210249

250+
#[test]
251+
fn test_display_tree_pack() {
252+
use insta::assert_snapshot;
211253
let select_from_pack_expr = select(
212254
["fizz", "buzz"],
213255
pack(
@@ -219,15 +261,15 @@ mod tests {
219261
Nullability::Nullable,
220262
),
221263
);
222-
assert_snapshot!(select_from_pack_expr.display_tree().to_string(), @r#"
223-
vortex.select include={fizz, buzz}
224-
└── child: vortex.pack PackOptions { names: FieldNames([FieldName("fizz"), FieldName("bar"), FieldName("buzz")]), nullability: Nullable }
225-
├── fizz: vortex.root
226-
├── bar: vortex.literal 5i32
227-
└── buzz: vortex.binary =
228-
├── lhs: vortex.literal 42i32
229-
└── rhs: vortex.get_item "answer"
230-
└── input: vortex.root
231-
"#);
264+
assert_snapshot!(select_from_pack_expr.display_tree().to_string(), @r"
265+
vortex.select({fizz, buzz})
266+
└── child: vortex.pack(names: [fizz, bar, buzz], nullability: ?)
267+
├── fizz: vortex.root()
268+
├── bar: vortex.literal(5i32)
269+
└── buzz: vortex.binary(=)
270+
├── lhs: vortex.literal(42i32)
271+
└── rhs: vortex.get_item(answer)
272+
└── input: vortex.root()
273+
");
232274
}
233275
}

0 commit comments

Comments
 (0)