Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8yXp-000827-3w for pgsql-jdbc@arkaria.postgresql.org; Sat, 27 Jun 2015 22:25:53 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z8yXo-0007ed-Jc for pgsql-jdbc@arkaria.postgresql.org; Sat, 27 Jun 2015 22:25:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z8yX8-00073O-Gg for pgsql-jdbc@postgresql.org; Sat, 27 Jun 2015 22:25:10 +0000 Received: from mail-wi0-f177.google.com ([209.85.212.177]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Z8yX5-0007Xs-ER for pgsql-jdbc@postgresql.org; Sat, 27 Jun 2015 22:25:09 +0000 Received: by wicnd19 with SMTP id nd19so43112423wic.1 for ; Sat, 27 Jun 2015 15:25:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=rmOE6fAh19AuMc1BUNbtaeitQjUEVkD8OLP8eG0H87U=; b=O6o0GY+RQo9QHPYSAlb8wqlL67N+wh4xwHzYQArQcsrKtzS1YQuO8EMLD+CMpzceSd VfolJjF1zBt9NsXpc0jgavu5J3rnL5LzKJZnyTwPPrxBBa7TmU0GA61xbPDkg0kmU36r /07eRJiDvBo2XAM+iYKYB+LmBvEJQTJMIlGCiqobw6w7jfCfnf/Di85Xt03T8CuTvwnK om1v6goQJAAyUM80xjDIZXdvpafcEQkZZUJsN1Kn2ClR3T6r62m1KRuQDuMO1jKhzxSn 6iviiJpxmNbNmZ7SQtQgRvHnC9COjV6Qbjo1h1Az6o5tT4iYfCKyS5mazDCidV4Xu7WA iCUg== X-Gm-Message-State: ALoCoQnqiMrUGO72+/+ZiayXYdcD/reD76j77J1IAP9cC8h1I413pCTGOGk+m5o+jQWS7aMBAPxN X-Received: by 10.194.172.130 with SMTP id bc2mr16263975wjc.85.1435443905979; Sat, 27 Jun 2015 15:25:05 -0700 (PDT) Received: from [192.168.43.95] ([31.4.238.26]) by mx.google.com with ESMTPSA id ha4sm4774302wib.0.2015.06.27.15.25.04 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 27 Jun 2015 15:25:05 -0700 (PDT) Message-ID: <558F22BE.5050508@8Kdata.com> Date: Sun, 28 Jun 2015 00:25:02 +0200 From: =?UTF-8?B?w4FsdmFybyBIZXJuw6FuZGV6IFRvcnRvc2E=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Sehrope Sarkuni , Markus KARG , Dave Cramer CC: List Subject: Re: SQLJSON References: <558ED5A6.4070500@8Kdata.com> <002701d0b104$114cdd60$33e69820$@eu> <000601d0b125$17d3fee0$477bfca0$@eu> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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 ...)) 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 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