Currently, if you want to search a key using JSON UDFs you have
to specify each its part as a separate argument to the function:
JSON_CONTAINS_KEY(doc, 'root', 'child', 'child of child',
'child of child of child', etc.....). This way of working
with parameters is easy for developer, less error-prone, but can
be not very beautiful.
I was suggested by some of users to change it to
'/parent/child/child-of-child/...' or to
'parent:child:child-of-child:...' There are, probably, can
be other suggestions. What do you like the best? How do you feel
about current style with separate argument for each key element?
Should we change or extend this syntax?
Two weeks ago I announced new maintenance release of JSON UDFs:
0.2.1. It not only contains bug fixes, how you can expect from a
maintenance release, but also contains improvements in build and
test scripts.
First improvement is the easier way to build JSON UDFs on
Windows. In the first version building on Windows was a pane: you
had to build PCRE library, copy four files to directories where
Visual Studio can find them and only then build JSON functions
themselves. Now you can build this way too, but only if you
really wish.
By default cmake will create appropriate makefiles for bundled
PCRE sources and for JSON functions. Only command you need to
prepare sources is:
"C:\Program Files (x86)\CMake 2.8\bin\cmake.exe" -G "Visual
Studio 11 Win64" .
-DMYSQL_DIR="/path/to/mysql/installation"
And then you can build functions:
devenv my_json_udf.sln …
After I released maintenance release of JSON UDFs last week it
is time to think about which features I should implement in
upcoming major version.
Many users asked me about the possibility to explicitly specify
if they want to append last element to a JSON array. This feature
can be made for two functions: json_append and
json_set.
I have four ideas of how to implement this. All have pros and
contras.
-
- Create new function called json_append_last which will
work exactly like json_append, but it will add the element
to the end of array. I.e., for JSON document {"colors":
["red", "green", "blue"]} json_append_last(doc, 'colors',
'orange') returns {"colors": ["red", "green", "blue",
"orange"]}
- …
Today new version of JSON UDF functions: 0.2.1 was released. This
is maintenance release which added no new functionality and only
contains bug fixes. However, it also includes improvements for
build ans test procedures. As usual, you can download source and
binary packages at MySQL Labs. Binary packages were build for MySQL
server 5.6.14. If you want to use other version of the server,
you need to recompile functions.
What was changed? Let me quote the ChangeLog.
Functionality added or changed:
Added cmake option WITH_PCRE which alolows to specify if existent
or bundled version of PCRE should be used. Bundled is
default on Windows. To compile with bundled version, run: "cmake
. -DMYSQL_DIR=/path/to/mysql/dir -DWITH_PCRE=bundled", to turn
bundled version off on Windows, run: "cmake . …
When I designed first version of JSON UDFs which was reviewed
only internally, I let all functions to validate input and output
JSON. But my colleagues told me to remove this functionality,
because it makes such functions, as json_search,
json_replace or json_contains_key deadly slow if
they find the occurrence in the beginning of the long document.
And first published version of JSON UDFs: 0.2.0 has not this
functionality. What we expected is that users would call
json_valid if they want to be 100% sure the document is
valid.
But I was not surprised that some users expect JSON functions to
work as it was in the first version: validate first, then
process. For example, Ammon Sutherland writes: "json_set - according to the
documentation a sort of 'INSERT... ON DUPLICATE KEY UPDATE'
function which …
JSON UDFs got own category at MySQL Bugs Database: "Server: JSON UDF"
Use this category to post new bug reports and vote for existent.
Some time ago I wrote a blog post describing a way I use to
verify MySQL Server bugs. But my job consists
not only of bugs which can be verified just by passing SQL
queries to the server.
One of such examples is UDF bugs.
MySQL User Reference Manual is good source of
information for those who want to write UDF functions, as well as
book "MySQL 5.1 Plugin Development" by Sergei
Golubchik and Andrew Hutchings. But while the book describes in
details how to write UDFs it was created in time when current
MySQL version was 5.1 and does not contain information about how
to build UDF nowadays. User Reference Manual has this
information, …
Even in times of a growing market of specialized NoSQL databases, the relevance of traditional RDBMS doesn't decline. Especially when it comes to the calculation of aggregates based on complex data sets that can not be processed as a batch like Map&Reduce. MySQL is already bringing in a handful of aggregate functions that can be useful for a statistical analysis. The best known of this type are certainly:
Even in times of a growing market of specialized NoSQL databases, the relevance of traditional RDBMS doesn't decline. Especially when it comes to the calculation of aggregates based on complex data sets that can not be processed as a batch like Map&Reduce. MySQL is already bringing in a handful of aggregate functions that can be useful for a statistical analysis. The best known of this type are certainly:
Since I use MySQL for the statistical analysis on a project, I wanted to optimize the database queries and learned a lot about stuff like number theory, set theory and partial sums. I took my MySQL UDF, I've published two years ago, for this purpose and added new functions for a deeper statistical analysis. The project is around for a while, so it's time to share things with the public to start a discussion of how things could be further optimized. The source and a small documentation can be found on Github: