From 61deec1fd9327cb96e1557269a23fe8d0392ca60 Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Thu, 28 Dec 2023 21:40:56 -0800 Subject: [PATCH] update deps + release 1.0.0 (#18) --- .github/workflows/rust.yml | 5 +++ CHANGELOG.md | 8 ++++- Cargo.toml | 14 ++++---- src/parser.rs | 68 ++++++++++++++++++-------------------- 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index c8d6fe5..895cf17 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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: diff --git a/CHANGELOG.md b/CHANGELOG.md index 094a6b7..05a40d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 65171a4..a8a4ff5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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"] } diff --git a/src/parser.rs b/src/parser.rs index ae2bbbb..fe2c5a4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -169,10 +169,10 @@ pub fn coercions() -> &'static RwLock> { } => 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]) - )))?; + )))? } }; @@ -215,10 +215,10 @@ pub fn coercions() -> &'static RwLock> { } => 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]) - )))?; + )))? } }; @@ -237,16 +237,12 @@ pub fn coercions() -> &'static RwLock> { } 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(), + ))?, _ => {} } @@ -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",), )), @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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())?; @@ -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); @@ -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(()) } @@ -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); @@ -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); @@ -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)?; @@ -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(()) } }