Skip to content

Commit b34df60

Browse files
committed
Fix events ordering
1 parent 8f0fd12 commit b34df60

File tree

9 files changed

+72
-9
lines changed

9 files changed

+72
-9
lines changed

vortex-expr/src/exprs/between.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use prost::Message;
45
use std::fmt::Formatter;
56
use vortex_array::compute::{between as between_compute, BetweenOptions};
67
use vortex_array::ArrayRef;
78
use vortex_dtype::DType;
89
use vortex_dtype::DType::Bool;
910
use vortex_error::{vortex_bail, VortexExpect, VortexResult};
11+
use vortex_proto::expr as pb;
1012

1113
use crate::exprs::binary::Binary;
1214
use crate::exprs::operators::Operator;
@@ -33,6 +35,32 @@ impl VTable for Between {
3335
ExprId::from("vortex.between")
3436
}
3537

38+
fn serialize(&self, instance: &Self::Instance) -> VortexResult<Option<Vec<u8>>> {
39+
Ok(Some(
40+
pb::BetweenOpts {
41+
lower_strict: instance.lower_strict.is_strict(),
42+
upper_strict: instance.upper_strict.is_strict(),
43+
}
44+
.encode_to_vec(),
45+
))
46+
}
47+
48+
fn deserialize(&self, metadata: &[u8]) -> VortexResult<Option<Self::Instance>> {
49+
let opts = pb::BetweenOpts::decode(metadata)?;
50+
Ok(Some(BetweenOptions {
51+
lower_strict: if opts.lower_strict {
52+
vortex_array::compute::StrictComparison::Strict
53+
} else {
54+
vortex_array::compute::StrictComparison::NonStrict
55+
},
56+
upper_strict: if opts.upper_strict {
57+
vortex_array::compute::StrictComparison::Strict
58+
} else {
59+
vortex_array::compute::StrictComparison::NonStrict
60+
},
61+
}))
62+
}
63+
3664
fn validate(&self, expr: &ExprInstance<Self>) -> VortexResult<()> {
3765
if expr.children().len() != 3 {
3866
vortex_bail!(

vortex-expr/src/exprs/binary.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl VTable for Binary {
5252

5353
fn fmt_sql(&self, expr: &ExprInstance<Self>, f: &mut Formatter<'_>) -> std::fmt::Result {
5454
write!(f, "(")?;
55-
expr.lhs().fmt(f)?;
55+
expr.lhs().fmt_sql(f)?;
5656
write!(f, " {} ", expr.operator())?;
57-
expr.rhs().fmt(f)?;
57+
expr.rhs().fmt_sql(f)?;
5858
write!(f, ")")
5959
}
6060

vortex-expr/src/exprs/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod tests {
172172
get_item("value", root()),
173173
DType::Primitive(PType::I64, Nullability::NonNullable),
174174
);
175-
assert_eq!(expr.to_string(), "cast($.value, i64)");
175+
assert_eq!(expr.to_string(), "cast($.value as i64)");
176176

177177
let expr2 = cast(root(), DType::Bool(Nullability::Nullable));
178178
assert_eq!(expr2.to_string(), "cast($, bool?)");

vortex-expr/src/exprs/get_item.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ impl VTable for GetItem {
5858
write!(f, ".{}", expr.data())
5959
}
6060

61+
fn fmt_data(&self, instance: &Self::Instance, f: &mut Formatter<'_>) -> std::fmt::Result {
62+
// We use debug format to include the quotes around the field name.
63+
write!(f, "{:?}", instance.inner().as_ref())
64+
}
65+
6166
fn return_dtype(&self, expr: &ExprInstance<Self>, scope: &DType) -> VortexResult<DType> {
6267
let input = expr.children()[0].return_dtype(scope)?;
6368
input

vortex-expr/src/exprs/list_contains.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ impl VTable for ListContains {
2121
ExprId::from("vortex.list.contains")
2222
}
2323

24+
fn serialize(&self, _instance: &Self::Instance) -> VortexResult<Option<Vec<u8>>> {
25+
Ok(Some(vec![]))
26+
}
27+
28+
fn deserialize(&self, _metadata: &[u8]) -> VortexResult<Option<Self::Instance>> {
29+
Ok(Some(()))
30+
}
31+
2432
fn validate(&self, expr: &ExprInstance<Self>) -> VortexResult<()> {
2533
if expr.children().len() != 2 {
2634
vortex_bail!(

vortex-expr/src/exprs/merge.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ impl VTable for Merge {
2929
ExprId::new_ref("vortex.merge")
3030
}
3131

32+
fn serialize(&self, instance: &Self::Instance) -> VortexResult<Option<Vec<u8>>> {
33+
Ok(Some(match instance {
34+
DuplicateHandling::RightMost => vec![0x00],
35+
DuplicateHandling::Error => vec![0x01],
36+
}))
37+
}
38+
39+
fn deserialize(&self, metadata: &[u8]) -> VortexResult<Option<Self::Instance>> {
40+
let instance = match metadata {
41+
[0x00] => DuplicateHandling::RightMost,
42+
[0x01] => DuplicateHandling::Error,
43+
_ => {
44+
vortex_bail!("invalid metadata for Merge expression");
45+
}
46+
};
47+
Ok(Some(instance))
48+
}
49+
3250
fn validate(&self, _expr: &ExprInstance<Self>) -> VortexResult<()> {
3351
Ok(())
3452
}
@@ -428,9 +446,9 @@ mod tests {
428446
#[test]
429447
pub fn test_display() {
430448
let expr = merge([get_item("struct1", root()), get_item("struct2", root())]);
431-
assert_eq!(expr.to_string(), "merge[error]($.struct1, $.struct2)");
449+
assert_eq!(expr.to_string(), "merge($.struct1, $.struct2)");
432450

433451
let expr2 = merge(vec![get_item("a", root())]);
434-
assert_eq!(expr2.to_string(), "merge[error]($.a)");
452+
assert_eq!(expr2.to_string(), "merge($.a)");
435453
}
436454
}

vortex-expr/src/exprs/not.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl VTable for Not {
4747
}
4848

4949
fn fmt_sql(&self, expr: &ExprInstance<Self>, f: &mut Formatter<'_>) -> std::fmt::Result {
50-
write!(f, "~(")?;
50+
write!(f, "not(")?;
5151
expr.child(0).fmt_sql(f)?;
5252
write!(f, ")")
5353
}
@@ -113,8 +113,8 @@ mod tests {
113113
let a = not(get_item("a", root()));
114114
let b = get_item("a", not(root()));
115115
assert_ne!(a.to_string(), b.to_string());
116-
assert_eq!(a.to_string(), "(!$.a)");
117-
assert_eq!(b.to_string(), "(!$).a");
116+
assert_eq!(a.to_string(), "not($.a)");
117+
assert_eq!(b.to_string(), "not($).a");
118118
}
119119

120120
#[test]

vortex-expr/src/exprs/root.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ impl VTable for Root {
5050
write!(f, "$")
5151
}
5252

53+
fn fmt_data(&self, _instance: &Self::Instance, _f: &mut Formatter<'_>) -> std::fmt::Result {
54+
Ok(()) // No data
55+
}
56+
5357
fn return_dtype(&self, _expr: &ExprInstance<Self>, scope: &DType) -> VortexResult<DType> {
5458
Ok(scope.clone())
5559
}

vortex-expr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ mod tests {
197197
"(($.col1 < $.col2) or ($.col1 != $.col2))"
198198
);
199199

200-
assert_eq!(not(col1.clone()).to_string(), "(!$.col1)");
200+
assert_eq!(not(col1.clone()).to_string(), "not($.col1)");
201201

202202
assert_eq!(
203203
select(vec![FieldName::from("col1")], root()).to_string(),

0 commit comments

Comments
 (0)