-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"hr": { | ||
"employeesNest": [ | ||
{ | ||
"title": null, | ||
"id": 3, | ||
"projects": [ | ||
{ | ||
"name": "AWS Redshift Spectrum querying" | ||
}, | ||
{ | ||
"name": "AWS Redshift security" | ||
}, | ||
{ | ||
"name": "AWS Aurora security" | ||
} | ||
], | ||
"name": "Bob Smith" | ||
}, | ||
{ | ||
"title": "Dev Mgr", | ||
"name": "Susan Smith", | ||
"id": 4, | ||
"projects": [] | ||
}, | ||
{ | ||
"id": 6, | ||
"title": "Software Eng 2", | ||
"projects": [ | ||
{ | ||
"name": "AWS Redshift security" | ||
} | ||
], | ||
"name": "Jane Smith" | ||
} | ||
] | ||
} | ||
} |
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,46 @@ | ||
use std::collections::HashMap; | ||
|
||
use itertools::Itertools; | ||
|
||
use crate::dsql_parser; | ||
use crate::models::JsonValue; | ||
use crate::pqlir_parser; | ||
use crate::sql::to_list; | ||
use crate::sql::Bingings; | ||
use crate::sql::DField; | ||
use crate::sql::DSql as Sql; | ||
use crate::sql::DWhereCond; | ||
use crate::sql::Dpath; | ||
use crate::sql_parser; | ||
|
||
pub fn run(sql: Sql, data: JsonValue) -> JsonValue { | ||
let fields = sql | ||
.select_clause | ||
.iter() | ||
.chain(sql.from_clause.iter()) | ||
.map(|e| e.to_owned()) | ||
.collect::<Vec<_>>(); | ||
let bindings = Bingings::from(fields.as_slice()); | ||
|
||
let select_fields = sql | ||
.select_clause | ||
.iter() | ||
.map(|field| field.to_owned().full(&bindings)) | ||
.collect::<Vec<_>>(); | ||
let bindings_for_select = Bingings::from(select_fields.as_slice()); | ||
|
||
let value = data.select_by_fields(&select_fields).unwrap(); | ||
let list = to_list(value); | ||
|
||
let filtered_list = list | ||
.iter() | ||
.filter_map(|value| match &sql.where_clause { | ||
Some(cond) if cond.eval(&value.to_owned(), &bindings, &bindings_for_select) => { | ||
Some(value.to_owned()) | ||
} | ||
_ => None, | ||
}) | ||
.collect::<Vec<JsonValue>>(); | ||
|
||
JsonValue::Array(filtered_list) | ||
} |
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