Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edyVu-0003lj-EE for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2018 13:21:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1edyVt-0003uf-Po for pgsql-hackers@arkaria.postgresql.org; Tue, 23 Jan 2018 13:21:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1edyVt-0003uV-5y for pgsql-hackers@lists.postgresql.org; Tue, 23 Jan 2018 13:21:21 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1edyVp-0004ws-3m for pgsql-hackers@postgresql.org; Tue, 23 Jan 2018 13:21:19 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2CE3421C074F; Tue, 23 Jan 2018 16:21:13 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [10.100.236.30] (unknown [195.82.154.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id CD31121C05D3; Tue, 23 Jan 2018 16:21:12 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1516713672; bh=1ZrsccqtK7EzKhOOjltSVHuC/mU6fkjZoRKc3zmDOjw=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=ZETbSG6OcRDDq4EQi6h12DqtssRTU8GQiG4Wf7LaVDgYMQ5x3aoqChwWKHaY+4Obh 2rq/XmCm7jir8TS4AVioKapf3m1MzDZVleG0rxXgwwSZ5CHKiuMHLUrqk8+Nt00AIq 8C+39Vuk+FA9VeBmtQ/nPGLQTqynO1i5gpLgQGzc= Subject: Re: jsonpath To: Andrew Dunstan , Pavel Stehule Cc: PostgreSQL-development , Oleg Bartunov References: <9f845926-0d7d-7c4d-75e3-b1e921a1677a@2ndQuadrant.com> <48f13b75-0be7-c356-ff26-1db743add56e@postgrespro.ru> <7b4b8973-43f5-71c5-bf86-51cb5798dd88@2ndQuadrant.com> <5290ddd1-f23e-a53a-cae0-830dbde0a5fe@2ndQuadrant.com> From: Nikita Glukhov Organization: Postgres Professional Message-ID: <604ffe9c-b42e-7c42-e16b-aa44c3a12c3c@postgrespro.ru> Date: Tue, 23 Jan 2018 16:18:14 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <5290ddd1-f23e-a53a-cae0-830dbde0a5fe@2ndQuadrant.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 23.01.2018 01:41, Andrew Dunstan wrote: > On 01/17/2018 04:01 PM, Andrew Dunstan wrote: >> On 01/15/2018 07:24 PM, Andrew Dunstan wrote: >>> On 01/10/2018 05:42 PM, Nikita Glukhov wrote: >>>> Attached new 8th version of jsonpath related patches. Complete >>>> documentation is still missing. >>>> >>>> The first 4 small patches are necessary datetime handling in jsonpath: >>>> 1. simple refactoring, extracted function that will be used later in >>>> jsonpath >>>> 2. throw an error when the input or format string contains trailing >>>> elements >>>> 3. avoid unnecessary cstring to text conversions >>>> 4. add function for automatic datetime type recognition by the >>>> presence of formatting components >>>> >>>> Should they be posted in a separate thread? >>>> >>> The first of these refactors the json/jsonb timestamp formatting into a >>> single function, removing a lot of code duplication. The involves >>> exposing time2tm() and timetz2tm(). I don't think that's a tragedy, so >>> unless there is any objection I propose to commit it shortly. >>> >>> The next three expose a bit more of the date/time API. I'm still >>> reviewing those. >> I have committed the first of these patches. >> >> I have reviewed the next three, and I think they are generally good. >> There is no real point in committing them ahead of the jsonpath patch >> since there would be no point in having them at all but for that patch. >> >> Note that these do export the following hitherto internal bits of the >> datetime functionality: >> >> tm2time >> tm2timetz >> AdjustTimeForTypmod >> AdjustTimestampForTypmod >> >> Moving on to review the main jsonpath patch. > > OK, I understand a good deal more than I did about how the jsopnpath > code works, but the commenting is abysmal. Thank you for reviewing. > I got quite nervous about adding a new datetime variant to JsonbValue. > However, my understanding from the code is that this will only ever be > used in an intermediate jsonpath processing result, and it won't be used > in a stored or build jsonb object. Is that right? Yes, you are right. Datetime JsonbValues are used only for for in-memory representation of SQL/JSON datetime items, they converted into ordinary JSON strings in ISO format when json/jsonb encoded into a datum. > If it is we need to say so, and moreover we need to warn coders in the > header file about the restricted use of this variant.  I'm not sure we > can enforce it with an Assert, but If we can we should. I'm not 100% > sure that doing it this way, i.e. by extending and resuing jsonbValue, > is desirable, I'd like to know some of the thinking behind the design. Datetime support was added to our jsonpath implementation when there was already a lot of code using plain JsonbValue. So, the simplest are most effective solution I found was JsonbValue extension. We could also introduce extended struct SqlJsonItem, but it seems that there will be a lot of unnecessary conversions between SqlJsonItem and JsonbValue. > The encoding of a jsonpath value into a binary string is quite nifty, > but it needs to be documented. Once I understood it better some of my > fears about parser overhead were alleviated. > The use of a function pointer inside JsonPathVariable seems unnecessary > and baroque. It would be much more straightforward to set an isnull flag > in the struct and process the value in an "if" statement accordingly, > avoiding the function pointer altogether. Callback in JsonPathVariable is used for on-demand evaluation of SQL/JSON PASSING parameters (see EvalJsonPathVar() from patch 0010-sqljson-v08.patch). For jsonpath itself it is really unnecessary. > I am going to be travelling for a few days, then back online for a day > or two, then gone for a week. I hope we can make progress on these > features, but this needs lots more eyeballs, reviewing code as well as > testing, and lots more responsiveness. The whole suite is enormous. > > cheers > > andrew -- Nikita Glukhov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company