Skip to content

Commit

Permalink
update deps + release 1.0.0 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
deankarn committed Dec 29, 2023
1 parent 6f38202 commit 61deec1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 43 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: Lint & Test
on:
pull_request:
types: [opened, edited, reopened, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
CARGO_TERM_COLOR: always
jobs:
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0] - 2023-12-29
### Changed
- Updated deps.
- Releasing 1.0.0.

## [0.12.0] - 2023-06-17
### Changed
- Function signature of custom coercions to allow parsing more complex coercions types such as substr.
Expand Down Expand Up @@ -120,7 +125,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release.

[Unreleased]: https://github.com/rust-playground/ksql/compare/v0.12.0...HEAD
[Unreleased]: https://github.com/rust-playground/ksql/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/rust-playground/ksql/compare/v0.12.0...v1.0.0
[0.12.0]: https://github.com/rust-playground/ksql/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/rust-playground/ksql/compare/v0.10.0...v0.11.0
[0.10.0]: https://github.com/rust-playground/ksql/compare/v0.9.1...v0.10.0
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ksql"
description = "A JSON data expression lexer, parser, cli and library"
version = "0.12.0"
version = "1.0.0"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -17,13 +17,13 @@ keywords = [

[dependencies]
anydate = "0.3.0"
anyhow = "1.0.71"
chrono = { version = "0.4.26", features = ["serde"] }
clap = { version = "4.3.0", features = ["derive"] }
anyhow = "1.0.75"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.4.7", features = ["derive"] }
gjson = "0.8.1"
serde = { version = "1.0.163", features = ["derive"] }
serde_json = "1.0.96"
thiserror = "1.0.40"
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"

[dev-dependencies]
criterion = { version = "0.5.1", features = ["html_reports"] }
Expand Down
68 changes: 33 additions & 35 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ pub fn coercions() -> &'static RwLock<HashMap<String, CustomCoercion>> {
} => None,
tok => {
let start = tok.start as usize;
return Err(Error::Custom(format!(
Err(Error::Custom(format!(
"Expected number after _substr_[ but got {}",
String::from_utf8_lossy(&parser.exp[start..start + tok.len as usize])
)))?;
)))?
}
};

Expand Down Expand Up @@ -215,10 +215,10 @@ pub fn coercions() -> &'static RwLock<HashMap<String, CustomCoercion>> {
} => None,
tok => {
let start = tok.start as usize;
return Err(Error::Custom(format!(
Err(Error::Custom(format!(
"Expected number after _substr_[n: but got {}",
String::from_utf8_lossy(&parser.exp[start..start + tok.len as usize])
)))?;
)))?
}
};

Expand All @@ -237,16 +237,12 @@ pub fn coercions() -> &'static RwLock<HashMap<String, CustomCoercion>> {
}

match (start_idx, end_idx) {
(Some(start), Some(end)) if start > end => {
return Err(Error::Custom(format!(
"Start index {start} is greater than end index {end}"
)))?;
}
(None, None) => {
return Err(Error::Custom(
"Start and end index for substr cannot both be None".to_string(),
))?;
}
(Some(start), Some(end)) if start > end => Err(Error::Custom(format!(
"Start index {start} is greater than end index {end}"
)))?,
(None, None) => Err(Error::Custom(
"Start and end index for substr cannot both be None".to_string(),
))?,
_ => {}
}

Expand Down Expand Up @@ -754,7 +750,9 @@ impl Expression for COERCENumber {
)),
Value::Number(num) => Ok(Value::Number(num)),
Value::Bool(b) => Ok(Value::Number(if b { 1.0 } else { 0.0 })),
Value::DateTime(dt) => Ok(Value::Number(dt.timestamp_nanos() as f64)),
Value::DateTime(dt) => Ok(Value::Number(
dt.timestamp_nanos_opt().unwrap_or_default() as f64
)),
_ => Err(Error::UnsupportedCOERCE(
format!("{value} COERCE datetime",),
)),
Expand Down Expand Up @@ -1384,7 +1382,7 @@ mod tests {
#[test]
fn sp_add_sp_num() -> anyhow::Result<()> {
let src = r#"{"field1":10.1,"field2":23.23}"#;
let expression = r#".field1 + .field2"#;
let expression = ".field1 + .field2";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1395,7 +1393,7 @@ mod tests {
#[test]
fn sp_sub_sp() -> anyhow::Result<()> {
let src = r#"{"field1":10.1,"field2":23.23}"#;
let expression = r#".field2 - .field1"#;
let expression = ".field2 - .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1406,7 +1404,7 @@ mod tests {
#[test]
fn sp_mult_identsp() -> anyhow::Result<()> {
let src = r#"{"field1":11.1,"field2":3}"#;
let expression = r#".field2 * .field1"#;
let expression = ".field2 * .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1417,7 +1415,7 @@ mod tests {
#[test]
fn sp_div_sp() -> anyhow::Result<()> {
let src = r#"{"field1":3,"field2":33.3}"#;
let expression = r#".field2 / .field1"#;
let expression = ".field2 / .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1428,7 +1426,7 @@ mod tests {
#[test]
fn num_add_num() -> anyhow::Result<()> {
let src = "";
let expression = r#"11.1 + 22.2"#;
let expression = "11.1 + 22.2";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1439,7 +1437,7 @@ mod tests {
#[test]
fn sp_add_num() -> anyhow::Result<()> {
let src = r#"{"field1":3,"field2":33.3}"#;
let expression = r#"11.1 + .field1"#;
let expression = "11.1 + .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1450,7 +1448,7 @@ mod tests {
#[test]
fn sp_eq_num_false() -> anyhow::Result<()> {
let src = r#"{"field1":3,"field2":33.3}"#;
let expression = r#"11.1 == .field1"#;
let expression = "11.1 == .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1461,7 +1459,7 @@ mod tests {
#[test]
fn sp_eq_num_true() -> anyhow::Result<()> {
let src = r#"{"field1":11.1,"field2":33.3}"#;
let expression = r#"11.1 == .field1"#;
let expression = "11.1 == .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1472,7 +1470,7 @@ mod tests {
#[test]
fn sp_gt_num_false() -> anyhow::Result<()> {
let src = r#"{"field1":11.1,"field2":33.3}"#;
let expression = r#"11.1 > .field1"#;
let expression = "11.1 > .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand All @@ -1483,7 +1481,7 @@ mod tests {
#[test]
fn sp_gte_num_true() -> anyhow::Result<()> {
let src = r#"{"field1":11.1,"field2":33.3}"#;
let expression = r#"11.1 >= .field1"#;
let expression = "11.1 >= .field1";

let ex = Parser::parse(expression)?;
let result = ex.calculate(src.as_ref())?;
Expand Down Expand Up @@ -1740,7 +1738,7 @@ mod tests {
let result = ex.calculate("".as_bytes())?;
assert_eq!(Value::Bool(false), result);

let expression = r#"[] == []"#;
let expression = "[] == []";
let ex = Parser::parse(expression)?;
let result = ex.calculate("".as_bytes())?;
assert_eq!(Value::Bool(true), result);
Expand Down Expand Up @@ -1971,31 +1969,31 @@ mod tests {
let expression = "COERCE .key _number_";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"1.0"#, format!("{result}"));
assert_eq!("1.0", format!("{result}"));

let src = r#"{"key":"2"}"#.as_bytes();
let expression = "COERCE .key _number_";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"2.0"#, format!("{result}"));
assert_eq!("2.0", format!("{result}"));

let src = r#"{"key":true}"#.as_bytes();
let expression = "COERCE .key _number_";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"1.0"#, format!("{result}"));
assert_eq!("1.0", format!("{result}"));

let src = r#"{"key":false}"#.as_bytes();
let expression = "COERCE .key _number_";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"0.0"#, format!("{result}"));
assert_eq!("0.0", format!("{result}"));

let src = r#"{"key":"2023-05-30T06:21:05Z"}"#.as_bytes();
let expression = "COERCE .key _datetime_,_number_";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"1.685427665e18"#, format!("{result}"));
assert_eq!("1.685427665e18", format!("{result}"));

Ok(())
}
Expand Down Expand Up @@ -2230,7 +2228,7 @@ mod tests {
let result = ex.calculate(src)?;
assert_eq!(Value::Bool(true), result);

let expression = r#".MyValue != NULL && .MyValue > 19"#;
let expression = ".MyValue != NULL && .MyValue > 19";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(Value::Bool(false), result);
Expand Down Expand Up @@ -2270,7 +2268,7 @@ mod tests {
let result = ex.calculate("{}".as_bytes())?;
assert_eq!(Value::String("*******".to_string()), result);

let expression = r#"COERCE 1234 _string_,_star_"#;
let expression = "COERCE 1234 _string_,_star_";
let ex = Parser::parse(expression)?;
let result = ex.calculate("{}".as_bytes())?;
assert_eq!(Value::String("****".to_string()), result);
Expand Down Expand Up @@ -2299,7 +2297,7 @@ mod tests {
assert_eq!(r#""yb""#, format!("{result}"));

// const eligible
let src = r#"{}"#.as_bytes();
let src = "{}".as_bytes();
let expression = r#"COERCE "Joeybloggs" _substr_[3:5]"#;
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
Expand All @@ -2310,7 +2308,7 @@ mod tests {
let expression = "COERCE .name _substr_[500:1000]";
let ex = Parser::parse(expression)?;
let result = ex.calculate(src)?;
assert_eq!(r#"null"#, format!("{result}"));
assert_eq!("null", format!("{result}"));
Ok(())
}
}

0 comments on commit 61deec1

Please sign in to comment.