Re: Tackling JsonPath support - Mailing list pgsql-hackers

From Nico Williams
Subject Re: Tackling JsonPath support
Date
Msg-id 20161128192343.GD11117@localhost
Whole thread Raw
In response to Re: Tackling JsonPath support  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Tackling JsonPath support
List pgsql-hackers
On Mon, Nov 28, 2016 at 05:56:41PM +0100, Pavel Stehule wrote:
> Dne 28. 11. 2016 17:26 napsal uživatel "David Fetter" <david@fetter.org>:
> > There's another option we should also consider: jq
> > <https://stedolan.github.io/jq/>.  It's available under a
> > PostgreSQL-compatible license, and has had a LOT of work put into
> > correctness and performance.
>
> we can use it for inspiration. but the syntax of this tool is little bit
> too complex and too original against Json path ... jsonpath is relative
> simple implementation of xpath to json
>
> we have one proprietary syntax already, two is maybe too much :-)

jq is hardly proprietary :)

JSON Path is not expressive enough (last I looked) and can be mapped
onto jq if need be anyways.

libjq has a number of desirable features, mostly its immutable/COW data
structures.  In libjq data structures are only mutated when there's
only one reference to them, but libjq's jv API is built around
immutability, so jv values are always notionally immutable.  For
example, one writes:
 jv a = jv_array();
 a = jv_array_append(a, jv_true()); // `a' is notionally new, but since                                    // it had
onlyone reference, its                                    // memory is reused 

and similarly for objects.  One could instead write:
 jv a = jv_array_append(jv_array(), jv_true());
or
 jv a = JV_ARRAY(jv_true());

One of the nice things about libjv is that almost every function
consumes a reference of every jv value passed in, with very few
exceptions.  This simplifies memory management, or at least avoidance of
double-free and use-after-free (it can be harder to track down leaks
though, since tools like valgrind don't understand that jv_copy() call
sites can be like allocations).

Nico
--



pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: PSQL commands: \quit_if, \quit_unless
Next
From: Jim Nasby
Date:
Subject: Time to up bgwriter_lru_maxpages?