Re: jsonpath
От | Nikita Glukhov |
---|---|
Тема | Re: jsonpath |
Дата | |
Msg-id | a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru обсуждение исходный текст |
Ответ на | Re: jsonpath (Alexander Korotkov <a.korotkov@postgrespro.ru>) |
Список | pgsql-hackers |
On 20.01.2019 2:45, Alexander Korotkov wrote:
3) How do we calculate the "id" property returned by keyvalue() function? It's not documented. Even presence of "id" columns isn't documented. Standard stands that it's implementation-depended indetifier of object holding key-value pair. The way of its calculation is also not clear from the code. Why do we need constant of 10000000000? id = jb->type != jbvBinary ? 0 : (int64)((char *) jb->val.binary.data - (char *) cxt->baseObject.jbc); id += (int64) cxt->baseObject.id * INT64CONST(10000000000);
I decided to construct object id from the two parts: base object id and its binary offset in its base object's jsonb: object_id = 10000000000 * base_object_id + object_offset_in_base_object 10000000000 (10^10) -- is a first round decimal number greater than 2^32 (maximal offset in jsonb). Decimal multiplier is used here to improve the readability of identifiers. Base object is usually a root object of the path: context item '$' or path variable '$var', literals can't produce objects for now. But if the path contains generated objects (.keyvalue() itself, for example), then they become base object for the subsequent .keyvalue(). See example: '$.a.b.keyvalue().value.keyvalue()' :- base for the first .keyvalue() is '$'- base for the second .keyvalue() is '$.a.b.keyvalue()' Id of '$' is 0. Id of '$var' is its ordinal (positive) number in the list of variables. Ids for generated objects are assigned using global counter 'JsonPathExecContext.generatedObjectId' starting from 'number_of_vars + 1'. Corresponding comments will be added in the upcoming version of the patches. -- Nikita Glukhov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company
В списке pgsql-hackers по дате отправления: