Skip to content

Commit

Permalink
Merge branch 'main' into fuchsnj/fix_array_object_undefined_literals
Browse files Browse the repository at this point in the history
  • Loading branch information
fuchsnj authored Aug 18, 2023
2 parents 6993fe4 + e9ab9b5 commit 1929aaa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn read_grok_patterns() {
fs::read_dir(Path::new("src/datadog/grok/patterns"))
.expect("can't read 'patterns' dir")
.filter_map(|path| File::open(path.expect("can't read 'patterns' dir").path()).ok())
.flat_map(|f| BufReader::new(f).lines().filter_map(|l| l.ok()))
.flat_map(|f| BufReader::new(f).lines().map_while(Result::ok))
.filter(|line| !line.starts_with('#') && !line.trim().is_empty())
.for_each(|line| {
let (key, value) = line.split_at(
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.69.0"
channel = "1.71.1"
profile = "default"
29 changes: 20 additions & 9 deletions src/compiler/value/arithmetic.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(clippy::integer_arithmetic)]
#![deny(clippy::arithmetic_side_effects)]

use std::collections::BTreeMap;
use std::ops::{Add, Mul, Rem, Sub};

use crate::value::Value;
use bytes::{BufMut, Bytes, BytesMut};
Expand Down Expand Up @@ -79,7 +80,10 @@ impl VrlValueArithmetic for Value {
let rhv = rhs.try_into_i64().map_err(|_| err())?;
i64::wrapping_mul(lhv, rhv).into()
}
Value::Float(lhv) => (lhv * rhs.try_into_f64().map_err(|_| err())?).into(),
Value::Float(lhv) => {
let rhs = rhs.try_into_f64().map_err(|_| err())?;
lhv.mul(rhs).into()
}
Value::Bytes(lhv) if rhs.is_integer() => {
Bytes::from(lhv.repeat(as_usize(rhs.try_integer()?))).into()
}
Expand Down Expand Up @@ -118,14 +122,15 @@ impl VrlValueArithmetic for Value {
.map_err(|_| ValueError::Add(Kind::integer(), rhs.kind()))?;
i64::wrapping_add(lhs, rhv).into()
}
(Value::Float(lhs), rhs) => (lhs
+ rhs
(Value::Float(lhs), rhs) => {
let rhs = rhs
.try_into_f64()
.map_err(|_| ValueError::Add(Kind::float(), rhs.kind()))?)
.into(),
.map_err(|_| ValueError::Add(Kind::float(), rhs.kind()))?;
lhs.add(rhs).into()
}
(lhs @ Value::Bytes(_), Value::Null) => lhs,
(Value::Bytes(lhs), Value::Bytes(rhs)) => {
#[allow(clippy::integer_arithmetic)]
#[allow(clippy::arithmetic_side_effects)]
let mut value = BytesMut::with_capacity(lhs.len() + rhs.len());
value.put(lhs);
value.put(rhs);
Expand All @@ -150,7 +155,10 @@ impl VrlValueArithmetic for Value {
let rhv = rhs.try_into_i64().map_err(|_| err())?;
i64::wrapping_sub(lhv, rhv).into()
}
Value::Float(lhv) => (lhv - rhs.try_into_f64().map_err(|_| err())?).into(),
Value::Float(lhv) => {
let rhv = rhs.try_into_f64().map_err(|_| err())?;
lhv.sub(rhv).into()
}
_ => return Err(err()),
};

Expand Down Expand Up @@ -212,7 +220,10 @@ impl VrlValueArithmetic for Value {
let rhv = rhs.try_into_i64().map_err(|_| err())?;
i64::wrapping_rem(lhv, rhv).into()
}
Value::Float(lhv) => (lhv % rhs.try_into_f64().map_err(|_| err())?).into(),
Value::Float(lhv) => {
let rhv = rhs.try_into_f64().map_err(|_| err())?;
lhv.rem(rhv).into()
}
_ => return Err(err()),
};

Expand Down
6 changes: 3 additions & 3 deletions src/stdlib/encode_json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::compiler::prelude::*;

fn encode_json(value: Value, pretty: bool) -> Resolved {
fn encode_json(value: Value, pretty: bool) -> Value {
// With `vrl::Value` it should not be possible to get `Err`.

let result = if pretty {
Expand All @@ -10,7 +10,7 @@ fn encode_json(value: Value, pretty: bool) -> Resolved {
};

match result {
Ok(value) => Ok(value.into()),
Ok(value) => value.into(),
Err(error) => unreachable!("unable encode to json: {}", error),
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ impl FunctionExpression for EncodeJsonFn {
Some(pretty) => pretty.resolve(ctx)?.try_boolean()?,
None => false,
};
encode_json(value, pretty)
Ok(encode_json(value, pretty))
}

fn type_def(&self, _: &state::TypeState) -> TypeDef {
Expand Down
2 changes: 1 addition & 1 deletion src/stdlib/match_datadog_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Function for MatchDatadogQuery {
// Build the matcher function that accepts a VRL event value. This will parse the `node`
// at boot-time and return a boxed func that contains just the logic required to match a
// VRL `Value` against the Datadog Search Syntax literal.
let filter = build_matcher(&node, &VrlFilter::default());
let filter = build_matcher(&node, &VrlFilter);

Ok(MatchDatadogQueryFn { value, filter }.as_expr())
}
Expand Down

0 comments on commit 1929aaa

Please sign in to comment.