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(functions): add map_contains_key scalar function #15465

Merged
merged 5 commits into from
May 12, 2024

Conversation

hanxuanliang
Copy link
Contributor

@hanxuanliang hanxuanliang commented May 10, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label May 10, 2024
@hanxuanliang
Copy link
Contributor Author

@b41sh

When performing unit tests, I encountered a problem:

cargo test --package databend-common-functions --test it -- scalars::map::test_map --exact --show-output

error:

running 1 test
test scalars::map::test_map ... FAILED

successes:

successes:

failures:

---- scalars::map::test_map stdout ----
thread 'scalars::map::test_map' panicked at /Users/hanfox/.cargo/registry/src/rsproxy.cn-0dccff568467c15b/goldenfile-1.6.0/src/differs.rs:15:5:
assertion failed: `(left == right)`'
  left: `"ast            : map([], [])\nraw expr       : map(array(), array())\nchecked expr   : map<Array(Nothing), Array(Nothing)>(array<>(), array<>())\noptimized expr : {} :: Map(Nothing)\noutput type    : Map(..."` (truncated)
 right: `"ast            : map([], [])\nraw expr       : map(array(), array())\nchecked expr   : map<Array(Nothing), Array(Nothing)>(array<>(), array<>())\noptimized expr : {} :: Map(Nothing)\noutput type    : Map(..."` (truncated)

Differences (-left|+right):
 output type    : Boolean
 output domain  : {TRUE}
 output         : true

+

I have two areas of doubt:

  1. How should I interpret this error?
  2. How can I determine if my unit tests are written correctly?

Thank you for taking the time to assist me with this task.

@b41sh b41sh self-requested a review May 10, 2024 14:43
@b41sh
Copy link
Member

b41sh commented May 10, 2024

I have two areas of doubt:

  1. How should I interpret this error?
  2. How can I determine if my unit tests are written correctly?

Thank you for taking the time to assist me with this task.

Hi, @hanxuanliang thanks for your contribution. The unit test is failed because you missed some blank lines, just add those lines will pass the test.

Differences (-left|+right):
 output type    : Map(String, Map(String, String))
 output domain  : {[{"k1"..="k2"}], [{[{"nk1"..="nk3"}], [{"new_nv1"..="nv3"}]}]}
 output         : {'k1':{'nk1':'new_nv1'}, 'k2':{'nk3':'nv3'}}

+
 ast            : map_contains_key({'k1': 'v1', 'k2': 'v2'}, 'k1')
 raw expr       : map_contains_key(map(array('k1', 'k2'), array('v1', 'v2')), 'k1')
 checked expr   : map_contains_key<T0=String, T1=String><Map(T0, T1), String>(map<T0=String, T1=String><Array(T0), Array(T1)>(array<T0=String><T0, T0>("k1", "k2"), array<T0=String><T0, T0>("v1", "v2")), "k1")
 optimized expr : true
 output type    : Boolean
 output domain  : {TRUE}
 output         : true
+
+

you should also modify the function list file src/query/functions/tests/it/scalars/testdata/function_list.txt, add the new function in the function list.

Differences (-left|+right):
 0 map_cat(Map(Nothing), Map(Nothing)) :: Map(Nothing)
 1 map_cat(Map(Nothing) NULL, Map(Nothing) NULL) :: Map(Nothing) NULL
 2 map_cat(Map(T0, T1), Map(T0, T1)) :: Map(T0, T1)
 3 map_cat(Map(T0, T1) NULL, Map(T0, T1) NULL) :: Map(T0, T1) NULL
+0 map_contains_key(Map(Nothing), String) :: Boolean
+1 map_contains_key(Map(T0, T1), String) :: Boolean
+2 map_contains_key(Map(T0, T1) NULL, String NULL) :: Boolean NULL
 0 map_keys(Map(Nothing)) :: Array(Nothing)
 1 map_keys(Map(T0, T1)) :: Array(T0)
 2 map_keys(Map(T0, T1) NULL) :: Array(T0) NULL
 0 map_size(Map(Nothing)) :: UInt8

You can run make unit-test after development is complete, and if it doesn't report an error it means the changes were made correctly.

src/query/functions/src/scalars/map.rs Outdated Show resolved Hide resolved
src/query/functions/src/scalars/map.rs Outdated Show resolved Hide resolved
src/query/functions/tests/it/scalars/map.rs Outdated Show resolved Hide resolved
@b41sh
Copy link
Member

b41sh commented May 11, 2024

this PR is almost OK, please fix sql logic test reviews.

@b41sh b41sh marked this pull request as ready for review May 11, 2024 15:09
@hanxuanliang
Copy link
Contributor Author

But when I was running the SQL logic test locally, I encountered a problem:

first I need to start databend server: make run-debug. then an issue occurred while executing this command:

Databend Metasrv started
panicked at src/meta/client/src/lib.rs:47:28:
run `git fetch --tags` to solve this error,
    to learn more about this error, please visit https://crates.io/crates/semver: Error("unexpected character 'D' while parsing major version number")
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
             ...
Databend Query start failure, cause: MetaServiceError. Code: 2001, Text = meta-client dedicated runtime error: tokio::sync::oneshot::error::RecvError: channel closed while: when recv resp from MetaGrpcClient worker.

An error occurred when starting databend-query. I initially thought it was an issue with port 8000, but even after switching to port 8001, the same problem persisted.

@b41sh
Copy link
Member

b41sh commented May 11, 2024

But when I was running the SQL logic test locally, I encountered a problem:

first I need to start databend server: make run-debug. then an issue occurred while executing this command:

Databend Metasrv started
panicked at src/meta/client/src/lib.rs:47:28:
run `git fetch --tags` to solve this error,
    to learn more about this error, please visit https://crates.io/crates/semver: Error("unexpected character 'D' while parsing major version number")
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/8ace7ea1f7cbba7b4f031e66c54ca237a0d65de6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
             ...
Databend Query start failure, cause: MetaServiceError. Code: 2001, Text = meta-client dedicated runtime error: tokio::sync::oneshot::error::RecvError: channel closed while: when recv resp from MetaGrpcClient worker.

An error occurred when starting databend-query. I initially thought it was an issue with port 8000, but even after switching to port 8001, the same problem persisted.

databend use github tags to calculate the version, otherwise the meta and query version is incorrect, which will cause the startup failed.
please run the following command first and then rebuild the target

git fetch --tags https://github.com/datafuselabs/databend.git

Copy link
Member

@b41sh b41sh left a comment

Choose a reason for hiding this comment

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

LGTM @hanxuanliang Thanks for your contribution.

@b41sh b41sh added this pull request to the merge queue May 12, 2024
@BohuTANG BohuTANG removed this pull request from the merge queue due to a manual request May 12, 2024
@BohuTANG BohuTANG merged commit d2b3fd9 into datafuselabs:main May 12, 2024
72 checks passed
@hanxuanliang
Copy link
Contributor Author

@b41sh Thank you for your help, I can successfully complete the development.. At the same time, during the development, I feel that the develop process of scalar func is not very clear in the documentation. Is there also support to contribute?

@hanxuanliang hanxuanliang deleted the feat/15337_map_contains branch May 13, 2024 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants