Skip to content

Commit

Permalink
WIP: aw-query: Test make variables get consumed
Browse files Browse the repository at this point in the history
Previously they were cloned on each reference
  • Loading branch information
johan-bjareholt committed May 31, 2020
1 parent 132370b commit c423321
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 19 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ install:
# Install systemd user service
mkdir -p $(DESTDIR)$(PREFIX)/lib/systemd/user
install -m 644 aw-server.service $(DESTDIR)$(PREFIX)/lib/systemd/user/aw-server.service

coverage:
export CARGO_INCREMENTAL=0
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort"
export RUSTDOCFLAGS="-Cpanic=abort"
cargo build --verbose $(cargoflag)
cargo test --verbose $(cargoflag)
2 changes: 1 addition & 1 deletion aw-query/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod query_benchmarks {
}
//
let mut event_list = Vec::new();
for i in 0..3000 {
for i in 0..30000 {
let e = Event {
id: None,
timestamp: chrono::Utc::now() + Duration::seconds(i),
Expand Down
1 change: 1 addition & 0 deletions aw-query/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Expr_ {
Equal(Box<Expr>, Box<Expr>),

Var(String),
VarRef(String),
Assign(String, Box<Expr>),
Function(String, Box<Expr>),
If(Vec<(Box<Expr>, Vec<Expr>)>),
Expand Down
12 changes: 9 additions & 3 deletions aw-query/src/interpret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,17 @@ fn interpret_expr(
env.insert(var, val);
Ok(DataType::None())
}
// FIXME: avoid clone, it's slow
Var(var) => match env.get(&var) {
Some(v) => Ok(v.clone()),
Var(var) => match env.remove(&var) {
Some(v) => Ok(v),
None => Err(QueryError::VariableNotDefined(var.to_string())),
},
VarRef(var) => {
// TODO: Remove clone
match env.get(&var) {
Some(v) => Ok(v.clone()),
None => Err(QueryError::VariableNotDefined(var.to_string())),
}
}
Bool(lit) => Ok(DataType::Bool(lit)),
Number(lit) => Ok(DataType::Number(lit)),
String(litstr) => Ok(DataType::String(litstr.to_string())),
Expand Down
2 changes: 2 additions & 0 deletions aw-query/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum Token {
Number(f64),
String(String),
Plus,
Ampersand,
Minus,
Star,
Slash,
Expand Down Expand Up @@ -69,6 +70,7 @@ lexer! {

r#"=="# => (Token::Equals, text),
r#"="# => (Token::Assign, text),
r#"\&"# => (Token::Ampersand, text),
r#"\+"# => (Token::Plus, text),
r#"-"# => (Token::Minus, text),
r#"\*"# => (Token::Star, text),
Expand Down
4 changes: 4 additions & 0 deletions aw-query/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ parser! {
span: span!(),
node: Expr_::Var(v),
},
Ampersand Ident(v) => Expr {
span: span!(),
node: Expr_::VarRef(v),
},
Bool(b) => Expr {
span: span!(),
node: Expr_::Bool(b),
Expand Down
28 changes: 14 additions & 14 deletions aw-query/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ mod query_tests {
let code = String::from(
"
a=True; n=1;
if a { n=2; }
if &a { n=2; }
return n;",
);
match aw_query::query(&code, &interval, &ds).unwrap() {
Expand Down Expand Up @@ -269,8 +269,8 @@ mod query_tests {
let code = String::from(
"
a=False; b=True; n=1;
if a { n=2; }
elif b { n=3; }
if &a { n=2; }
elif &b { n=3; }
return n;",
);
match aw_query::query(&code, &interval, &ds).unwrap() {
Expand All @@ -282,8 +282,8 @@ mod query_tests {
let code = String::from(
"
a=False; b=True; n=1;
if a { n=2; }
elif a { n=3; }
if &a { n=2; }
elif &a { n=3; }
else { n=4; }
return n;",
);
Expand All @@ -296,7 +296,7 @@ mod query_tests {
let code = String::from(
"
a=True; n=1;
if a { if a { n = 2; } }
if &a { if &a { n = 2; } }
return n;",
);
match aw_query::query(&code, &interval, &ds).unwrap() {
Expand Down Expand Up @@ -359,16 +359,16 @@ mod query_tests {
events = concat(events, query_bucket("{}"));
events = categorize(events, [[["test"], {{ "type": "regex", "regex": "value$" }}], [["test", "testing"], {{ "type": "regex", "regex": "value$" }}]]);
events = tag(events, [["testtag", {{ "type": "regex", "regex": "test$" }}], ["another testtag", {{ "type": "regex", "regex": "test-pat$" }}]]);
total_duration = sum_durations(events);
total_duration = sum_durations(&events);
bucketnames = query_bucket_names();
print("test", "test2");
url_events = split_url_events (events);
filtered_events = filter_period_intersect(events, events);
filtered_events = filter_keyvals(events, "$category", [["Uncategorized"]]);
filtered_events = filter_keyvals_regex(events, "key", "regex");
chunked_events = chunk_events_by_key(events, "key");
merged_events = merge_events_by_keys(events, ["key"]);
return merged_events;"#,
events = split_url_events (events);
events = filter_period_intersect(&events, &events);
events = filter_keyvals(events, "$category", [["Uncategorized"]]);
events = filter_keyvals_regex(events, "key", "regex");
events = chunk_events_by_key(events, "key");
events = merge_events_by_keys(events, ["key"]);
return events;"#,
"testid", "testid"
);
match aw_query::query(&code, &interval, &ds).unwrap() {
Expand Down
2 changes: 1 addition & 1 deletion aw-webui

0 comments on commit c423321

Please sign in to comment.