pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Álvaro Hernández Tortosa <aht@8Kdata.com>
To: Sehrope Sarkuni <sehrope@jackdb.com>
To: Markus KARG <markus@headcrashing.eu>
To: Dave Cramer <pg@fastcrypt.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: SQLJSON
Date: Sun, 28 Jun 2015 00:25:02 +0200
Message-ID: <558F22BE.5050508@8Kdata.com> (raw)
In-Reply-To: <CAH7T-arHGk_tyJZkJjubBVmip_FY5NR7xkquVTGwN5FLWxkqnA@mail.gmail.com>
References: <CADK3HH+RBjfo7gp3k-DSZYiZ-qS1BcS-OjG3xAgJhJDHbkgo_Q@mail.gmail.com>
	<F9AA993B-8CF6-4DFE-B582-BD775DCC1583@gmail.com>
	<CADK3HHLHxztk8gBYYxg4yTkRx=pPJbyT-3mxOqPX6W3aa3tXTg@mail.gmail.com>
	<C6608539-7F7D-49AB-B7D7-16034B9DED4A@gmail.com>
	<558ED5A6.4070500@8Kdata.com>
	<002701d0b104$114cdd60$33e69820$@eu>
	<CADK3HHJLxgo9BfyhZWn0qcRcEXhe01g9NppOymBScV5wqB=7Pw@mail.gmail.com>
	<000601d0b125$17d3fee0$477bfca0$@eu>
	<CAH7T-arHGk_tyJZkJjubBVmip_FY5NR7xkquVTGwN5FLWxkqnA@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>


On 28/06/15 00:11, Sehrope Sarkuni wrote:
> Thinking this through a bit, I see a couple things we'd need to figure 
> out:
>
> 1. What parser would we use?
> 2. What object type(s) would the parser return?
> 3. What would the end-user API look like?
> 4. What's the end user benefit of this?
>
> #1 has lots of possible answers. Everything from pluggable APIs, 
> classpath scanning, the JSON APIs mentioned so far in this thread.

     Hi Sehrope!

     To me, this is the least important question. If based on JSR353's 
SPI, it's trivial to swap the default, included one, for another one. 
Just picking a sensible default (Jackson, for instance) is probably good 
enough.

>
> #2 is driven a lot by #1 as depending on the parser implementation 
> there may be different object types returned. JSON is a bit tricky as 
> "valid JSON" can mean null, a scalar, an object, or an array. Most 
> people thing of it as just an object but "foobar" is valid JSON as 
> well. This leads us to #3...

     The object type to return has to be IMHO JsonObject: 
http://docs.oracle.com/javaee/7/api/javax/json/JsonObject.html

>
> #3 doesn't have a straight answer as there is no getJSON(...) methods 
> in the JDBC spec. It'd probably have to be returned via getObject(...).
>
> An alternative is to provide PGResultSet and PGPreparedStatement 
> classes similar to PGConnection that provides PG extensions. They 
> could have the get/set methods (ex: getJsonScalar(...) or 
> setJsonObject(Map<String,Object> ...)) to retrieve JSON values as 
> specific object types (i.e. scalar, object, array). It'd be a bit more 
> type safe as presumably most people using json/jsonb types know the 
> top level type of what they're storing.

     Probably adding methods to PG classes would be better than 
getObject and force explicit casts. Regarding the methods, if they 
simply return JsonObject, you already have a full API there to parse and 
extract and process. So anything that returns a JsonObject from a column 
(identifier or #) would be enough for me.

>
> For #4 I see two possible wins. First off on the usability side, 
> there's some convenience to natively interfacing with json/jsonb 
> types. It'll only have value though if those types are the same ones 
> that users are using in the rest of their code. If they're just using 
> them as Map<String,Object> everywhere then it'd still be a pain for a 
> user to convert to our "native" PG JSON types to use via JDBC. Having 
> a dedicated API that allows for interaction using native Java types 
> would make this more convenient.
>
> The other win I can see for #4 is on performance. Right now JSON is 
> converted to a String. That means everybody using it has to convert it 
> twice. First raw bytes to String, then String to object. A dedicated 
> API could cut one of those out of the way. Given how the wire protocol 
> is implemented in the driver, it wouldn't be a direct reading from the 
> input stream (it'll be buffered in a byte array), but at least it 
> won't be copied twice.

     As far as I know, most users are using JsonObject, so returning 
that is a perfect match for pgjdbc. I don't expect however big 
performance wins as JSON is sent as a String over the wire...

     Regards,

     Álvaro

-- 
Álvaro Hernández Tortosa


-----------
8Kdata



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (103+ messages)  latest in thread

Message-ID: <558F22BE.5050508@8Kdata.com>
Permalink:  ../558F22BE.5050508@8Kdata.com/
Also on:    postgresql.org/message-id/558F22BE.5050508@8Kdata.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: aht@8Kdata.com, sehrope@jackdb.com, markus@headcrashing.eu, pg@fastcrypt.com
  Subject: Re: SQLJSON
  In-Reply-To: <558F22BE.5050508@8Kdata.com>
  References: <CADK3HH+RBjfo7gp3k-DSZYiZ-qS1BcS-OjG3xAgJhJDHbkgo_Q@mail.gmail.com> <F9AA993B-8CF6-4DFE-B582-BD775DCC1583@gmail.com> <CADK3HHLHxztk8gBYYxg4yTkRx=pPJbyT-3mxOqPX6W3aa3tXTg@mail.gmail.com> <C6608539-7F7D-49AB-B7D7-16034B9DED4A@gmail.com> <558ED5A6.4070500@8Kdata.com> <002701d0b104$114cdd60$33e69820$@eu> <CADK3HHJLxgo9BfyhZWn0qcRcEXhe01g9NppOymBScV5wqB=7Pw@mail.gmail.com> <000601d0b125$17d3fee0$477bfca0$@eu> <CAH7T-arHGk_tyJZkJjubBVmip_FY5NR7xkquVTGwN5FLWxkqnA@mail.gmail.com> <558F22BE.5050508@8Kdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox