Tuesday, October 7, 2014

MySQL JSON UDF (Installation)

MySQL JSON UDF is (UDF - User Defined Function ) SQL function which perform query on JSON data.

Why needed this
-------------------------
We have lots of records that is in JSON format.We can use MySQL for storing it.But to process (Read/Write/Manipulate/Parse) data we either needed to build some library in PHP;i.e. not going to perform well for large data(Personal Perception).

So in my search i come to know about this MySQL library(UDF) that provides same feature to process JSON data;i.e. going to be faster in respect to some library i.e. builded on PHP(Personal Perception)

Instatllation Step
--------------------------

(
This not includes compilation part.
Machine is x64 and MySQL version is 5.6.17
)

1)It can be downloaded from

http://labs.mysql.com/

(As warned in that page not fit for production.So use it on production on your own risk)

Or

wget 'http://downloads.mysql.com/snapshots/pb/mysql-json-udfs-0.3.2/mysql-json-udfs-0.3.2-labs-json-udfs-linux-glibc2.5-x86_64.tar.gz'


2)tar -xzf  mysql-json-udfs-0.3.2-labs-json-udfs-linux-glibc2.5-x86_64.tar.gz

3)It is better to read README file inside extracted directory

4)Copy so file to the plugin directory

cp libmy_json_udf.so /usr/lib/mysql/plugin/.

5)Login into mysql.Execute following query

        CREATE FUNCTION json_valid RETURNS integer SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_search RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_extract RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_replace RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_append RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_remove RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_set RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_merge RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_safe_merge RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_deep_merge RETURNS string SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_contains_key RETURNS integer SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_depth RETURNS INTEGER SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_count RETURNS INTEGER SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_version RETURNS STRING SONAME 'libmy_json_udf.so';
        CREATE FUNCTION json_test_parser RETURNS string SONAME 'libmy_json_udf.so';



6)Test it

>SELECT json_valid('{"a":1}') ;
+-----------------------+
| json_valid('{"a":1}') |
+-----------------------+
|                     1 |
+-----------------------+

No comments: