-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: Move the filter operator in new file
- Loading branch information
1 parent
44a1793
commit baba96c
Showing
4 changed files
with
38 additions
and
45 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,26 @@ | ||
use gitql_ast::expression::Expression; | ||
use gitql_core::environment::Environment; | ||
use gitql_core::object::Row; | ||
|
||
use crate::engine_evaluator::evaluate_expression; | ||
|
||
#[inline(always)] | ||
#[allow(clippy::borrowed_box)] | ||
pub fn filter_rows_by_condition( | ||
env: &mut Environment, | ||
condition: &Box<dyn Expression>, | ||
titles: &[String], | ||
objects: &Vec<Row>, | ||
) -> Result<Vec<Row>, String> { | ||
let mut rows: Vec<Row> = vec![]; | ||
|
||
for object in objects { | ||
if evaluate_expression(env, condition, titles, &object.values)?.as_bool() { | ||
rows.push(Row { | ||
values: object.values.clone(), | ||
}); | ||
} | ||
} | ||
|
||
Ok(rows) | ||
} |
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