Transform for pl/perl

Started by Anthony Bykovover 8 years ago62 messageshackers
Jump to latest
#1Anthony Bykov
a.bykov@postgrespro.ru

Hello.
Please, check out jsonb transform
(https://www.postgresql.org/docs/9.5/static/sql-createtransform.html)
for pl/perl language I've implemented.

Attachments:

0001-jsonb_plperl-extension.patchtext/x-patchDownload+577-2
#2Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Anthony Bykov (#1)
Re: Transform for pl/perl

There are some moments I should mention:
1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while
["1","2"]::jsonb is transformed into AV ["1", "2"]

2. If there is a numeric value appear in jsonb, it will be transformed
to SVnv through string (Numeric->String->SV->SVnv). Not the best
solution, but as far as I understand this is usual practise in
postgresql to serialize Numerics and de-serialize them.

3. SVnv is transformed into jsonb through string
(SVnv->String->Numeric).

An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into perl,
transforms it back into jsonb and returns it.

create extension jsonb_plperl cascade;

create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plperl
as $$
return $_[0];
$$;

select test('{"1":1,"example": null}'::jsonb);

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Robert Haas
robertmhaas@gmail.com
In reply to: Anthony Bykov (#1)
Re: Transform for pl/perl

On Tue, Oct 24, 2017 at 1:01 PM, anthony <a.bykov@postgrespro.ru> wrote:

Hello.
Please, check out jsonb transform
(https://www.postgresql.org/docs/9.5/static/sql-createtransform.html)
for pl/perl language I've implemented.

Neat.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Pavel Stehule
pavel.stehule@gmail.com
In reply to: Anthony Bykov (#2)
Re: Transform for pl/perl

Hi

2017-10-24 14:27 GMT+02:00 Anthony Bykov <a.bykov@postgrespro.ru>:

There are some moments I should mention:
1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while
["1","2"]::jsonb is transformed into AV ["1", "2"]

2. If there is a numeric value appear in jsonb, it will be transformed
to SVnv through string (Numeric->String->SV->SVnv). Not the best
solution, but as far as I understand this is usual practise in
postgresql to serialize Numerics and de-serialize them.

3. SVnv is transformed into jsonb through string
(SVnv->String->Numeric).

An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into perl,
transforms it back into jsonb and returns it.

create extension jsonb_plperl cascade;

create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plperl
as $$
return $_[0];
$$;

select test('{"1":1,"example": null}'::jsonb);

I am looking to this patch:

1. the patch contains some artefacts - look the word "hstore"

2. I got lot of warnings

make[1]: Vstupuje se do adresáře
„/home/pavel/src/postgresql/contrib/jsonb_plperl“
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-g -ggdb -Og -g3 -fno-omit-frame-pointer -fPIC -I../../src/pl/plperl -I.
-I. -I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/lib64/perl5/CORE -c -o jsonb_plperl.o jsonb_plperl.c
jsonb_plperl.c: In function ‘SV_FromJsonbValue’:
jsonb_plperl.c:83:9: warning: ‘result’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
return (result);
^
jsonb_plperl.c: In function ‘SV_FromJsonb’:
jsonb_plperl.c:95:10: warning: ‘object’ may be used uninitialized in this
function [-Wmaybe-uninitialized]
HV *object;
^~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:5644:0,
from ../../src/pl/plperl/plperl.h:52,
from jsonb_plperl.c:17:
/usr/lib64/perl5/CORE/embed.h:404:19: warning: ‘value’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
#define newRV(a) Perl_newRV(aTHX_ a)
^~~~~~~~~~
jsonb_plperl.c:101:10: note: ‘value’ was declared here
SV *value;
^~~~~
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute
-Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-g -ggdb -Og -g3 -fno-omit-frame-pointer -fPIC -shared -o jsonb_plperl.so
jsonb_plperl.o -L../../src/port -L../../src/common -Wl,--as-needed
-Wl,-rpath,'/usr/lib64/perl5/CORE',--enable-new-dtags -Wl,-z,relro
-specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong
-L/usr/local/lib -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -lnsl
-ldl -lm -lcrypt -lutil -lc
make[1]: Opouští se adresář
„/home/pavel/src/postgresql/contrib/jsonb_plperl“

[pavel@nemesis contrib]$ gcc --version
gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

3. regress tests passed

4. There are not any documentation - probably it should be part of PLPerl

5. The regress tests doesn't coverage other datatypes than numbers. I miss
boolean, binary, object, ... Maybe using data::dumper or some similar can
be interesting

Note - it is great extension, I am pleasured so transformations are used.

Regards

Pavel

Show quoted text

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Pavel Stehule (#4)
Re: [HACKERS] Transform for pl/perl

On Fri, 10 Nov 2017 14:40:21 +0100
Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hi

2017-10-24 14:27 GMT+02:00 Anthony Bykov <a.bykov@postgrespro.ru>:

There are some moments I should mention:
1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while
["1","2"]::jsonb is transformed into AV ["1", "2"]

2. If there is a numeric value appear in jsonb, it will be
transformed to SVnv through string (Numeric->String->SV->SVnv). Not
the best solution, but as far as I understand this is usual
practise in postgresql to serialize Numerics and de-serialize them.

3. SVnv is transformed into jsonb through string
(SVnv->String->Numeric).

An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into perl,
transforms it back into jsonb and returns it.

create extension jsonb_plperl cascade;

create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plperl
as $$
return $_[0];
$$;

select test('{"1":1,"example": null}'::jsonb);

I am looking to this patch:

1. the patch contains some artefacts - look the word "hstore"

2. I got lot of warnings

make[1]: Vstupuje se do adresáře
„/home/pavel/src/postgresql/contrib/jsonb_plperl“
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -I../../src/pl/plperl -I. -I.
-I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/lib64/perl5/CORE -c -o jsonb_plperl.o jsonb_plperl.c
jsonb_plperl.c: In function ‘SV_FromJsonbValue’: jsonb_plperl.c:83:9:
warning: ‘result’ may be used uninitialized in this function
[-Wmaybe-uninitialized] return (result);
^
jsonb_plperl.c: In function ‘SV_FromJsonb’:
jsonb_plperl.c:95:10: warning: ‘object’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
HV *object;
^~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:5644:0,
from ../../src/pl/plperl/plperl.h:52,
from jsonb_plperl.c:17:
/usr/lib64/perl5/CORE/embed.h:404:19: warning: ‘value’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
#define newRV(a) Perl_newRV(aTHX_ a)
^~~~~~~~~~
jsonb_plperl.c:101:10: note: ‘value’ was declared here
SV *value;
^~~~~
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -shared -o jsonb_plperl.so
jsonb_plperl.o -L../../src/port -L../../src/common -Wl,--as-needed
-Wl,-rpath,'/usr/lib64/perl5/CORE',--enable-new-dtags -Wl,-z,relro
-specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE
-lperl -lpthread -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc make[1]:
Opouští se adresář „/home/pavel/src/postgresql/contrib/jsonb_plperl“

[pavel@nemesis contrib]$ gcc --version
gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

3. regress tests passed

4. There are not any documentation - probably it should be part of
PLPerl

5. The regress tests doesn't coverage other datatypes than numbers. I
miss boolean, binary, object, ... Maybe using data::dumper or some
similar can be interesting

Note - it is great extension, I am pleasured so transformations are
used.

Regards

Pavel

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Hello,
Thank you for your review. I have fixed most of your comments, except
for the 5-th part, about data::dumper - I just couldn't understand
your point, but I've added more tests with more complex objects if this
helps.

Please, take a look at new patch. You can find it in attachments to
this message (it is called "0001-jsonb_plperl-extension-v2.patch")
--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

0001-jsonb_plperl-extension-v2.patchtext/x-patchDownload+883-2
#6Pavel Stehule
pavel.stehule@gmail.com
In reply to: Anthony Bykov (#5)
Re: [HACKERS] Transform for pl/perl

Hi

Hello,
Thank you for your review. I have fixed most of your comments, except
for the 5-th part, about data::dumper - I just couldn't understand
your point, but I've added more tests with more complex objects if this
helps.

Please, take a look at new patch. You can find it in attachments to
this message (it is called "0001-jsonb_plperl-extension-v2.patch")

I changed few lines in regress tests.

Now, I am think so this patch is ready for commiters.

1. all tests passed
2. there are some basic documentation

I have not any other objections

Regards

Pavel

Show quoted text

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

0001-jsonb_plperl-extension-v3.patchtext/x-patch; charset=US-ASCII; name=0001-jsonb_plperl-extension-v3.patchDownload+1275-2
#7Aleksander Alekseev
aleksander@timescale.com
In reply to: Pavel Stehule (#6)
Re: Transform for pl/perl

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed

Hello Anthony,

Great patch! Everything is OK and I almost agree with Pavel.

The only thing that I would like to suggest is to add a little more tests for
various corner cases. For instance:

1. Converting in both directions (Perl <-> JSONB) +/- infinity, NaN, MAX_INT,
MIN_INT.

2. Converting in both directions strings that contain non-ASCII (Russian /
Japanese / etc) characters and special characters like \n, \t, \.

3. Make sure that converting Perl objects that are not representable in JSONB
(blessed hashes, file descriptors, regular expressions, ...) doesn't crash
everything and shows a reasonable error message.

The new status of this patch is: Waiting on Author

#8Oleg Bartunov
oleg@sai.msu.su
In reply to: Anthony Bykov (#5)
Re: [HACKERS] Transform for pl/perl

On 14 Nov 2017 11:35, "Anthony Bykov" <a.bykov@postgrespro.ru> wrote:

On Fri, 10 Nov 2017 14:40:21 +0100
Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hi

2017-10-24 14:27 GMT+02:00 Anthony Bykov <a.bykov@postgrespro.ru>:

There are some moments I should mention:
1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while
["1","2"]::jsonb is transformed into AV ["1", "2"]

2. If there is a numeric value appear in jsonb, it will be
transformed to SVnv through string (Numeric->String->SV->SVnv). Not
the best solution, but as far as I understand this is usual
practise in postgresql to serialize Numerics and de-serialize them.

3. SVnv is transformed into jsonb through string
(SVnv->String->Numeric).

An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into perl,
transforms it back into jsonb and returns it.

create extension jsonb_plperl cascade;

create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plperl
as $$
return $_[0];
$$;

select test('{"1":1,"example": null}'::jsonb);

I am looking to this patch:

1. the patch contains some artefacts - look the word "hstore"

2. I got lot of warnings

make[1]: Vstupuje se do adresáře
„/home/pavel/src/postgresql/contrib/jsonb_plperl“
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -I../../src/pl/plperl -I. -I.
-I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/lib64/perl5/CORE -c -o jsonb_plperl.o jsonb_plperl.c
jsonb_plperl.c: In function ‘SV_FromJsonbValue’: jsonb_plperl.c:83:9:
warning: ‘result’ may be used uninitialized in this function
[-Wmaybe-uninitialized] return (result);
^
jsonb_plperl.c: In function ‘SV_FromJsonb’:
jsonb_plperl.c:95:10: warning: ‘object’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
HV *object;
^~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:5644:0,
from ../../src/pl/plperl/plperl.h:52,
from jsonb_plperl.c:17:
/usr/lib64/perl5/CORE/embed.h:404:19: warning: ‘value’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
#define newRV(a) Perl_newRV(aTHX_ a)
^~~~~~~~~~
jsonb_plperl.c:101:10: note: ‘value’ was declared here
SV *value;
^~~~~
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -shared -o jsonb_plperl.so
jsonb_plperl.o -L../../src/port -L../../src/common -Wl,--as-needed
-Wl,-rpath,'/usr/lib64/perl5/CORE',--enable-new-dtags -Wl,-z,relro
-specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE
-lperl -lpthread -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc make[1]:
Opouští se adresář „/home/pavel/src/postgresql/contrib/jsonb_plperl“

[pavel@nemesis contrib]$ gcc --version
gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

3. regress tests passed

4. There are not any documentation - probably it should be part of
PLPerl

5. The regress tests doesn't coverage other datatypes than numbers. I
miss boolean, binary, object, ... Maybe using data::dumper or some
similar can be interesting

Note - it is great extension, I am pleasured so transformations are
used.

Regards

Pavel

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Hello,
Thank you for your review. I have fixed most of your comments, except
for the 5-th part, about data::dumper - I just couldn't understand
your point, but I've added more tests with more complex objects if this
helps.

Please, take a look at new patch. You can find it in attachments to
this message (it is called "0001-jsonb_plperl-extension-v2.patch")

I'm curious, how much benefit we could get from this ? There are several
publicly available json datasets, which can be used to measure performance
gaining. I have bookmarks and review datasets available from
http://www.sai.msu.su/~megera/postgres/files/, look at js.dump.gz and
jr.dump.gz

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#9Pavel Stehule
pavel.stehule@gmail.com
In reply to: Oleg Bartunov (#8)
Re: [HACKERS] Transform for pl/perl

2017-11-15 10:24 GMT+01:00 Oleg Bartunov <obartunov@gmail.com>:

On 14 Nov 2017 11:35, "Anthony Bykov" <a.bykov@postgrespro.ru> wrote:

On Fri, 10 Nov 2017 14:40:21 +0100
Pavel Stehule <pavel.stehule@gmail.com> wrote:

Hi

2017-10-24 14:27 GMT+02:00 Anthony Bykov <a.bykov@postgrespro.ru>:

There are some moments I should mention:
1. {"1":1}::jsonb is transformed into HV {"1"=>"1"}, while
["1","2"]::jsonb is transformed into AV ["1", "2"]

2. If there is a numeric value appear in jsonb, it will be
transformed to SVnv through string (Numeric->String->SV->SVnv). Not
the best solution, but as far as I understand this is usual
practise in postgresql to serialize Numerics and de-serialize them.

3. SVnv is transformed into jsonb through string
(SVnv->String->Numeric).

An example may also be helpful to understand extension. So, as an
example, function "test" transforms incoming jsonb into perl,
transforms it back into jsonb and returns it.

create extension jsonb_plperl cascade;

create or replace function test(val jsonb)
returns jsonb
transform for type jsonb
language plperl
as $$
return $_[0];
$$;

select test('{"1":1,"example": null}'::jsonb);

I am looking to this patch:

1. the patch contains some artefacts - look the word "hstore"

2. I got lot of warnings

make[1]: Vstupuje se do adresáře
„/home/pavel/src/postgresql/contrib/jsonb_plperl“
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -I../../src/pl/plperl -I. -I.
-I../../src/include -D_GNU_SOURCE -I/usr/include/libxml2
-I/usr/lib64/perl5/CORE -c -o jsonb_plperl.o jsonb_plperl.c
jsonb_plperl.c: In function ‘SV_FromJsonbValue’: jsonb_plperl.c:83:9:
warning: ‘result’ may be used uninitialized in this function
[-Wmaybe-uninitialized] return (result);
^
jsonb_plperl.c: In function ‘SV_FromJsonb’:
jsonb_plperl.c:95:10: warning: ‘object’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
HV *object;
^~~~~~
In file included from /usr/lib64/perl5/CORE/perl.h:5644:0,
from ../../src/pl/plperl/plperl.h:52,
from jsonb_plperl.c:17:
/usr/lib64/perl5/CORE/embed.h:404:19: warning: ‘value’ may be used
uninitialized in this function [-Wmaybe-uninitialized]
#define newRV(a) Perl_newRV(aTHX_ a)
^~~~~~~~~~
jsonb_plperl.c:101:10: note: ‘value’ was declared here
SV *value;
^~~~~
gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -ggdb -Og -g3
-fno-omit-frame-pointer -fPIC -shared -o jsonb_plperl.so
jsonb_plperl.o -L../../src/port -L../../src/common -Wl,--as-needed
-Wl,-rpath,'/usr/lib64/perl5/CORE',--enable-new-dtags -Wl,-z,relro
-specs=/usr/lib/rpm/redhat/redhat-hardened-ld
-fstack-protector-strong -L/usr/local/lib -L/usr/lib64/perl5/CORE
-lperl -lpthread -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc make[1]:
Opouští se adresář „/home/pavel/src/postgresql/contrib/jsonb_plperl“

[pavel@nemesis contrib]$ gcc --version
gcc (GCC) 7.2.1 20170915 (Red Hat 7.2.1-2)
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There
is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

3. regress tests passed

4. There are not any documentation - probably it should be part of
PLPerl

5. The regress tests doesn't coverage other datatypes than numbers. I
miss boolean, binary, object, ... Maybe using data::dumper or some
similar can be interesting

Note - it is great extension, I am pleasured so transformations are
used.

Regards

Pavel

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Hello,
Thank you for your review. I have fixed most of your comments, except
for the 5-th part, about data::dumper - I just couldn't understand
your point, but I've added more tests with more complex objects if this
helps.

Please, take a look at new patch. You can find it in attachments to
this message (it is called "0001-jsonb_plperl-extension-v2.patch")

I'm curious, how much benefit we could get from this ? There are several
publicly available json datasets, which can be used to measure performance
gaining. I have bookmarks and review datasets available from
http://www.sai.msu.su/~megera/postgres/files/, look at js.dump.gz and
jr.dump.gz

I don't expect significant performance effect - it remove some
transformations - perl object -> json | json -> jsonb - but on modern cpu
these transformations should be fast. For me - main benefit is user comfort
- it does direct transformation from perl object -> jsonb

But some performance check can be interesting

Regards

Pavel

Show quoted text

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#10Aleksander Alekseev
aleksander@timescale.com
In reply to: Pavel Stehule (#9)
Re: [HACKERS] Transform for pl/perl

Hello, hackers.

I'm curious, how much benefit we could get from this ? There are several
publicly available json datasets, which can be used to measure performance
gaining. I have bookmarks and review datasets available from
http://www.sai.msu.su/~megera/postgres/files/, look at js.dump.gz and
jr.dump.gz

I don't expect significant performance effect - it remove some
transformations - perl object -> json | json -> jsonb - but on modern cpu
these transformations should be fast. For me - main benefit is user comfort
- it does direct transformation from perl object -> jsonb

I completely agree that currently the main benefit of this feature is
user comfort. So correctness is the priority. When we make sure that the
implementation is correct we can start worry about the performance.
Probably in a separate patch.

Thanks for the datasets though!

--
Best regards,
Aleksander Alekseev

#11Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Aleksander Alekseev (#7)
Re: Transform for pl/perl

On Wed, 15 Nov 2017 08:58:54 +0000
Aleksander Alekseev <a.alekseev@postgrespro.ru> wrote:

The following review has been posted through the commitfest
application: make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed

Hello Anthony,

Great patch! Everything is OK and I almost agree with Pavel.

The only thing that I would like to suggest is to add a little more
tests for various corner cases. For instance:

1. Converting in both directions (Perl <-> JSONB) +/- infinity, NaN,
MAX_INT, MIN_INT.

2. Converting in both directions strings that contain non-ASCII
(Russian / Japanese / etc) characters and special characters like \n,
\t, \.

3. Make sure that converting Perl objects that are not representable
in JSONB (blessed hashes, file descriptors, regular expressions, ...)
doesn't crash everything and shows a reasonable error message.

The new status of this patch is: Waiting on Author

Hello Aleksander,
Thank you for your review.

I've added more tests and I had to change behavior of transform when
working with not-representable-in-JSONB format objects - now it will
through an exception. You can find an example in tests.

Please, find the 4-th version of patch in attachments.

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

0001-jsonb_plperl-extension-v4.patchtext/x-patchDownload+1180-2
#12Aleksander Alekseev
aleksander@timescale.com
In reply to: Anthony Bykov (#11)
Re: Transform for pl/perl

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed

Looks good to me.

The new status of this patch is: Ready for Committer

#13Michael Paquier
michael@paquier.xyz
In reply to: Aleksander Alekseev (#12)
Re: Transform for pl/perl

On Tue, Nov 28, 2017 at 5:14 PM, Aleksander Alekseev
<a.alekseev@postgrespro.ru> wrote:

The new status of this patch is: Ready for Committer

Patch moved to CF 2018-01. Perhaps a committer will look at it at some point.
--
Michael

#14Robert Haas
robertmhaas@gmail.com
In reply to: Michael Paquier (#13)
Re: Transform for pl/perl

On Fri, Dec 1, 2017 at 12:30 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Tue, Nov 28, 2017 at 5:14 PM, Aleksander Alekseev
<a.alekseev@postgrespro.ru> wrote:

The new status of this patch is: Ready for Committer

Patch moved to CF 2018-01. Perhaps a committer will look at it at some point.

FWIW, although I like the idea, I'm not going to work on the patch. I
like Perl, but I neither know its internals nor use plperl. I hope
someone else will be interested.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#14)
Re: Transform for pl/perl

Robert Haas <robertmhaas@gmail.com> writes:

On Fri, Dec 1, 2017 at 12:30 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Patch moved to CF 2018-01. Perhaps a committer will look at it at some point.

FWIW, although I like the idea, I'm not going to work on the patch. I
like Perl, but I neither know its internals nor use plperl. I hope
someone else will be interested.

I've been assuming (and I imagine other committers think likewise) that
Peter will pick this up at some point, since the whole transform feature
was his work to begin with. If he doesn't want to touch it, maybe he
should say so explicitly so that other people will feel free to take it.

regards, tom lane

#16Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Anthony Bykov (#11)
Re: Transform for pl/perl

A few very minor comments while quickly paging through:

1. non-ASCII tests are going to cause problems in one platform or
another. Please don't include that one.

2. error messages
a) please use ereport() not elog()
b) conform to style guidelines: errmsg() start with lowercase, others
are complete phrases (start with uppercase, end with period)
c) replace
"The type you was trying to transform can't be represented in JSONB"
maybe with
errmsg("could not transform to type \"%s\"", "jsonb"),
errdetail("The type you are trying to transform can't be represented in JSON")
d) same errmsg() for the other error; figure out suitable errdetail.

3. whitespace: don't add newlines to while, DirectFunctionCallN, pnstrdup.

4. the "relocatability" test seems pointless to me.

5. "#undef _" looks bogus. Don't do it.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#17Andrew Dunstan
andrew@dunslane.net
In reply to: Robert Haas (#14)
Re: Transform for pl/perl

On 12/01/2017 11:37 AM, Robert Haas wrote:

On Fri, Dec 1, 2017 at 12:30 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Tue, Nov 28, 2017 at 5:14 PM, Aleksander Alekseev
<a.alekseev@postgrespro.ru> wrote:

The new status of this patch is: Ready for Committer

Patch moved to CF 2018-01. Perhaps a committer will look at it at some point.

FWIW, although I like the idea, I'm not going to work on the patch. I
like Perl, but I neither know its internals nor use plperl. I hope
someone else will be interested.

I will probably pick it up fairly shortly.

cheers

andrew

--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#18Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Alvaro Herrera (#16)
Re: Transform for pl/perl

On Fri, 1 Dec 2017 15:49:21 -0300
Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

A few very minor comments while quickly paging through:

1. non-ASCII tests are going to cause problems in one platform or
another. Please don't include that one.

2. error messages
a) please use ereport() not elog()
b) conform to style guidelines: errmsg() start with lowercase,
others are complete phrases (start with uppercase, end with period)
c) replace
"The type you was trying to transform can't be represented in
JSONB" maybe with
errmsg("could not transform to type \"%s\"", "jsonb"),
errdetail("The type you are trying to transform can't be
represented in JSON") d) same errmsg() for the other error; figure
out suitable errdetail.

3. whitespace: don't add newlines to while, DirectFunctionCallN,
pnstrdup.

4. the "relocatability" test seems pointless to me.

5. "#undef _" looks bogus. Don't do it.

Hello,
thank you for your time.

1. I really think that it might be a good practice to test non ASCII
symbols on platforms where it is possible. Maybe locale-dependent
Makefile? I've already spent pretty much time trying to find possible
solutions and I have no results. So, I've deleted this tests. Maybe
there is a better solution I don't know about?

2. Thank you for this one. Writing those errors were really pain for
me. I've changed those things in new patch.

3. I've fixed all the whitespaces you was talking about in new version
of the patch.

4. The relocatibility test is needed in order to check if patch is
still relocatable. With this test I've tried to prove the code
"relocatable=true" in *.control files. So, I've decided to leave them
in next version of the patch.

5. If I delete #undef _, I will get the warning:
/usr/lib/x86_64-linux-gnu/perl/5.22/CORE/config.h:3094:0:
warning: "_" redefined #define _(args) args

In file included from ../../src/include/postgres.h:47:0,
from jsonb_plperl.c:12:
../../src/include/c.h:971:0: note: this is the location of the
previous definition #define _(x) gettext(x)
This #undef was meant to fix the warning. I hope a new comment next
to #undef contains all the explanations needed.

Please, find a new version of the patch in attachments to this message.

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#19Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Anthony Bykov (#18)
Re: Transform for pl/perl

On Thu, 7 Dec 2017 12:54:55 +0300
Anthony Bykov <a.bykov@postgrespro.ru> wrote:

On Fri, 1 Dec 2017 15:49:21 -0300
Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

A few very minor comments while quickly paging through:

1. non-ASCII tests are going to cause problems in one platform or
another. Please don't include that one.

2. error messages
a) please use ereport() not elog()
b) conform to style guidelines: errmsg() start with lowercase,
others are complete phrases (start with uppercase, end with period)
c) replace
"The type you was trying to transform can't be represented in
JSONB" maybe with
errmsg("could not transform to type \"%s\"", "jsonb"),
errdetail("The type you are trying to transform can't be
represented in JSON") d) same errmsg() for the other error; figure
out suitable errdetail.

3. whitespace: don't add newlines to while, DirectFunctionCallN,
pnstrdup.

4. the "relocatability" test seems pointless to me.

5. "#undef _" looks bogus. Don't do it.

Hello,
thank you for your time.

1. I really think that it might be a good practice to test non ASCII
symbols on platforms where it is possible. Maybe locale-dependent
Makefile? I've already spent pretty much time trying to find
possible solutions and I have no results. So, I've deleted this
tests. Maybe there is a better solution I don't know about?

2. Thank you for this one. Writing those errors were really pain for
me. I've changed those things in new patch.

3. I've fixed all the whitespaces you was talking about in new version
of the patch.

4. The relocatibility test is needed in order to check if patch is
still relocatable. With this test I've tried to prove the code
"relocatable=true" in *.control files. So, I've decided to leave
them in next version of the patch.

5. If I delete #undef _, I will get the warning:
/usr/lib/x86_64-linux-gnu/perl/5.22/CORE/config.h:3094:0:
warning: "_" redefined #define _(args) args

In file included from ../../src/include/postgres.h:47:0,
from jsonb_plperl.c:12:
../../src/include/c.h:971:0: note: this is the location of the
previous definition #define _(x) gettext(x)
This #undef was meant to fix the warning. I hope a new comment next
to #undef contains all the explanations needed.

Please, find a new version of the patch in attachments to this
message.

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Forgot the patch.

--
Anthony Bykov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachments:

0001-jsonb_plperl-extension-v5.patchtext/x-patchDownload+1162-2
#20Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#15)
Re: Transform for pl/perl

On 12/1/17 13:15, Tom Lane wrote:

Robert Haas <robertmhaas@gmail.com> writes:

On Fri, Dec 1, 2017 at 12:30 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

Patch moved to CF 2018-01. Perhaps a committer will look at it at some point.

FWIW, although I like the idea, I'm not going to work on the patch. I
like Perl, but I neither know its internals nor use plperl. I hope
someone else will be interested.

I've been assuming (and I imagine other committers think likewise) that
Peter will pick this up at some point, since the whole transform feature
was his work to begin with. If he doesn't want to touch it, maybe he
should say so explicitly so that other people will feel free to take it.

I'll take a look.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

#21Thomas Munro
thomas.munro@gmail.com
In reply to: Anthony Bykov (#19)
#22Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Thomas Munro (#21)
#23Andrew Dunstan
andrew@dunslane.net
In reply to: Anthony Bykov (#22)
#24Thomas Munro
thomas.munro@gmail.com
In reply to: Anthony Bykov (#22)
#25Arthur Zakirov
a.zakirov@postgrespro.ru
In reply to: Anthony Bykov (#22)
#26Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Andrew Dunstan (#23)
#27Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Arthur Zakirov (#25)
#28Pavel Stehule
pavel.stehule@gmail.com
In reply to: Anthony Bykov (#27)
#29Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Pavel Stehule (#28)
#30Pavel Stehule
pavel.stehule@gmail.com
In reply to: Anthony Bykov (#29)
#31Nikita Glukhov
n.gluhov@postgrespro.ru
In reply to: Pavel Stehule (#30)
#32Pavel Stehule
pavel.stehule@gmail.com
In reply to: Nikita Glukhov (#31)
#33Peter Eisentraut
peter_e@gmx.net
In reply to: Pavel Stehule (#32)
In reply to: Peter Eisentraut (#33)
#35Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dagfinn Ilmari Mannsåker (#34)
In reply to: Tom Lane (#35)
#37Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dagfinn Ilmari Mannsåker (#36)
In reply to: Tom Lane (#37)
#39Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dagfinn Ilmari Mannsåker (#38)
In reply to: Tom Lane (#39)
In reply to: Dagfinn Ilmari Mannsåker (#40)
#42Peter Eisentraut
peter_e@gmx.net
In reply to: Dagfinn Ilmari Mannsåker (#38)
#43Peter Eisentraut
peter_e@gmx.net
In reply to: Dagfinn Ilmari Mannsåker (#41)
#44Andrew Dunstan
andrew@dunslane.net
In reply to: Peter Eisentraut (#43)
#45Peter Eisentraut
peter_e@gmx.net
In reply to: Andrew Dunstan (#44)
#46Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#45)
#47Peter Eisentraut
peter_e@gmx.net
In reply to: Tom Lane (#46)
#48Peter Eisentraut
peter_e@gmx.net
In reply to: Dagfinn Ilmari Mannsåker (#38)
In reply to: Peter Eisentraut (#48)
#50Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Dagfinn Ilmari Mannsåker (#49)
#51Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#50)
#52Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#50)
#53Anthony Bykov
a.bykov@postgrespro.ru
In reply to: Dagfinn Ilmari Mannsåker (#49)
#54Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Peter Eisentraut (#52)
#55Peter Eisentraut
peter_e@gmx.net
In reply to: Alvaro Herrera (#54)
In reply to: Peter Eisentraut (#55)
#57Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dagfinn Ilmari Mannsåker (#56)
#58Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#57)
#59Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#58)
#60Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#59)
#61Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dagfinn Ilmari Mannsåker (#56)
#62Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tom Lane (#61)