Skip to content

Commit

Permalink
feat(function): Support json_path_query using JSON path (#11142)
Browse files Browse the repository at this point in the history
* feat(function): Support `json_path_query` using JSON path

* fix tests

* fix tests

* fix
  • Loading branch information
b41sh authored Apr 21, 2023
1 parent 11e8fd9 commit ee1f9c9
Show file tree
Hide file tree
Showing 10 changed files with 945 additions and 312 deletions.
33 changes: 17 additions & 16 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ opendal = { version = "0.32", features = [
"services-redis",
"trust-dns",
] }
ordered-float = { version = "3.4.0", default-features = false }
jsonb = { version = "0.1.1" }
ordered-float = { version = "3.6.0", default-features = false }
jsonb = { version = "0.2.0" }

# openraft = { version = "0.8.2", features = ["compat-07"] }
# For debugging
Expand Down
13 changes: 12 additions & 1 deletion src/query/expression/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,9 +881,11 @@ impl<'a> Evaluator<'a> {
/// for each input row, along with the number of rows in each set.
pub fn run_srf(&self, expr: &Expr) -> Result<Vec<(Value<AnyType>, usize)>> {
if let Expr::FunctionCall {
span,
function,
args,
return_type,
generics,
..
} = expr
{
Expand All @@ -894,7 +896,16 @@ impl<'a> Evaluator<'a> {
.map(|expr| self.run(expr))
.collect::<Result<Vec<_>>>()?;
let cols_ref = args.iter().map(Value::as_ref).collect::<Vec<_>>();
let result = (eval)(&cols_ref, self.input_columns.num_rows());
let mut ctx = EvalContext {
generics,
num_rows: self.input_columns.num_rows(),
validity: None,
errors: None,
tz: self.func_ctx.tz,
func_ctx: self.func_ctx,
};
let result = (eval)(&cols_ref, &mut ctx);
ctx.render_error(*span, &args, &function.signature.name)?;
assert_eq!(result.len(), self.input_columns.num_rows());
return Ok(result);
}
Expand Down
7 changes: 5 additions & 2 deletions src/query/expression/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ pub enum FunctionEval {
SRF {
/// Given multiple rows, return multiple sets of results
/// for each input row, along with the number of rows in each set.
eval:
Box<dyn Fn(&[ValueRef<AnyType>], usize) -> Vec<(Value<AnyType>, usize)> + Send + Sync>,
eval: Box<
dyn Fn(&[ValueRef<AnyType>], &mut EvalContext) -> Vec<(Value<AnyType>, usize)>
+ Send
+ Sync,
>,
},
}

Expand Down
Loading

1 comment on commit ee1f9c9

@vercel
Copy link

@vercel vercel bot commented on ee1f9c9 Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

databend – ./

databend-git-main-databend.vercel.app
databend.vercel.app
databend-databend.vercel.app
databend.rs

Please sign in to comment.