Skip to content

Commit 3e980e3

Browse files
bitnergadomski
andauthored
add ability to reduce constants and match cql2 against json (#55)
Add ability to reduce constant expressions using json and to evaluate whether a json item matches a CQL2 Query. --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent 896e8a0 commit 3e980e3

File tree

10 files changed

+1031
-161
lines changed

10 files changed

+1031
-161
lines changed

Cargo.lock

+417-151
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ license = { workspace = true }
2323
keywords = ["cql2"]
2424

2525
[dependencies]
26-
boon = "0.6.0"
27-
geo-types = "0.7.13"
26+
boon = "0.6.1"
27+
geo = "0.29.3"
28+
geo-types = "0.7.15"
2829
geojson = "0.24.1"
2930
geozero = "0.14.0"
31+
jiff = "0.1.24"
32+
json_dotpath = "1.1.0"
3033
lazy_static = "1.5"
34+
like = "0.3.1"
3135
pest = "2.7"
3236
pest_derive = { version = "2.7", features = ["grammar-extras"] }
3337
pg_escape = "0.1.1"
3438
serde = "1.0"
35-
serde_derive = "1.0"
36-
serde_json = { version = "1.0", features = ["preserve_order"] }
39+
serde_derive = "1.0.217"
40+
serde_json = { version = "1.0.135", features = ["preserve_order"] }
3741
thiserror = "2.0"
42+
unaccent = "0.1.0"
43+
wkt = "0.12.0"
3844

3945
[dev-dependencies]
4046
assert-json-diff = "2"
41-
rstest = "0.23"
47+
rstest = "0.24.0"
4248

4349
[workspace]
4450
default-members = [".", "cli"]

cli/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ pub struct Cli {
3030
#[arg(long, default_value_t = true, action = ArgAction::Set)]
3131
validate: bool,
3232

33+
/// Reduce the CQL2
34+
#[arg(long, default_value_t = false, action = ArgAction::Set)]
35+
reduce: bool,
36+
3337
/// Verbosity.
3438
///
3539
/// Provide this argument several times to turn up the chatter.
@@ -95,7 +99,7 @@ impl Cli {
9599
InputFormat::Text
96100
}
97101
});
98-
let expr: Expr = match input_format {
102+
let mut expr: Expr = match input_format {
99103
InputFormat::Json => cql2::parse_json(&input)?,
100104
InputFormat::Text => match cql2::parse_text(&input) {
101105
Ok(expr) => expr,
@@ -104,6 +108,9 @@ impl Cli {
104108
}
105109
},
106110
};
111+
if self.reduce {
112+
expr = expr.reduce(None)?;
113+
}
107114
if self.validate {
108115
let validator = Validator::new().unwrap();
109116
let value = serde_json::to_value(&expr).unwrap();

src/error.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::Expr;
12
use thiserror::Error;
23

34
/// Crate-specific error enum.
@@ -65,4 +66,40 @@ pub enum Error {
6566
/// validator's data.
6667
#[error("validation error")]
6768
Validation(serde_json::Value),
69+
70+
/// Error Converting Expr to f64
71+
#[error("Could not convert Expression to f64")]
72+
ExprToF64(Expr),
73+
74+
/// Error Converting Expr to bool
75+
#[error("Could not convert Expression to bool")]
76+
ExprToBool(Expr),
77+
78+
/// Error Converting Expr to geometry
79+
#[error("Could not convert Expression to Geometry")]
80+
ExprToGeom(Expr),
81+
82+
/// Error Converting Expr to DateRange
83+
#[error("Could not convert Expression to DateRange")]
84+
ExprToDateRange(Expr),
85+
86+
/// Operator not implemented.
87+
#[error("Operator {0} is not implemented for this type.")]
88+
OpNotImplemented(&'static str),
89+
90+
/// Expression not reduced to boolean
91+
#[error("Could not reduce expression to boolean")]
92+
NonReduced(),
93+
94+
/// Could not run arith operation
95+
#[error("Could not run operation.")]
96+
OperationError(),
97+
98+
/// [json_dotpath::Error]
99+
#[error(transparent)]
100+
JsonDotpath(#[from] json_dotpath::Error),
101+
102+
/// [like::Error]
103+
#[error(transparent)]
104+
Like(#[from] like::InvalidPatternError),
68105
}

0 commit comments

Comments
 (0)