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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ keywords = ["cql2"]

[dependencies]
boon = "0.6.0"
enum-as-inner = "0.6.1"
geo-types = "0.7.13"
geojson = "0.24.1"
geos = "9.1.1"
geozero = "0.14.0"
jiff = "0.1.15"
json_dotpath = "1.1.0"
lazy_static = "1.5"
pest = "2.7"
pest_derive = { version = "2.7", features = ["grammar-extras"] }
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.reduce(Some(&json!({})));
}
if self.validate {
let validator = Validator::new().unwrap();
let value = serde_json::to_value(&expr).unwrap();
Expand Down
28 changes: 28 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ pub enum Error {
#[error(transparent)]
Geozero(#[from] geozero::error::GeozeroError),

/// [geos::Error]
#[error(transparent)]
Geos(#[from] geos::Error),

/// Invalid CQL2 text
#[error("invalid cql2-text: {0}")]
InvalidCql2Text(String),
Expand Down Expand Up @@ -65,4 +69,28 @@ 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(),

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

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

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

/// 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(),
}
Loading
Loading