From 329bb74040e9639e74e1be5a555725dc7429009d Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 2 Sep 2024 11:03:26 +0100 Subject: [PATCH] Fix `NONE` and `NULL` less than or greater than bugs (#4658) --- core/src/doc/table.rs | 28 ++++++++++++++++++++++------ core/src/fnc/operate.rs | 8 ++++---- sdk/tests/table.rs | 10 +++++++++- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/core/src/doc/table.rs b/core/src/doc/table.rs index 5d304a91..5544d96c 100644 --- a/core/src/doc/table.rs +++ b/core/src/doc/table.rs @@ -458,9 +458,17 @@ impl Document { Value::Subquery(Box::new(Subquery::Ifelse(IfelseStatement { exprs: vec![( Value::Expression(Box::new(Expression::Binary { - l: Value::Idiom(key.clone()), - o: Operator::MoreThan, - r: val.clone(), + l: Value::Expression(Box::new(Expression::Binary { + l: Value::Idiom(key.clone()), + o: Operator::Exact, + r: Value::None, + })), + o: Operator::Or, + r: Value::Expression(Box::new(Expression::Binary { + l: Value::Idiom(key.clone()), + o: Operator::MoreThan, + r: val.clone(), + })), })), val, )], @@ -505,9 +513,17 @@ impl Document { Value::Subquery(Box::new(Subquery::Ifelse(IfelseStatement { exprs: vec![( Value::Expression(Box::new(Expression::Binary { - l: Value::Idiom(key.clone()), - o: Operator::LessThan, - r: val.clone(), + l: Value::Expression(Box::new(Expression::Binary { + l: Value::Idiom(key.clone()), + o: Operator::Exact, + r: Value::None, + })), + o: Operator::Or, + r: Value::Expression(Box::new(Expression::Binary { + l: Value::Idiom(key.clone()), + o: Operator::LessThan, + r: val.clone(), + })), })), val, )], diff --git a/core/src/fnc/operate.rs b/core/src/fnc/operate.rs index 9cf7b898..e8b7aff1 100644 --- a/core/src/fnc/operate.rs +++ b/core/src/fnc/operate.rs @@ -105,19 +105,19 @@ pub fn any_like(a: &Value, b: &Value) -> Result { } pub fn less_than(a: &Value, b: &Value) -> Result { - Ok((a.is_none_or_null() || b.is_none_or_null() || a.lt(b)).into()) + Ok(a.lt(b).into()) } pub fn less_than_or_equal(a: &Value, b: &Value) -> Result { - Ok((a.is_none_or_null() || b.is_none_or_null() || a.le(b)).into()) + Ok(a.le(b).into()) } pub fn more_than(a: &Value, b: &Value) -> Result { - Ok((a.is_none_or_null() || b.is_none_or_null() || a.gt(b)).into()) + Ok(a.gt(b).into()) } pub fn more_than_or_equal(a: &Value, b: &Value) -> Result { - Ok((a.is_none_or_null() || b.is_none_or_null() || a.ge(b)).into()) + Ok(a.ge(b).into()) } pub fn contain(a: &Value, b: &Value) -> Result { diff --git a/sdk/tests/table.rs b/sdk/tests/table.rs index b400be31..5c473ddc 100644 --- a/sdk/tests/table.rs +++ b/sdk/tests/table.rs @@ -54,7 +54,15 @@ async fn define_foreign_table() -> Result<(), Error> { assert_eq!(tmp, val); // let tmp = res.remove(0).result?; - let val = Value::parse("[{ id: person:one, age: 39, score: 70 }]"); + let val = Value::parse( + "[ + { + age: 39, + id: person:one, + score: 70, + } + ]", + ); assert_eq!(tmp, val); // let tmp = res.remove(0).result?;