Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

start of work to match cql2 against json #55

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
568 changes: 417 additions & 151 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@ license = { workspace = true }
keywords = ["cql2"]

[dependencies]
boon = "0.6.0"
geo-types = "0.7.13"
boon = "0.6.1"
geo = "0.29.3"
geo-types = "0.7.15"
geojson = "0.24.1"
geozero = "0.14.0"
jiff = "0.1.24"
json_dotpath = "1.1.0"
lazy_static = "1.5"
like = "0.3.1"
pest = "2.7"
pest_derive = { version = "2.7", features = ["grammar-extras"] }
pg_escape = "0.1.1"
serde = "1.0"
serde_derive = "1.0"
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_derive = "1.0.217"
serde_json = { version = "1.0.135", features = ["preserve_order"] }
thiserror = "2.0"
unaccent = "0.1.0"
wkt = "0.12.0"

[dev-dependencies]
assert-json-diff = "2"
rstest = "0.23"
rstest = "0.24.0"

[workspace]
default-members = [".", "cli"]
Expand Down
10 changes: 9 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{anyhow, Result};
use clap::{ArgAction, Parser, ValueEnum};
use cql2::{Expr, Validator};
use serde_json::json;
use std::io::Read;

/// The CQL2 command-line interface.
Expand Down Expand Up @@ -30,6 +31,10 @@ pub struct Cli {
#[arg(long, default_value_t = true, action = ArgAction::Set)]
validate: bool,

/// Reduce the CQL2
#[arg(long, default_value_t = false, action = ArgAction::Set)]
reduce: bool,

/// Verbosity.
///
/// Provide this argument several times to turn up the chatter.
Expand Down Expand Up @@ -95,7 +100,7 @@ impl Cli {
InputFormat::Text
}
});
let expr: Expr = match input_format {
let mut expr: Expr = match input_format {
InputFormat::Json => cql2::parse_json(&input)?,
InputFormat::Text => match cql2::parse_text(&input) {
Ok(expr) => expr,
Expand All @@ -104,6 +109,9 @@ impl Cli {
}
},
};
if self.reduce {
expr = expr.reduce(Some(&json!({})))?;
}
if self.validate {
let validator = Validator::new().unwrap();
let value = serde_json::to_value(&expr).unwrap();
Expand Down
37 changes: 37 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::Expr;
use thiserror::Error;

/// Crate-specific error enum.
Expand Down Expand Up @@ -65,4 +66,40 @@ pub enum Error {
/// validator's data.
#[error("validation error")]
Validation(serde_json::Value),

/// Error Converting Expr to f64
#[error("Could not convert Expression to f64")]
ExprToF64(Expr),

/// Error Converting Expr to bool
#[error("Could not convert Expression to bool")]
ExprToBool(Expr),

/// Error Converting Expr to geometry
#[error("Could not convert Expression to Geometry")]
ExprToGeom(Expr),

/// Error Converting Expr to DateRange
#[error("Could not convert Expression to DateRange")]
ExprToDateRange(Expr),

/// Operator not implemented.
#[error("Operator {0} is not implemented for this type.")]
OpNotImplemented(&'static str),

/// Expression not reduced to boolean
#[error("Could not reduce expression to boolean")]
NonReduced(),

/// Could not run arith operation
#[error("Could not run operation.")]
OperationError(),

/// [json_dotpath::Error]
#[error(transparent)]
JsonDotpath(#[from] json_dotpath::Error),

/// [like::Error]
#[error(transparent)]
Like(#[from] like::InvalidPatternError),
}
Loading
Loading