Skip to content

Commit

Permalink
feat(expr): add json path functions (#13568) (#13798)
Browse files Browse the repository at this point in the history
Signed-off-by: Runji Wang <[email protected]>
Co-authored-by: Runji Wang <[email protected]>
  • Loading branch information
github-actions[bot] and wangrunji0408 authored Dec 5, 2023
1 parent 3f72a88 commit 4205179
Show file tree
Hide file tree
Showing 17 changed files with 724 additions and 323 deletions.
18 changes: 16 additions & 2 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions proto/expr.proto
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ message ExprNode {
TO_JSONB = 617;
JSONB_BUILD_ARRAY = 618;
JSONB_BUILD_OBJECT = 619;
JSONB_PATH_EXISTS = 620;
JSONB_PATH_MATCH = 621;
JSONB_PATH_QUERY_ARRAY = 622;
JSONB_PATH_QUERY_FIRST = 623;

// Non-pure functions below (> 1000)
// ------------------------
Expand Down Expand Up @@ -295,6 +299,7 @@ message TableFunction {
JSONB_EACH = 12;
JSONB_EACH_TEXT = 13;
JSONB_OBJECT_KEYS = 14;
JSONB_PATH_QUERY = 15;
// User defined table function
UDTF = 100;
}
Expand Down
11 changes: 8 additions & 3 deletions src/common/src/types/jsonb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ impl<'a> JsonbRef<'a> {
buf
}

/// Returns a jsonb `null` value.
pub fn null() -> Self {
Self(ValueRef::Null)
}

/// Returns true if this is a jsonb `null`.
pub fn is_jsonb_null(&self) -> bool {
self.0.as_null().is_some()
self.0.is_null()
}

/// Returns true if this is a jsonb null, boolean, number or string.
Expand All @@ -250,12 +255,12 @@ impl<'a> JsonbRef<'a> {

/// Returns true if this is a jsonb array.
pub fn is_array(&self) -> bool {
matches!(self.0, ValueRef::Array(_))
self.0.is_array()
}

/// Returns true if this is a jsonb object.
pub fn is_object(&self) -> bool {
matches!(self.0, ValueRef::Object(_))
self.0.is_object()
}

/// Returns the type name of this jsonb.
Expand Down
1 change: 1 addition & 0 deletions src/expr/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha1 = "0.10"
sha2 = "0.10"
sql-json-path = { version = "0.1", features = ["jsonbb"] }
thiserror = "1"
tokio = { version = "0.2", package = "madsim-tokio", features = ["time"] }
tracing = "0.1"
Expand Down
Loading

0 comments on commit 4205179

Please sign in to comment.