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: fix the arg verification for json functions. #54145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

Issue Number: close #54029

Problem Summary:

For some json functions, the arg verification is not implemented correctly:

  1. For json_type, it didn't verify the type of args.
  2. For many other json functions, they didn't verify the charset of the args.

What changed and how does it work?

Add a unified function to verify the args of json functions.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Release note

Fix the issue that `json_type` can accept non-JSON arguments.
Fix the issue that some json functions accept binary string arguments.

Copy link

ti-chi-bot bot commented Jun 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zanmato1984 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 20, 2024
Copy link

ti-chi-bot bot commented Jun 20, 2024

@YangKeao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/mysql-test e74bca6 link true /test mysql-test
idc-jenkins-ci-tidb/unit-test e74bca6 link true /test unit-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Copy link

tiprow bot commented Jun 20, 2024

@YangKeao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow e74bca6 link true /test fast_test_tiprow
tidb_parser_test e74bca6 link true /test tidb_parser_test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Copy link

codecov bot commented Jun 20, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 56.0615%. Comparing base (6ad9cac) to head (e74bca6).
Report is 1 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54145         +/-   ##
=================================================
- Coverage   72.8813%   56.0615%   -16.8198%     
=================================================
  Files          1519       1639        +120     
  Lines        434852     605436     +170584     
=================================================
+ Hits         316926     339417      +22491     
- Misses        98376     242844     +144468     
- Partials      19550      23175       +3625     
Flag Coverage Δ
integration 37.0706% <93.7500%> (?)

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

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.7543% <ø> (+6.5987%) ⬆️

@YangKeao
Copy link
Member Author

/hold

Also consider #54044 (comment). Maybe it's not good to verify args type/charset in getFunction, because it'll be called in PREPARE stage.

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 20, 2024
@@ -727,7 +727,7 @@ Error 3146 (22032): Invalid data type for JSON data in argument 1 to function js
SELECT JSON_OVERLAPS('{}', 123);
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function json_overlaps; a JSON string or JSON type is required.
SELECT 'abc' MEMBER OF(123);
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function member of; a JSON string or JSON type is required.
Error 3146 (22032): Invalid data type for JSON data in argument 2 to function json_memberof; a JSON string or JSON type is required.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this error need to be fixed.

MySQL v8.4.0:

mysql-8.4.0> SELECT 'abc' MEMBER OF (123);
ERROR 3146 (22032): Invalid data type for JSON data in argument 2 to function member of; a JSON string or JSON type is required.

This is a weird function syntax wise...

return ErrInvalidTypeForJSON.GenWithStackByArgs(2, "member of")
}
return nil
return verifyJSONArgsType(ctx, c.funcName, true, args, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return verifyJSONArgsType(ctx, c.funcName, true, args, 1)
return verifyJSONArgsType(ctx, "member of", true, args, 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using JSON_TYPE on non-JSON values should return an error
2 participants