From 2e854063b099958a8ff73b348c5491ec8c4cc84f Mon Sep 17 00:00:00 2001 From: chubei <914745487@qq.com> Date: Tue, 19 Sep 2023 15:59:11 +0800 Subject: [PATCH] chore: Split `jsonpath` --- Cargo.lock | 12 +++++++++++ Cargo.toml | 2 +- dozer-sql/Cargo.toml | 13 ++++++------ dozer-sql/jsonpath/Cargo.toml | 21 +++++++++++++++++++ dozer-sql/{src => }/jsonpath/README.md | 0 .../jsonpath/mod.rs => jsonpath/src/lib.rs} | 8 +++---- .../src}/parser/grammar/json_path.pest | 0 .../src}/parser/macros.rs | 0 .../jsonpath => jsonpath/src}/parser/mod.rs | 0 .../jsonpath => jsonpath/src}/parser/model.rs | 2 +- .../src}/parser/parser.rs | 7 ++++--- .../jsonpath => jsonpath/src}/path/index.rs | 12 +++++------ .../jsonpath => jsonpath/src}/path/json.rs | 0 .../jsonpath => jsonpath/src}/path/mod.rs | 8 +++---- .../jsonpath => jsonpath/src}/path/top.rs | 6 +++--- dozer-sql/src/lib.rs | 7 ------- .../src/pipeline/expression/json_functions.rs | 2 +- 17 files changed, 63 insertions(+), 37 deletions(-) create mode 100644 dozer-sql/jsonpath/Cargo.toml rename dozer-sql/{src => }/jsonpath/README.md (100%) rename dozer-sql/{src/jsonpath/mod.rs => jsonpath/src/lib.rs} (96%) rename dozer-sql/{src/jsonpath => jsonpath/src}/parser/grammar/json_path.pest (100%) rename dozer-sql/{src/jsonpath => jsonpath/src}/parser/macros.rs (100%) rename dozer-sql/{src/jsonpath => jsonpath/src}/parser/mod.rs (100%) rename dozer-sql/{src/jsonpath => jsonpath/src}/parser/model.rs (98%) rename dozer-sql/{src/jsonpath => jsonpath/src}/parser/parser.rs (97%) rename dozer-sql/{src/jsonpath => jsonpath/src}/path/index.rs (96%) rename dozer-sql/{src/jsonpath => jsonpath/src}/path/json.rs (100%) rename dozer-sql/{src/jsonpath => jsonpath/src}/path/mod.rs (92%) rename dozer-sql/{src/jsonpath => jsonpath/src}/path/top.rs (97%) diff --git a/Cargo.lock b/Cargo.lock index a841ab5e10..4bda283428 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2787,6 +2787,7 @@ dependencies = [ "dozer-types", "enum_dispatch", "half 2.3.1", + "jsonpath", "jsonpath-rust", "like", "linked-hash-map", @@ -4249,6 +4250,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "jsonpath" +version = "0.2.6" +dependencies = [ + "dozer-types", + "lazy_static", + "pest", + "pest_derive", + "regex", +] + [[package]] name = "jsonpath-rust" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 0dcbfd4775..f90ae5752f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ members = [ "dozer-log", "dozer-log-js", "dozer-log-python", - "dozer-utils" + "dozer-utils", ] resolver = "2" diff --git a/dozer-sql/Cargo.toml b/dozer-sql/Cargo.toml index 95679dc0f3..883c16e0fb 100644 --- a/dozer-sql/Cargo.toml +++ b/dozer-sql/Cargo.toml @@ -7,10 +7,11 @@ authors = ["getdozer/dozer-dev"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -dozer-types = {path = "../dozer-types"} -dozer-storage = {path = "../dozer-storage"} -dozer-core = {path = "../dozer-core"} -dozer-tracing = {path = "../dozer-tracing"} +dozer-types = { path = "../dozer-types" } +dozer-storage = { path = "../dozer-storage" } +dozer-core = { path = "../dozer-core" } +dozer-tracing = { path = "../dozer-tracing" } +jsonpath = { path = "jsonpath" } ahash = "0.8.3" enum_dispatch = "0.3.11" @@ -23,8 +24,8 @@ num-traits = "0.2.15" pest = "2.6.0" pest_derive = "2.5.6" regex = "1.8.1" -sqlparser = {git = "https://github.com/getdozer/sqlparser-rs.git" } -uuid = {version = "1.3.0", features = ["v1", "v4", "fast-rng"]} +sqlparser = { git = "https://github.com/getdozer/sqlparser-rs.git" } +uuid = { version = "1.3.0", features = ["v1", "v4", "fast-rng"] } bigdecimal = { version = "0.3", features = ["serde"], optional = true } ort = { version = "1.15.2", optional = true } ndarray = { version = "0.15", optional = true } diff --git a/dozer-sql/jsonpath/Cargo.toml b/dozer-sql/jsonpath/Cargo.toml new file mode 100644 index 0000000000..82bab34296 --- /dev/null +++ b/dozer-sql/jsonpath/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "jsonpath" +description = "The library provides the basic functionality to find the set of the data according to the filtering query." +version = "0.2.6" +authors = ["BorisZhguchev "] +edition = "2018" +license-file = "LICENSE" +homepage = "https://github.com/besok/jsonpath-rust" +repository = "https://github.com/besok/jsonpath-rust" +readme = "README.md" +keywords = ["json", "json-path", "jsonpath", "jsonpath-rust", "xpath"] +categories = ["development-tools", "parsing", "text-processing"] + +[dependencies] +dozer-types = { path = "../../dozer-types" } +regex = "1" +pest = "2.0" +pest_derive = "2.0" + +[dev-dependencies] +lazy_static = "1.0" diff --git a/dozer-sql/src/jsonpath/README.md b/dozer-sql/jsonpath/README.md similarity index 100% rename from dozer-sql/src/jsonpath/README.md rename to dozer-sql/jsonpath/README.md diff --git a/dozer-sql/src/jsonpath/mod.rs b/dozer-sql/jsonpath/src/lib.rs similarity index 96% rename from dozer-sql/src/jsonpath/mod.rs rename to dozer-sql/jsonpath/src/lib.rs index f6bb58226f..7791404a2d 100644 --- a/dozer-sql/src/jsonpath/mod.rs +++ b/dozer-sql/jsonpath/src/lib.rs @@ -1,8 +1,6 @@ -#![allow(clippy::vec_init_then_push)] - -use crate::jsonpath::parser::model::JsonPath; -use crate::jsonpath::path::{json_path_instance, PathInstance}; -use crate::jsonpath::JsonPathValue::{NewValue, NoValue, Slice}; +use crate::parser::model::JsonPath; +use crate::path::{json_path_instance, PathInstance}; +use crate::JsonPathValue::{NewValue, NoValue, Slice}; use dozer_types::json_types::JsonValue; use std::convert::TryInto; use std::fmt::Debug; diff --git a/dozer-sql/src/jsonpath/parser/grammar/json_path.pest b/dozer-sql/jsonpath/src/parser/grammar/json_path.pest similarity index 100% rename from dozer-sql/src/jsonpath/parser/grammar/json_path.pest rename to dozer-sql/jsonpath/src/parser/grammar/json_path.pest diff --git a/dozer-sql/src/jsonpath/parser/macros.rs b/dozer-sql/jsonpath/src/parser/macros.rs similarity index 100% rename from dozer-sql/src/jsonpath/parser/macros.rs rename to dozer-sql/jsonpath/src/parser/macros.rs diff --git a/dozer-sql/src/jsonpath/parser/mod.rs b/dozer-sql/jsonpath/src/parser/mod.rs similarity index 100% rename from dozer-sql/src/jsonpath/parser/mod.rs rename to dozer-sql/jsonpath/src/parser/mod.rs diff --git a/dozer-sql/src/jsonpath/parser/model.rs b/dozer-sql/jsonpath/src/parser/model.rs similarity index 98% rename from dozer-sql/src/jsonpath/parser/model.rs rename to dozer-sql/jsonpath/src/parser/model.rs index 56e5b1aff7..094c6e566c 100644 --- a/dozer-sql/src/jsonpath/parser/model.rs +++ b/dozer-sql/jsonpath/src/parser/model.rs @@ -1,4 +1,4 @@ -use crate::jsonpath::parser::parser::parse_json_path; +use crate::parser::parser::parse_json_path; use dozer_types::json_types::JsonValue; use std::convert::TryFrom; diff --git a/dozer-sql/src/jsonpath/parser/parser.rs b/dozer-sql/jsonpath/src/parser/parser.rs similarity index 97% rename from dozer-sql/src/jsonpath/parser/parser.rs rename to dozer-sql/jsonpath/src/parser/parser.rs index 8dc79c9a82..e4778f80f3 100644 --- a/dozer-sql/src/jsonpath/parser/parser.rs +++ b/dozer-sql/jsonpath/src/parser/parser.rs @@ -1,14 +1,15 @@ -use crate::jsonpath::parser::model::FilterExpression::{And, Or}; -use crate::jsonpath::parser::model::{ +use crate::parser::model::FilterExpression::{And, Or}; +use crate::parser::model::{ FilterExpression, FilterSign, Function, JsonPath, JsonPathIndex, Operand, }; use dozer_types::json_types::JsonValue; use pest::error::Error; use pest::iterators::{Pair, Pairs}; use pest::Parser; +use pest_derive::Parser; #[derive(Parser)] -#[grammar = "jsonpath/parser/grammar/json_path.pest"] +#[grammar = "parser/grammar/json_path.pest"] pub struct JsonPathParser; /// the parsing function. diff --git a/dozer-sql/src/jsonpath/path/index.rs b/dozer-sql/jsonpath/src/path/index.rs similarity index 96% rename from dozer-sql/src/jsonpath/path/index.rs rename to dozer-sql/jsonpath/src/path/index.rs index 859466c32d..a27d386813 100644 --- a/dozer-sql/src/jsonpath/path/index.rs +++ b/dozer-sql/jsonpath/src/path/index.rs @@ -1,9 +1,9 @@ -use crate::jsonpath::parser::model::{FilterExpression, FilterSign, JsonPath}; -use crate::jsonpath::path::json::{any_of, eq, inside, less, regex, size, sub_set_of}; -use crate::jsonpath::path::top::ObjectField; -use crate::jsonpath::path::{json_path_instance, process_operand, Path, PathInstance}; -use crate::jsonpath::JsonPathValue; -use crate::jsonpath::JsonPathValue::{NoValue, Slice}; +use crate::parser::model::{FilterExpression, FilterSign, JsonPath}; +use crate::path::json::{any_of, eq, inside, less, regex, size, sub_set_of}; +use crate::path::top::ObjectField; +use crate::path::{json_path_instance, process_operand, Path, PathInstance}; +use crate::JsonPathValue; +use crate::JsonPathValue::{NoValue, Slice}; use dozer_types::json_types::JsonValue; use dozer_types::json_types::JsonValue::Array; diff --git a/dozer-sql/src/jsonpath/path/json.rs b/dozer-sql/jsonpath/src/path/json.rs similarity index 100% rename from dozer-sql/src/jsonpath/path/json.rs rename to dozer-sql/jsonpath/src/path/json.rs diff --git a/dozer-sql/src/jsonpath/path/mod.rs b/dozer-sql/jsonpath/src/path/mod.rs similarity index 92% rename from dozer-sql/src/jsonpath/path/mod.rs rename to dozer-sql/jsonpath/src/path/mod.rs index 18274bc358..4e2317197e 100644 --- a/dozer-sql/src/jsonpath/path/mod.rs +++ b/dozer-sql/jsonpath/src/path/mod.rs @@ -1,9 +1,9 @@ -use crate::jsonpath::parser::model::{Function, JsonPath, JsonPathIndex, Operand}; -use crate::jsonpath::path::index::{ArrayIndex, ArraySlice, Current, FilterPath, UnionIndex}; -use crate::jsonpath::path::top::{ +use crate::parser::model::{Function, JsonPath, JsonPathIndex, Operand}; +use crate::path::index::{ArrayIndex, ArraySlice, Current, FilterPath, UnionIndex}; +use crate::path::top::{ Chain, DescentObject, DescentWildcard, FnPath, IdentityPath, ObjectField, RootPointer, Wildcard, }; -use crate::jsonpath::JsonPathValue; +use crate::JsonPathValue; use dozer_types::json_types::JsonValue; /// The module is in charge of processing [[JsonPathIndex]] elements diff --git a/dozer-sql/src/jsonpath/path/top.rs b/dozer-sql/jsonpath/src/path/top.rs similarity index 97% rename from dozer-sql/src/jsonpath/path/top.rs rename to dozer-sql/jsonpath/src/path/top.rs index 65d2dc6714..d7d7a27648 100644 --- a/dozer-sql/src/jsonpath/path/top.rs +++ b/dozer-sql/jsonpath/src/path/top.rs @@ -1,6 +1,6 @@ -use crate::jsonpath::parser::model::*; -use crate::jsonpath::path::JsonPathValue::{NewValue, NoValue, Slice}; -use crate::jsonpath::path::{json_path_instance, JsonPathValue, Path, PathInstance}; +use crate::parser::model::*; +use crate::path::JsonPathValue::{NewValue, NoValue, Slice}; +use crate::path::{json_path_instance, JsonPathValue, Path, PathInstance}; use dozer_types::json_types::JsonValue::{Array, Object}; use dozer_types::json_types::{serde_json_to_json_value, JsonValue}; use dozer_types::serde_json::json; diff --git a/dozer-sql/src/lib.rs b/dozer-sql/src/lib.rs index 88de44f389..a4f10a8581 100644 --- a/dozer-sql/src/lib.rs +++ b/dozer-sql/src/lib.rs @@ -1,11 +1,4 @@ -extern crate core; - // Re-export sqlparser pub use sqlparser; -pub mod jsonpath; pub mod pipeline; - -#[macro_use] -extern crate pest_derive; -extern crate pest; diff --git a/dozer-sql/src/pipeline/expression/json_functions.rs b/dozer-sql/src/pipeline/expression/json_functions.rs index 8c36f1c806..4538cec3d0 100644 --- a/dozer-sql/src/pipeline/expression/json_functions.rs +++ b/dozer-sql/src/pipeline/expression/json_functions.rs @@ -4,10 +4,10 @@ use crate::pipeline::errors::PipelineError::{ }; use crate::pipeline::expression::execution::Expression; -use crate::jsonpath::{JsonPathFinder, JsonPathInst}; use dozer_types::json_types::JsonValue; use dozer_types::types::Record; use dozer_types::types::{Field, Schema}; +use jsonpath::{JsonPathFinder, JsonPathInst}; use std::fmt::{Display, Formatter}; use std::str::FromStr;