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(frontend): Bind concat_ws expression #2589

Merged
merged 13 commits into from
May 17, 2022
Merged

Conversation

kwannoel
Copy link
Contributor

@kwannoel kwannoel commented May 17, 2022

What's changed and what's your intention?

Implement support for concat_ws on frontend.

  • Summarize your change (mandatory)

    Bind concat_ws on frontend. Call cast over function arguments to ensure they are varchar.

  • How does this PR work? Need a brief introduction for the changed logic (optional)

  • Describe clearly one logical change and avoid lazy messages (optional)

  • Describe any limitations of the current code (optional)

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests

Refer to a related PR or issue link (optional)

Part of #2405

@kwannoel kwannoel changed the title Cast concat_ws inputs to varchar feat(frontend): Bind concat_ws expression May 17, 2022
@kwannoel kwannoel force-pushed the noel/concat_ws_frontend branch 2 times, most recently from d3c51d9 to 8a21d2d Compare May 17, 2022 05:13
@codecov
Copy link

codecov bot commented May 17, 2022

Codecov Report

Merging #2589 (e249ee6) into main (2868681) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2589      +/-   ##
==========================================
+ Coverage   72.39%   72.40%   +0.01%     
==========================================
  Files         675      678       +3     
  Lines       87931    88016      +85     
==========================================
+ Hits        63660    63732      +72     
- Misses      24271    24284      +13     
Flag Coverage Δ
rust 72.40% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
src/frontend/src/binder/expr/function.rs 91.45% <100.00%> (+0.07%) ⬆️
src/frontend/src/expr/function_call.rs 99.36% <100.00%> (+0.07%) ⬆️
src/bench/ss_bench/utils/my_stats.rs 0.00% <0.00%> (-72.42%) ⬇️
src/storage/src/monitor/state_store_metrics.rs 98.17% <0.00%> (-1.34%) ⬇️
src/storage/src/hummock/sstable_store.rs 65.11% <0.00%> (-0.81%) ⬇️
src/bench/ss_bench/main.rs 0.68% <0.00%> (-0.02%) ⬇️
src/compute/src/server.rs 0.00% <0.00%> (ø)
src/storage/compactor/src/server.rs 0.00% <0.00%> (ø)
src/ctl/src/common/hummock_service.rs 0.00% <0.00%> (ø)
src/bench/ss_bench/utils/display_stats.rs 0.00% <0.00%> (ø)
... and 11 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@kwannoel kwannoel force-pushed the noel/concat_ws_frontend branch from 0ff7a10 to 63206cd Compare May 17, 2022 07:25
@kwannoel kwannoel mentioned this pull request May 17, 2022
3 tasks
@kwannoel kwannoel force-pushed the noel/concat_ws_frontend branch 2 times, most recently from fe9b389 to 7640d05 Compare May 17, 2022 07:48
@kwannoel kwannoel marked this pull request as ready for review May 17, 2022 08:04
@kwannoel kwannoel requested a review from xiangjinwu May 17, 2022 08:05
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.

Mostly lgtm. Just some small adjustments:

src/frontend/src/expr/function_call.rs Outdated Show resolved Hide resolved
src/frontend/src/binder/expr/function.rs Outdated Show resolved Hide resolved
Comment on lines 93 to 107
query T
select concat_ws(true, 1, 1.01, 'A', NULL);
----
1true1.01trueA

statement ok
create table t (v1 bool, v2 smallint, v3 int, v4 decimal, v5 real, v6 double, v7 varchar, v8 varchar);

statement ok
insert into t values (true, 1, 2, 3.01, 4, 5.01, 'abc', NULL);

query T
select concat_ws(v1, v2, v3, v4, v5, v6, v7, v8) from t;
----
1true2true3.01true4true5.01trueabc
Copy link
Contributor

@xiangjinwu xiangjinwu May 17, 2022

Choose a reason for hiding this comment

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

These 2 cases are invalid in PostgreSQL. The 0-th arg is required to be string without casting (my bad, implicit casting is always allowed).

@xiangjinwu
Copy link
Contributor

Also add a query in src/frontend/test_runner/tests/testdata/expr.yaml to improve test coverage.

@kwannoel kwannoel force-pushed the noel/concat_ws_frontend branch from 7640d05 to 1e4cdc3 Compare May 17, 2022 10:26
Comment on lines 126 to 138
if inputs[0].return_type() != DataType::Varchar {
return Err(ErrorCode::BindError(
"ConcatWs function must have text as first argument".into(),
)
.into());
}

// subsequent inputs can be any type, they are cast into varchars with
// explicit_cast.
inputs = inputs
.into_iter()
.map(|input| input.cast_explicit(DataType::Varchar))
.collect::<Result<Vec<_>>>()?;
Copy link
Contributor

@xiangjinwu xiangjinwu May 17, 2022

Choose a reason for hiding this comment

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

                inputs = inputs
                    .into_iter()
                    .enumerate()
                    .map(|(i, input)| match i {
                        // 0-th arg must be string
                        0 => input.cast_implicit(DataType::Varchar),
                        // subsequent can be any type
                        _ => input.cast_explicit(DataType::Varchar),
                    })
                    .collect::<Result<Vec<_>>>()?;

This would also allow the e2e test cases that use literal null as separator.

(Basically, when pg doc says it accepts type "T", it always means accepting any types implicitly castable to "T".)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I was wondering how to patch that.

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.

rest lgtm

@kwannoel kwannoel merged commit 48e898e into main May 17, 2022
@kwannoel kwannoel deleted the noel/concat_ws_frontend branch May 17, 2022 14:25
@xiangjinwu xiangjinwu added the user-facing-changes Contains changes that are visible to users label May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants