From: | Florents Tselai <florents(dot)tselai(at)gmail(dot)com> |
---|---|
To: | "David E(dot) Wheeler" <david(at)justatheory(dot)com> |
Cc: | Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: PATCH: jsonpath string methods: lower, upper, initcap, l/r/btrim, replace, split_part |
Date: | 2024-09-27 10:28:21 |
Message-ID: | EA435DAF-B81C-4A3A-B0DE-9F63812644A8@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
> On 27 Sep 2024, at 12:45 PM, David E. Wheeler <david(at)justatheory(dot)com> wrote:
>
> On Sep 26, 2024, at 13:59, Florents Tselai <florents(dot)tselai(at)gmail(dot)com> wrote:
>
>> Speaking of extensible: the jsonpath standard does mention function extensions [1] ,
>> so it looks like we're covered by the standard, and the mutability aspect is an implementation detail. No?
>
> That’s not the standard used for Postgres jsonpath. Postgres follows the SQL/JSON standard in the SQL standard, which is not publicly available, but a few people on the list have copies they’ve purchased and so could provide some context.
>
> In a previous post I wondered if the SQL standard had some facility for function extensions, but I suspect not. Maybe in the next iteration?
>
>> And having said that, the whole jsonb/jsonpath parser/executor infrastructure is extremely powerful
>> and kinda under-utilized if we use it "only" for jsonpath.
>> Tbh, I can see it supporting more specific DSLs and even offering hooks for extensions.
>> And I know for certain I'm not the only one thinking about this.
>> See [2] for example where they've lifted, shifted and renamed the jsonb/jsonpath infra to build a separate language for graphs
>
> I’m all for extensibility, though jsonpath does need to continue to comply with the SQL standard. Do you have some idea of the sorts of hooks that would allow extension authors to use some of that underlying capability?
Re-tracing what I had to do
1. Define a new JsonPathItemType jpiMyExtType and map it to a JsonPathKeyword
2. Add a new JsonPathKeyword and make the lexer and parser aware of that,
3. Tell the main executor executeItemOptUnwrapTarget what to do when the new type is matched.
I think 1, 2 are the trickiest because they require hooks to jsonpath_scan.l and parser jsonpath_gram.y
3. is the meat of a potential hook, which would be something like
extern JsonPathExecResult executeOnMyJsonpathItem(JsonPathExecContext *cxt, JsonbValue *jb, JsonValueList *found);
This should be called by the main executor executeItemOptUnwrapTarget when it encounters case jpiMyExtType
It looks like quite an endeavor, to be honest.
From | Date | Subject | |
---|---|---|---|
Next Message | Andrey M. Borodin | 2024-09-27 10:36:58 | Re: Truncate logs by max_log_size |
Previous Message | David E. Wheeler | 2024-09-27 09:49:31 | Re: SQL:2023 JSON simplified accessor support |