Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26182

Create a function to check for JSON intersection

    XMLWordPrintable

Details

    Description

      Creating a function that checks for intersection between objects would be really helpful.

      For example, if we have the following 2 objects:

      {'a': '1', 'b': '1', 'c': '1', 'd': '1'} {'b': '1', 'd': '1'}

      And we would like to find/check for the intersection between them, we do not have a way to achieve that.

      This post (https://stackoverflow.com/questions/44687872/find-intersection-of-mysql-json-objects-or-arrays) on Stackoverflow.com can possibly explain what I mean.

      Final Implementation:

      The idea was to have simple functions that the user can combine to produce the exact result one wants. Having two object how do we know what the user desires - to get the intersection for same keys, or same key/value pairs.
      If objects have same key with an array as a value - does the user need the value of the first object, or the second or the intersection of these arrays? WE can't know for sure, and having small exact functions allows user to combine them to get what they need.

      Hence tweaked the implementation made by gsoc student a little and also added more json functions. So Now we have:

      • JSON_ARRAY_INTERSECT() : Find intersection between two jsons of array type,
      • JSON_OBJECT_FILTER_KEYS(): This will take two args. first will be an object and second will be array. It will output those key-value pairs from json object that are there in the array.
      • JSON_OBJECT_TO_ARRAY(Obj) : Converts key-value pairs in the outer most level to array.

      Idea: Alexey Botchkov
      Implementation: Ruixiang Tan and Rucha Deodhar

      Attachments

        Issue Links

          Activity

            People

              rucha174 Rucha Deodhar
              AbdullahXepro Abdullah
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.