-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support InList clause in streaming SQL (#1694)
* feat: support InList clause in streaming SQL Signed-off-by: hi-rustin <[email protected]> * feat: support not in list Signed-off-by: hi-rustin <[email protected]> * fix: use users Signed-off-by: hi-rustin <[email protected]> * Remove broken tests Signed-off-by: hi-rustin <[email protected]> * Fix fmt Signed-off-by: hi-rustin <[email protected]> * Better test code Signed-off-by: hi-rustin <[email protected]> --------- Signed-off-by: hi-rustin <[email protected]> Co-authored-by: Dario Pizzamiglio <[email protected]>
- Loading branch information
1 parent
5831ba4
commit bbaa21f
Showing
6 changed files
with
180 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use dozer_types::types::{Field, Record, Schema}; | ||
|
||
use crate::pipeline::errors::PipelineError; | ||
use crate::pipeline::expression::execution::{Expression, ExpressionExecutor}; | ||
|
||
pub(crate) fn evaluate_in_list( | ||
schema: &Schema, | ||
expr: &Expression, | ||
list: &[Expression], | ||
negated: bool, | ||
record: &Record, | ||
) -> Result<Field, PipelineError> { | ||
let field = expr.evaluate(record, schema)?; | ||
let mut result = false; | ||
for item in list { | ||
let item = item.evaluate(record, schema)?; | ||
if field == item { | ||
result = true; | ||
break; | ||
} | ||
} | ||
// Negate the result if the IN list was negated. | ||
if negated { | ||
result = !result; | ||
} | ||
Ok(Field::Boolean(result)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use crate::pipeline::expression::tests::test_common::run_fct; | ||
use dozer_types::types::{Field, FieldDefinition, FieldType, Schema, SourceDefinition}; | ||
|
||
#[test] | ||
fn test_in_list() { | ||
let f = run_fct( | ||
"SELECT 42 IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", | ||
Schema::empty(), | ||
vec![], | ||
); | ||
assert_eq!(f, Field::Boolean(false)); | ||
|
||
let f = run_fct( | ||
"SELECT 42 IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42)", | ||
Schema::empty(), | ||
vec![], | ||
); | ||
assert_eq!(f, Field::Boolean(true)); | ||
|
||
let schema = Schema::empty() | ||
.field( | ||
FieldDefinition::new( | ||
String::from("age"), | ||
FieldType::Int, | ||
false, | ||
SourceDefinition::Dynamic, | ||
), | ||
false, | ||
) | ||
.clone(); | ||
let f = run_fct( | ||
"SELECT age IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) FROM users", | ||
schema.clone(), | ||
vec![Field::Int(42)], | ||
); | ||
assert_eq!(f, Field::Boolean(false)); | ||
|
||
let f = run_fct( | ||
"SELECT age IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42) FROM users", | ||
schema.clone(), | ||
vec![Field::Int(42)], | ||
); | ||
assert_eq!(f, Field::Boolean(true)); | ||
} | ||
|
||
#[test] | ||
fn test_not_in_list() { | ||
let f = run_fct( | ||
"SELECT 42 NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", | ||
Schema::empty(), | ||
vec![], | ||
); | ||
assert_eq!(f, Field::Boolean(true)); | ||
|
||
let f = run_fct( | ||
"SELECT 42 NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42)", | ||
Schema::empty(), | ||
vec![], | ||
); | ||
assert_eq!(f, Field::Boolean(false)); | ||
|
||
let schema = Schema::empty() | ||
.field( | ||
FieldDefinition::new( | ||
String::from("age"), | ||
FieldType::Int, | ||
false, | ||
SourceDefinition::Dynamic, | ||
), | ||
false, | ||
) | ||
.clone(); | ||
let f = run_fct( | ||
"SELECT age NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) FROM users", | ||
schema.clone(), | ||
vec![Field::Int(42)], | ||
); | ||
assert_eq!(f, Field::Boolean(true)); | ||
|
||
let f = run_fct( | ||
"SELECT age NOT IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 42) FROM users", | ||
schema.clone(), | ||
vec![Field::Int(42)], | ||
); | ||
assert_eq!(f, Field::Boolean(false)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters