Обсуждение: pgsql: Partial implementation of SQL/JSON path language

Поиск
Список
Период
Сортировка

pgsql: Partial implementation of SQL/JSON path language

От
Alexander Korotkov
Дата:
Partial implementation of SQL/JSON path language

SQL 2016 standards among other things contains set of SQL/JSON features for
JSON processing inside of relational database.  The core of SQL/JSON is JSON
path language, allowing access parts of JSON documents and make computations
over them.  This commit implements partial support JSON path language as
separate datatype called "jsonpath".  The implementation is partial because
it's lacking datetime support and suppression of numeric errors.  Missing
features will be added later by separate commits.

Support of SQL/JSON features requires implementation of separate nodes, and it
will be considered in subsequent patches.  This commit includes following
set of plain functions, allowing to execute jsonpath over jsonb values:

 * jsonb_path_exists(jsonb, jsonpath[, jsonb, bool]),
 * jsonb_path_match(jsonb, jsonpath[, jsonb, bool]),
 * jsonb_path_query(jsonb, jsonpath[, jsonb, bool]),
 * jsonb_path_query_array(jsonb, jsonpath[, jsonb, bool]).
 * jsonb_path_query_first(jsonb, jsonpath[, jsonb, bool]).

This commit also implements "jsonb @? jsonpath" and "jsonb @@ jsonpath", which
are wrappers over jsonpath_exists(jsonb, jsonpath) and jsonpath_predicate(jsonb,
jsonpath) correspondingly.  These operators will have an index support
(implemented in subsequent patches).

Catversion bumped, to add new functions and operators.

Code was written by Nikita Glukhov and Teodor Sigaev, revised by me.
Documentation was written by Oleg Bartunov and Liudmila Mantrova.  The work
was inspired by Oleg Bartunov.

Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Author: Nikita Glukhov, Teodor Sigaev, Alexander Korotkov, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Tomas Vondra, Andrew Dunstan, Pavel Stehule, Alexander Korotkov

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/72b6460336e86ad5cafd3426af6013c7d8457367

Modified Files
--------------
doc/src/sgml/biblio.sgml                     |   11 +
doc/src/sgml/func.sgml                       |  768 ++++++++-
doc/src/sgml/json.sgml                       |  237 ++-
src/backend/Makefile                         |   11 +-
src/backend/catalog/system_views.sql         |   40 +
src/backend/utils/adt/.gitignore             |    3 +
src/backend/utils/adt/Makefile               |   19 +-
src/backend/utils/adt/jsonb.c                |   91 +-
src/backend/utils/adt/jsonb_util.c           |    8 +
src/backend/utils/adt/jsonpath.c             | 1053 ++++++++++++
src/backend/utils/adt/jsonpath_exec.c        | 2292 ++++++++++++++++++++++++++
src/backend/utils/adt/jsonpath_gram.y        |  480 ++++++
src/backend/utils/adt/jsonpath_scan.l        |  638 +++++++
src/backend/utils/adt/regexp.c               |    4 +-
src/backend/utils/errcodes.txt               |   15 +
src/include/catalog/catversion.h             |    2 +-
src/include/catalog/pg_operator.dat          |    8 +
src/include/catalog/pg_proc.dat              |   39 +
src/include/catalog/pg_type.dat              |    5 +
src/include/regex/regex.h                    |    8 +
src/include/utils/.gitignore                 |    1 +
src/include/utils/jsonb.h                    |    4 +
src/include/utils/jsonpath.h                 |  245 +++
src/include/utils/jsonpath_scanner.h         |   32 +
src/test/regress/expected/jsonb_jsonpath.out | 1756 ++++++++++++++++++++
src/test/regress/expected/jsonpath.out       |  806 +++++++++
src/test/regress/parallel_schedule           |    7 +-
src/test/regress/serial_schedule             |    2 +
src/test/regress/sql/jsonb_jsonpath.sql      |  369 +++++
src/test/regress/sql/jsonpath.sql            |  147 ++
src/tools/msvc/Mkvcbuild.pm                  |    2 +
src/tools/msvc/Solution.pm                   |   18 +
src/tools/pgindent/typedefs.list             |   13 +
33 files changed, 9079 insertions(+), 55 deletions(-)


Re: pgsql: Partial implementation of SQL/JSON path language

От
Tom Lane
Дата:
Alexander Korotkov <akorotkov@postgresql.org> writes:
> Partial implementation of SQL/JSON path language

Please fix the compiler warnings this produces.

jsonpath_exec.c: In function 'executePredicate':
jsonpath_exec.c:1458: warning: 'rseqit.next' may be used uninitialized in this function
jsonpath_exec.c:1458: warning: 'rseqit.value' may be used uninitialized in this function

            regards, tom lane


Re: pgsql: Partial implementation of SQL/JSON path language

От
Alexander Korotkov
Дата:
сб, 16 мар. 2019 г., 18:50 Tom Lane <tgl@sss.pgh.pa.us>:
Alexander Korotkov <akorotkov@postgresql.org> writes:
> Partial implementation of SQL/JSON path language

Please fix the compiler warnings this produces.

jsonpath_exec.c: In function 'executePredicate':
jsonpath_exec.c:1458: warning: 'rseqit.next' may be used uninitialized in this function
jsonpath_exec.c:1458: warning: 'rseqit.value' may be used uninitialized in this function 

Thank you for noticing.  Will fix this later today.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company