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

expression: add built-in function json_array_insert #11076

Merged
merged 6 commits into from
Jul 8, 2019

Conversation

foreyes
Copy link
Contributor

@foreyes foreyes commented Jul 4, 2019

What problem does this PR solve?

Add built-in function json_array_insert for #7546

What is changed and how it works?

Arccording to mysql decuments: https://dev.mysql.com/doc/refman/5.7/en/json-modification-functions.html#function_json-array-insert

mysql> SET @j = '["a", {"b": [1, 2]}, [3, 4]]';
mysql> SELECT JSON_ARRAY_INSERT(@j, '$[1]', 'x');
+------------------------------------+
| JSON_ARRAY_INSERT(@j, '$[1]', 'x') |
+------------------------------------+
| ["a", "x", {"b": [1, 2]}, [3, 4]]  |
+------------------------------------+
mysql> SELECT JSON_ARRAY_INSERT(@j, '$[100]', 'x');
+--------------------------------------+
| JSON_ARRAY_INSERT(@j, '$[100]', 'x') |
+--------------------------------------+
| ["a", {"b": [1, 2]}, [3, 4], "x"]    |
+--------------------------------------+
mysql> SELECT JSON_ARRAY_INSERT(@j, '$[1].b[0]', 'x');
+-----------------------------------------+
| JSON_ARRAY_INSERT(@j, '$[1].b[0]', 'x') |
+-----------------------------------------+
| ["a", {"b": ["x", 1, 2]}, [3, 4]]       |
+-----------------------------------------+
mysql> SELECT JSON_ARRAY_INSERT(@j, '$[2][1]', 'y');
+---------------------------------------+
| JSON_ARRAY_INSERT(@j, '$[2][1]', 'y') |
+---------------------------------------+
| ["a", {"b": [1, 2]}, [3, "y", 4]]     |
+---------------------------------------+
mysql> SELECT JSON_ARRAY_INSERT(@j, '$[0]', 'x', '$[2][1]', 'y');
+----------------------------------------------------+
| JSON_ARRAY_INSERT(@j, '$[0]', 'x', '$[2][1]', 'y') |
+----------------------------------------------------+
| ["x", "a", {"b": [1, 2]}, [3, 4]]                  |
+----------------------------------------------------+

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
  • Add exported method BinaryJSON#ArrayInsert()

Side effects

@codecov
Copy link

codecov bot commented Jul 4, 2019

Codecov Report

Merging #11076 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11076   +/-   ##
===========================================
  Coverage   81.4543%   81.4543%           
===========================================
  Files           420        420           
  Lines         90528      90528           
===========================================
  Hits          73739      73739           
  Misses        11554      11554           
  Partials       5235       5235

@eurekaka eurekaka changed the title add json_array_insert expression: add built-in function json_array_insert Jul 4, 2019
@eurekaka eurekaka added component/expression type/enhancement The issue or PR belongs to an enhancement. labels Jul 4, 2019
@eurekaka eurekaka self-requested a review July 4, 2019 08:23
@winoros
Copy link
Member

winoros commented Jul 4, 2019

@foreyes
Please fill the PR description
And if it's still WIP. You can add a WIP label too~

@foreyes foreyes removed the status/WIP label Jul 5, 2019
@foreyes foreyes marked this pull request as ready for review July 5, 2019 03:05
@foreyes foreyes requested a review from winoros July 5, 2019 05:15
@foreyes foreyes requested a review from lysu July 5, 2019 08:01
@foreyes foreyes requested review from alivxxx and removed request for lysu July 5, 2019 08:06
Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

@alivxxx alivxxx added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 5, 2019
Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 8, 2019
@eurekaka
Copy link
Contributor

eurekaka commented Jul 8, 2019

/run-all-tests

@eurekaka eurekaka merged commit d47f168 into pingcap:master Jul 8, 2019
@foreyes foreyes deleted the myfeature branch July 15, 2019 05:04
@foreyes foreyes restored the myfeature branch July 15, 2019 05:04
@foreyes foreyes deleted the myfeature branch July 17, 2019 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants