Re: JsonbValue to Jsonb conversion

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: JsonbValue to Jsonb conversion
Date: 2014-10-13 10:41:48
Message-ID: CAFj8pRBRt70Jj3g_55Sbgj3sxJuDgW0ZUub3Nrmver1_nMM2XQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

I am working on review of this patch.

There is new warnings:

jsonb.c: In function ‘jsonb_agg_transfn’:
jsonb.c:1540:20: warning: assignment makes pointer from integer without a
cast
v.val.numeric = DirectFunctionCall1(numeric_uplus,
NumericGetDatum(v.val.numeric));
^
jsonb.c: In function ‘jsonb_object_agg_transfn’:
jsonb.c:1745:20: warning: assignment makes pointer from integer without a
cast
v.val.numeric = DirectFunctionCall1(numeric_uplus,
NumericGetDatum(v.val.numeric));

[pavel(at)localhost postgresql]$ gcc --version
gcc (GCC) 4.9.1 20140930 (Red Hat 4.9.1-11)

Check fails

parallel group (19 tests): alter_table plancache temp domain prepare limit
plpgsql conversion sequence copy2 rangefuncs returning truncate xml with
without_oid largeobject polymorphism rowtypes
plancache ... FAILED (test process exited with exit
code 2)
limit ... FAILED (test process exited with exit
code 2)
plpgsql ... FAILED (test process exited with exit
code 2)
copy2 ... FAILED (test process exited with exit
code 2)
temp ... FAILED (test process exited with exit
code 2)
domain ... FAILED (test process exited with exit
code 2)
rangefuncs ... FAILED (test process exited with exit
code 2)
prepare ... FAILED (test process exited with exit
code 2)
without_oid ... FAILED (test process exited with exit
code 2)
conversion ... FAILED (test process exited with exit
code 2)
truncate ... FAILED (test process exited with exit
code 2)
alter_table ... FAILED (test process exited with exit
code 2)
sequence ... FAILED (test process exited with exit
code 2)
polymorphism ... FAILED (test process exited with exit
code 2)
rowtypes ... FAILED (test process exited with exit
code 2)
returning ... FAILED (test process exited with exit
code 2)
largeobject ... FAILED (test process exited with exit
code 2)
with ... FAILED (test process exited with exit
code 2)
xml ... FAILED (test process exited with exit
code 2)
test stats ... FAILED (test process exited with exit
code 2)

[pavel(at)localhost postgresql]$ uname -a
Linux localhost.localdomain 3.16.3-302.fc21.x86_64 #1 SMP Fri Sep 26
14:27:20 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

backtrace

Core was generated by `postgres: pavel regression [local]
SELECT '.
Program terminated with signal SIGSEGV, Segmentation fault.

(gdb) bt
#0 0x0000000001e95300 in ?? ()
#1 0x00000000007c048b in parse_object_field (lex=0x1ede9d8,
sem=0x7fff3c3c4660) at json.c:398
#2 0x00000000007c0524 in parse_object (lex=0x1ede9d8, sem=0x7fff3c3c4660)
at json.c:430
#3 0x00000000007c0214 in pg_parse_json (lex=0x1ede9d8, sem=0x7fff3c3c4660)
at json.c:297
#4 0x00000000007c5d91 in datum_to_jsonb (val=32118224, is_null=0 '\000',
result=0x7fff3c3c4800, tcategory=JSONBTYPE_JSON,
outfuncoid=322, key_scalar=0 '\000') at jsonb.c:789
#5 0x00000000007c68be in add_jsonb (val=32118224, is_null=0 '\000',
result=0x7fff3c3c4800, val_type=114, key_scalar=0 '\000')
at jsonb.c:1050
#6 0x00000000007c6d08 in jsonb_build_object (fcinfo=0x1edcb80) at
jsonb.c:1155
#7 0x000000000060bfc5 in ExecMakeFunctionResultNoSets (fcache=0x1edcb10,
econtext=0x1edc920, isNull=0x1edd568 "", isDone=0x1edd680)
at execQual.c:1992
#8 0x000000000060c8bc in ExecEvalFunc (fcache=0x1edcb10,
econtext=0x1edc920, isNull=0x1edd568 "", isDone=0x1edd680)
at execQual.c:2383
#9 0x0000000000612869 in ExecTargetList (targetlist=0x1edd650,
econtext=0x1edc920, values=0x1edd550, isnull=0x1edd568 "",
itemIsDone=0x1edd680, isDone=0x7fff3c3c4a84) at execQual.c:5265
#10 0x0000000000612e9d in ExecProject (projInfo=0x1edd580,
isDone=0x7fff3c3c4a84) at execQual.c:5480
#11 0x000000000062c046 in ExecResult (node=0x1edc810) at nodeResult.c:155
#12 0x0000000000608997 in ExecProcNode (node=0x1edc810) at
execProcnode.c:373
#13 0x000000000060696e in ExecutePlan (estate=0x1edc700,
planstate=0x1edc810, operation=CMD_SELECT, sendTuples=1 '\001',
numberTuples=0, direction=ForwardScanDirection, dest=0x1ea18b0) at
execMain.c:1481
#14 0x0000000000604de8 in standard_ExecutorRun (queryDesc=0x1edc2f0,
direction=ForwardScanDirection, count=0) at execMain.c:308
#15 0x0000000000604ce5 in ExecutorRun (queryDesc=0x1edc2f0,
direction=ForwardScanDirection, count=0) at execMain.c:256
#16 0x000000000075615a in PortalRunSelect (portal=0x1eda2e0, forward=1
'\001', count=0, dest=0x1ea18b0) at pquery.c:946
#17 0x0000000000755e34 in PortalRun (portal=0x1eda2e0,
count=9223372036854775807, isTopLevel=1 '\001', dest=0x1ea18b0,
altdest=0x1ea18b0, completionTag=0x7fff3c3c4dc0 "") at pquery.c:790
#18 0x00000000007502c2 in exec_simple_query (
query_string=0x1ea0050 "SELECT jsonb_build_object('e',json '{\"x\": 3,
\"y\": [1,2,3]}');") at postgres.c:1045
#19 0x0000000000754284 in PostgresMain (argc=1, argv=0x1e45448,
dbname=0x1e452f8 "postgres", username=0x1e452e0 "pavel")
at postgres.c:4010
#20 0x00000000006e7954 in BackendRun (port=0x1e64d20) at postmaster.c:4118
#21 0x00000000006e70ac in BackendStartup (port=0x1e64d20) at
postmaster.c:3793
#22 0x00000000006e3ba9 in ServerLoop () at postmaster.c:1572
#23 0x00000000006e327c in PostmasterMain (argc=3, argv=0x1e44540) at
postmaster.c:1219

Problematic statement:

SELECT jsonb_build_array('a',1,'b',1.2,'c',true,'d',null,'e',json '{"x": 3,
"y": [1,2,3]}');

or SELECT jsonb_build_object('e',json '{"x": 3, "y": [1,2,3]}');

Tested on HEAD

Regards

Pavel

2014-09-24 2:20 GMT+02:00 Andrew Dunstan <andrew(at)dunslane(dot)net>:

>
> On 09/23/2014 12:23 PM, Dmitry Dolgov wrote:
>
>> Hi all,
>>
>> I'm faced with some troubles about the jsonb implementation, and I hope
>> I'll get little advice =)
>> If I understand correctly, an abstract function for jsonb modification
>> should have the following stages:
>>
>> Jsonb -> JsonbValue -> Modification -> JsonbValue -> Jsonb
>>
>> One can convert the *JsonbValue* to the *Jsonb* only by
>> *JsonbValueToJsonb* function. So, my question is can be *JsonbValue*, that
>> contains few *jbvBinary* elements, converted to *Jsonb* by this function?
>> It will be very useful, if you want modify only small part of your
>> JsonbValue (e.g. replace value of some key). But when I'm trying to do
>> this, an exception "unknown type of jsonb container" appears. Maybe I
>> missed something? Or is there another approach to do this conversion?
>>
>
>
> If you can come up with a way of handling the jbvBinary values then by all
> means send a patch.
>
> But this problem is fairly easily worked around by using an iterator over
> the binary value. The attached patch, which is work in progress for adding
> in the currently missing json functions for jsonb, contains a sort of
> example of doing this in jsonb_agg_transfn.
>
> cheers
>
> andrew
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2014-10-13 13:04:56 Re: split builtins.h to quote.h
Previous Message Petr Jelinek 2014-10-13 10:01:10 Re: Sequence Access Method WIP