Skip to content

Commit

Permalink
Fix regression of reduce statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ex-nihil committed Jan 5, 2023
1 parent 5bb08df commit 2472388
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poe_query"
version = "0.1.15"
version = "0.1.16"
authors = ["Daniel <daniel@timeloop.se>"]
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion src/dat/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl DatFile {
}

pub fn valid(&self, spec: &FileSpec) {
info!("Validating using specification '{}'", spec);
debug!("Validating using specification '{}'", spec);
let last_field = spec.file_fields.last();
if let Some(field) = last_field {
let spec_row_size = field.field_offset + FileSpec::field_size(field);
Expand Down
1 change: 0 additions & 1 deletion src/query/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ kv_by_field = { identifier }
construct = _{ array_construction | object_construct }
array_construction = { "[" ~ query* ~ "]" }


// OBJECT CONSTRUCTION
object_construct = { "{" ~ ((key_value | kv_by_field) ~ comma?)* ~ "}" }
key_value = { key ~ (!("," ~ &key) ~ query)+ }
Expand Down
2 changes: 1 addition & 1 deletion src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn to_term(pair: pest::iterators::Pair<Rule>) -> Term {
};
initial.append(&mut build_ast(inner_next));
}
_ => current.append(&mut build_ast(next.into_inner().next().unwrap()))
_ => current.append(&mut build_ast(next))
}
}
Term::Reduce(outer_terms, initial, inner_terms)
Expand Down
7 changes: 5 additions & 2 deletions src/traversal/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,13 @@ impl<'a> DataTraverser<'a> for StaticContext<'a> {


let initial = self.traverse_terms_inner(&mut context.clone_value(None), cache, init);
let variable = vars.first().unwrap().as_str();
let Some(variable) = vars.first() else {
return None;
};

let value = cache
.variables
.get(variable)
.get(variable.as_str())
.unwrap_or(&Value::Empty)
.clone();

Expand Down
9 changes: 9 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ fn field() {
assert_eq!(result, vec!["2"]);
}

#[test]
fn reduce() {
let result = process(r#"[
{ "ring": 1000 },
{ "default": 1000 }
] | reduce .[] as $item ({}; . + $item)"#);

assert_eq!(result, vec![r#"{"ring":1000,"default":1000}"#]);
}

0 comments on commit 2472388

Please sign in to comment.