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: support map lambda functions #16683

Merged

Conversation

Dragonliu2018
Copy link
Contributor

@Dragonliu2018 Dragonliu2018 commented Oct 24, 2024

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

Summary

support map lambda functions

  • map_filter
  • map_transform_keys
  • map_transform_values
  • json_map_filter
  • json_map_transform_keys
  • json_map_transform_values

for example:

MySQL [(none)]> select map_transform_keys({1:2,3:4}, (k, v) -> k + 1);
+------------------------------------------------+
| map_transform_keys({1:2,3:4}, (k, v) -> k + 1) |
+------------------------------------------------+
| {2:2,4:4}                                      |
+------------------------------------------------+
1 row in set (0.046 sec)

MySQL [(none)]> select map_transform_values({'a':'b','c':'d'}, (k, v) -> concat(k, v));
+-----------------------------------------------------------------+
| map_transform_values({'a':'b','c':'d'}, (k, v) -> concat(k, v)) |
+-----------------------------------------------------------------+
| {'a':'ab','c':'cd'}                                             |
+-----------------------------------------------------------------+
1 row in set (0.047 sec)

MySQL [(none)]> select map_filter({1:2,3:4}, (k, v) -> k = 1);
+----------------------------------------+
| map_filter({1:2,3:4}, (k, v) -> k = 1) |
+----------------------------------------+
| {1:2}                                  |
+----------------------------------------+
1 row in set (0.051 sec)

MySQL [(none)]> select json_map_transform_keys('{"data":"bend","time":"space"}'::variant, (k, v) -> concat(k, v));
+--------------------------------------------------------------------------------------------+
| json_map_transform_keys('{"data":"bend","time":"space"}'::VARIANT, (k, v) -> concat(k, v)) |
+--------------------------------------------------------------------------------------------+
| {"databend":"bend","timespace":"space"}                                                    |
+--------------------------------------------------------------------------------------------+
1 row in set (0.052 sec)

MySQL [(none)]> select json_map_transform_values('{"data":"bend","time":"space"}'::variant, (k, v) -> concat(k, v));
+----------------------------------------------------------------------------------------------+
| json_map_transform_values('{"data":"bend","time":"space"}'::VARIANT, (k, v) -> concat(k, v)) |
+----------------------------------------------------------------------------------------------+
| {"data":"databend","time":"timespace"}                                                       |
+----------------------------------------------------------------------------------------------+
1 row in set (0.044 sec)

MySQL [(none)]> select json_map_filter('{"data":"bend","time":"space"}'::variant, (k, v) -> k = 'data');
+----------------------------------------------------------------------------------+
| json_map_filter('{"data":"bend","time":"space"}'::VARIANT, (k, v) -> k = 'data') |
+----------------------------------------------------------------------------------+
| {"data":"bend"}                                                                  |
+----------------------------------------------------------------------------------+
1 row in set (0.038 sec)

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 Oct 24, 2024
@b41sh b41sh self-requested a review October 24, 2024 10:45
@Dragonliu2018 Dragonliu2018 marked this pull request as ready for review October 27, 2024 14:00
@sundy-li sundy-li added this pull request to the merge queue Oct 28, 2024
Merged via the queue into databendlabs:main with commit f6429ae Oct 28, 2024
78 checks passed
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.

Feature: Support map lambda functions
3 participants