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: cast json_extract as bool #18948

Merged
merged 10 commits into from
Aug 7, 2020
Merged

expression: cast json_extract as bool #18948

merged 10 commits into from
Aug 7, 2020

Conversation

Win-Man
Copy link
Contributor

@Win-Man Win-Man commented Aug 3, 2020

What problem does this PR solve?

Issue Number: close #12233

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
CREATE TABLE `testjson` ( `id` int(11) NOT NULL AUTO_INCREMENT, `j` json DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;

INSERT INTO testjson SET j='{"test":1}';

INSERT INTO testjson SET j='{"test":3}';

INSERT INTO testjson SET j='{"test":0}';

insert into testjson set j='{"test":"0"}';

insert into testjson set j='{"test":0.0}';

INSERT INTO testjson SET j='{"test":"a"}';

INSERT INTO testjson SET j='{"test":"aaabbb"}';

INSERT INTO testjson SET j='{"test":3.1415}';

INSERT INTO testjson SET j='{"test":-1}';

INSERT INTO testjson SET j='{"test":[]}';

INSERT INTO testjson SET j='{"test":[1,2]}';

INSERT INTO testjson SET j='{"test":["b","c"]}';

INSERT INTO testjson SET j='{"test":{"ke":"val"}}';

insert into testjson set j='{"test":"2015-07-27 09:43:47"}';

insert into testjson set j='{"test":"0000-00-00 00:00:00"}';

insert into testjson set j='{"test":"9778"}';

insert into testjson set j='{"test":"0778"}';

insert into testjson set j='{"test":"0000"}';
select * from testjson where json_extract(j,'$.test'); 

## mocktikv
mysql> select * from testjson where json_extract(j,'$.test');
+----+---------------------------------+
| id | j                               |
+----+---------------------------------+
|  1 | {"test": 1}                     |
|  2 | {"test": 3}                     |
|  4 | {"test": "0"}                   |
|  6 | {"test": "a"}                   |
|  7 | {"test": "aaabbb"}              |
|  8 | {"test": 3.1415}                |
|  9 | {"test": -1}                    |
| 10 | {"test": []}                    |
| 11 | {"test": [1, 2]}                |
| 12 | {"test": ["b", "c"]}            |
| 13 | {"test": {"ke": "val"}}         |
| 14 | {"test": "2015-07-27 09:43:47"} |
| 15 | {"test": "0000-00-00 00:00:00"} |
| 16 | {"test": "9778"}                |
| 17 | {"test": "0778"}                |
| 18 | {"test": "0000"}                |
+----+---------------------------------+
16 rows in set (0.01 sec)

mysql> desc select * from testjson where json_extract(j,'$.test');
+-------------------------+----------+-----------+----------------+---------------------------------------------+
| id                      | estRows  | task      | access object  | operator info                               |
+-------------------------+----------+-----------+----------------+---------------------------------------------+
| Selection_7             | 10000.00 | root      |                | json_extract(gangshen.testjson.j, "$.test") |
| └─TableReader_6         | 10000.00 | root      |                | data:TableFullScan_5                        |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:testjson | keep order:false, stats:pseudo              |
+-------------------------+----------+-----------+----------------+---------------------------------------------+
3 rows in set (0.01 sec)

insert into mysql.expr_pushdown_blacklist values('json_extract','tikv','');
admin reload expr_pushdown_blacklist;

mysql> select * from testjson where json_extract(j,'$.test');
+----+---------------------------------+
| id | j                               |
+----+---------------------------------+
|  1 | {"test": 1}                     |
|  2 | {"test": 3}                     |
|  4 | {"test": "0"}                   |
|  6 | {"test": "a"}                   |
|  7 | {"test": "aaabbb"}              |
|  8 | {"test": 3.1415}                |
|  9 | {"test": -1}                    |
| 10 | {"test": []}                    |
| 11 | {"test": [1, 2]}                |
| 12 | {"test": ["b", "c"]}            |
| 13 | {"test": {"ke": "val"}}         |
| 14 | {"test": "2015-07-27 09:43:47"} |
| 15 | {"test": "0000-00-00 00:00:00"} |
| 16 | {"test": "9778"}                |
| 17 | {"test": "0778"}                |
| 18 | {"test": "0000"}                |
+----+---------------------------------+
16 rows in set (0.00 sec)

mysql> desc select * from testjson where json_extract(j,'$.test');
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| id                      | estRows | task      | access object  | operator info                               |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| TableReader_7           | 14.40   | root      |                | data:Selection_6                            |
| └─Selection_6           | 14.40   | cop[tikv] |                | json_extract(gangshen.testjson.j, "$.test") |
|   └─TableFullScan_5     | 18.00   | cop[tikv] | table:testjson | keep order:false, stats:pseudo              |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
3 rows in set (0.00 sec)


## tikv
mysql>  select * from testjson where json_extract(j,'$.test');
+----+---------------------------------+
| id | j                               |
+----+---------------------------------+
|  1 | {"test": 1}                     |
|  2 | {"test": 3}                     |
|  4 | {"test": "0"}                   |
|  6 | {"test": "a"}                   |
|  7 | {"test": "aaabbb"}              |
|  8 | {"test": 3.1415}                |
|  9 | {"test": -1}                    |
| 10 | {"test": []}                    |
| 11 | {"test": [1, 2]}                |
| 12 | {"test": ["b", "c"]}            |
| 13 | {"test": {"ke": "val"}}         |
| 14 | {"test": "2015-07-27 09:43:47"} |
| 15 | {"test": "0000-00-00 00:00:00"} |
| 16 | {"test": "9778"}                |
| 17 | {"test": "0778"}                |
| 18 | {"test": "0000"}                |
+----+---------------------------------+
16 rows in set (0.07 sec)

mysql> desc  select * from testjson where json_extract(j,'$.test');
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| id                      | estRows | task      | access object  | operator info                               |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| Selection_7             | 18.00   | root      |                | json_extract(gangshen.testjson.j, "$.test") |
| └─TableReader_6         | 18.00   | root      |                | data:TableFullScan_5                        |
|   └─TableFullScan_5     | 18.00   | cop[tikv] | table:testjson | keep order:false, stats:pseudo              |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
3 rows in set (0.00 sec)

insert into mysql.expr_pushdown_blacklist values('json_extract','tikv','');
admin reload expr_pushdown_blacklist;

mysql>  select * from testjson where json_extract(j,'$.test');
Empty set (0.09 sec)

mysql> desc  select * from testjson where json_extract(j,'$.test');
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| id                      | estRows | task      | access object  | operator info                               |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
| TableReader_7           | 14.40   | root      |                | data:Selection_6                            |
| └─Selection_6           | 14.40   | cop[tikv] |                | json_extract(gangshen.testjson.j, "$.test") |
|   └─TableFullScan_5     | 18.00   | cop[tikv] | table:testjson | keep order:false, stats:pseudo              |
+-------------------------+---------+-----------+----------------+---------------------------------------------+
3 rows in set (0.00 sec)

Side effects

  • Performance regression
    • Consumes more CPU
    • Consumes more MEM
  • Breaking backward compatibility

Release note

@Win-Man Win-Man requested a review from a team as a code owner August 3, 2020 09:36
@Win-Man Win-Man requested review from SunRunAway and removed request for a team August 3, 2020 09:36
@CLAassistant
Copy link

CLAassistant commented Aug 3, 2020

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Aug 3, 2020

Codecov Report

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

@@             Coverage Diff             @@
##             master     #18948   +/-   ##
===========================================
  Coverage   79.4013%   79.4013%           
===========================================
  Files           546        546           
  Lines        148762     148762           
===========================================
  Hits         118119     118119           
  Misses        21173      21173           
  Partials       9470       9470           

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

You should add some test cases into code.

util/chunk/column.go Outdated Show resolved Hide resolved
types/json/binary.go Show resolved Hide resolved
@Win-Man
Copy link
Contributor Author

Win-Man commented Aug 4, 2020

@SunRunAway PTAL

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

Would you like to add these following cases?

insert into testjson set j='""';
insert into testjson set j='null';
insert into testjson set j='0';

select * from testjson where j;

@Win-Man
Copy link
Contributor Author

Win-Man commented Aug 5, 2020

Would you like to add these following cases?

insert into testjson set j='""';
insert into testjson set j='null';
insert into testjson set j='0';

select * from testjson where j;

I've added some test cases.

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Aug 7, 2020
@SunRunAway SunRunAway requested a review from lzmhhh123 August 7, 2020 03:34
Copy link
Contributor

@lzmhhh123 lzmhhh123 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Aug 7, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 7, 2020
@lzmhhh123
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 7, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit 2b05ffd into pingcap:master Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON_EXTRACT fails to cast as bool
5 participants