Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(expr): support capturing context in expression #12747

Merged
merged 25 commits into from
Oct 17, 2023
Merged

Conversation

TennyZhuang
Copy link
Contributor

@TennyZhuang TennyZhuang commented Oct 10, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

#11522 #11752

Support context capture during expression evaluation.

And support casting to regclass with all valid inputs.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has totally checked 4258 files.

Valid Invalid Ignored Fixed
1889 1 2368 0
Click to see the invalid file list
  • src/expr/macro/src/context.rs

src/expr/macro/src/context.rs Show resolved Hide resolved
TennyZhuang and others added 10 commits October 11, 2023 02:04
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
@TennyZhuang TennyZhuang marked this pull request as ready for review October 11, 2023 13:28
Signed-off-by: TennyZhuang <zty0826@gmail.com>
@TennyZhuang TennyZhuang changed the title feat(expr): support captured context feat(expr): support capturing context in expression Oct 11, 2023
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Signed-off-by: TennyZhuang <zty0826@gmail.com>
Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

LGTM. Next, we can consider how to integrate context into the #[function] macro more gracefully. 🤔

Signed-off-by: TennyZhuang <zty0826@gmail.com>
@TennyZhuang
Copy link
Contributor Author

@xiangjinwu PTAL

Copy link
Contributor

@xiangjinwu xiangjinwu left a comment

Choose a reason for hiding this comment

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

LGTM. Btw we would need to update this to detect such functions for a better experience.

fn must_run_in_local_mode(batch_plan: PlanRef) -> bool {
SysTableVisitor::has_sys_table(batch_plan)
}

where
F: FnOnce(&#ty) -> R
{
LOCAL_KEY.try_with(f).map_err(|_| risingwave_expr::ContextUnavailable::new(stringify!(#name))).map_err(Into::into)
Copy link
Contributor

Choose a reason for hiding this comment

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

We may need the function name in error message as well:

dev=> set query_mode to distributed;
SET_VARIABLE
dev=> select ''::regclass;
ERROR:  QueryError: Expr error: Context DB_NAME not found

Or maybe it can be part of any ExprError?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be a part of any ExprError

@TennyZhuang
Copy link
Contributor Author

TennyZhuang commented Oct 13, 2023

https://buildkite.com/risingwavelabs/pull-request/builds/33335



failed to run `e2e_test/background_ddl/basic.slt`
--
  |  
  | Caused by:
  | query failed: db error: ERROR: QueryError: Catalog error: table or source not found: m1
  | [SQL] select count(*) from m1;
  | at e2e_test/background_ddl/basic.slt:41
  |  
  |  
  | Error: some test case failed:
  | [
  | "e2e_test/background_ddl/basic.slt",
  | ]


Unknown failure, seems unrelated to the PR.

@TennyZhuang
Copy link
Contributor Author

must_run_in_local_mode

I know how to modify it. Just merge the PR first to make the future work
parallelizable.

@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #12747 (8ac6bf6) into main (30f2baf) will decrease coverage by 0.01%.
Report is 1 commits behind head on main.
The diff coverage is 68.95%.

@@            Coverage Diff             @@
##             main   #12747      +/-   ##
==========================================
- Coverage   69.19%   69.19%   -0.01%     
==========================================
  Files        1489     1492       +3     
  Lines      245795   246004     +209     
==========================================
+ Hits       170088   170216     +128     
- Misses      75707    75788      +81     
Flag Coverage Δ
rust 69.19% <68.95%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/expr/impl/src/scalar/proctime.rs 94.11% <100.00%> (ø)
...rc/frontend/src/binder/relation/table_or_source.rs 79.25% <ø> (+0.05%) ⬆️
src/frontend/src/catalog/mod.rs 56.09% <ø> (ø)
src/frontend/src/expr/mod.rs 78.32% <ø> (ø)
src/frontend/src/expr/pure.rs 87.69% <100.00%> (ø)
src/frontend/src/handler/query.rs 59.93% <100.00%> (-0.77%) ⬇️
src/frontend/src/lib.rs 20.00% <ø> (ø)
src/frontend/src/scheduler/local.rs 32.59% <100.00%> (+2.71%) ⬆️
src/frontend/src/expr/function_impl/context.rs 83.33% <83.33%> (ø)
src/expr/macro/src/lib.rs 91.22% <90.00%> (-0.27%) ⬇️
... and 4 more

... and 3 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@TennyZhuang TennyZhuang added this pull request to the merge queue Oct 17, 2023
Merged via the queue into main with commit 7c37573 Oct 17, 2023
28 of 29 checks passed
@TennyZhuang TennyZhuang deleted the expr-context branch October 17, 2023 09:23
Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants