Skip to content

[u]int64_t parameters; decimal->number cast removed in favor of original textual representation - #28

Open
parihaaraka wants to merge 6 commits into
tarantool:masterfrom
parihaaraka:master
Open

[u]int64_t parameters; decimal->number cast removed in favor of original textual representation#28
parihaaraka wants to merge 6 commits into
tarantool:masterfrom
parihaaraka:master

Conversation

@parihaaraka

Copy link
Copy Markdown

No description provided.

@ligurio

ligurio commented Mar 25, 2022

Copy link
Copy Markdown
Member

Patch breaks tests:

Log
sergeyb@pony:~/sources/MRG/pg$ git describe 2.0.2-7-g4043e43
sergeyb@pony:~/sources/MRG/pg$ curl -O https://patch-diff.githubusercontent.com/raw/tarantool/pg/pull/28.patch
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1694 0 1694 0 0 3948 0 --:--:-- --:--:-- --:--:-- 3948
sergeyb@pony:~/sources/MRG/pg$ patch -p1 < 28.patch patching file pg/driver.c
sergeyb@pony:~/sources/MRG/pg$ make
[100%] Built target driver
sergeyb@pony:~/sources/MRG/pg$ tarantool --version
Tarantool 2.8.3-0-g01023dbc2
sergeyb@pony:~/sources/MRG/pg$ pg_config --version
PostgreSQL 14.2 (Ubuntu 14.2-1.pgdg20.04+1)
sergeyb@pony:~/sources/MRG/pg$ sudo -u postgres tarantool test/pg.test.lua
TAP version 13
# connection old api
1..15
ok - connection
ok - ping
ok - SELECT 123::text AS bla, 345
ok - SELECT -1 AS neg, NULL AS abc
not ok - SELECT -1.1 AS neg, 1.2 AS pos
---
path: //1/1/1/neg
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: -1.1
got: '-1.1'
...
not ok - SELECT ARRAY[1,2] AS arr, 1.2 AS pos
---
path: //1/1/1/pos
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 1.2
got: '1.2'
...
ok - SELECT $1 AS val % ["abc"]
not ok - SELECT $1 AS val % [123]
---
path: //1/1/1/val
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 123
got: '123'
...
ok - SELECT $1 AS val % [true]
ok - SELECT $1 AS val % [false]
not ok - SELECT $1 AS val, $2 AS num, $3 AS str % [false,123,"abc"]
---
path: //1/1/1/num
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 123
got: '123'
...
ok - SELECT * FROM (VALUES (1,2), (2,3)) t
# tx
1..7
ok - begin
ok - SELECT * FROM _tx_test
ok - roolback
ok - SELECT * FROM _tx_test
ok - begin
ok - commit
ok - SELECT * FROM _tx_test
# tx: end
ok - tx
# numeric string binding
1..1
ok - SELECT TEST1_REQUESTID FROM TEST1;# numeric string binding: end
ok - numeric string binding
ok - error
# connection old api: end# failed subtest: 4
TAP version 13
# connection old api via pool
1..15
ok - connection
ok - ping
ok - SELECT 123::text AS bla, 345
ok - SELECT -1 AS neg, NULL AS abc
not ok - SELECT -1.1 AS neg, 1.2 AS pos
---
path: //1/1/1/neg
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: -1.1
got: '-1.1'
...
not ok - SELECT ARRAY[1,2] AS arr, 1.2 AS pos
---
path: //1/1/1/pos
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 1.2
got: '1.2'
...
ok - SELECT $1 AS val % ["abc"]
not ok - SELECT $1 AS val % [123]
---
path: //1/1/1/val
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 123
got: '123'
...
ok - SELECT $1 AS val % [true]
ok - SELECT $1 AS val % [false]
not ok - SELECT $1 AS val, $2 AS num, $3 AS str % [false,123,"abc"]
---
path: //1/1/1/num
line: 0
strict: false
filename: test/pg.test.lua
trace:
- line: 26
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: method
name: q
src: test/pg.test.lua
- line: 22
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: Lua
namewhat: local
name: fun
src: test/pg.test.lua
- line: 218
source: '@builtin/tap.lua'
filename: builtin/tap.lua
what: Lua
namewhat: field
name: test
src: builtin/tap.lua
- line: 0
source: '@test/pg.test.lua'
filename: test/pg.test.lua
what: main
namewhat: src: test/pg.test.lua
expected: 123
got: '123'
...
ok - SELECT * FROM (VALUES (1,2), (2,3)) t
# tx
1..7
ok - begin
ok - SELECT * FROM _tx_test
ok - roolback
ok - SELECT * FROM _tx_test
ok - begin
ok - commit
ok - SELECT * FROM _tx_test
# tx: end
ok - tx
# numeric string binding
1..1
ok - SELECT TEST1_REQUESTID FROM TEST1;# numeric string binding: end
ok - numeric string binding
ok - error
# connection old api via pool: end# failed subtest: 4
TAP version 13
# test collection connections
1..1
ok - gc connections
# test collection connections: end
TAP version 13
# connection concurrent
1..1
ok - concurrent connections
# connection concurrent: end
TAP version 13
# int64
1..1
ok - int64 test# int64: end

@parihaaraka

Copy link
Copy Markdown
Author

Patch breaks tests:

Because client-side decimal->number cast is a faulty one. Take a look at Qt's NumericalPrecisionPolicy. If a user has no choice then we should preserve original precision.

@ligurio

Copy link
Copy Markdown
Member

Patch breaks tests:
Because client-side decimal->number cast is a faulty one.

Patch cannot be merged if it makes CI red. Please fix tests.

@Totktonada

Copy link
Copy Markdown
Contributor

Thanks for the patch!

The idea looks right for me. My doubts are about backward compatibility. I would prefer a safe way and keep everything as before if no new options are passed. So existing applications will not need to update its code if everything works for them. We'll suggest to enable the new (more correct) behaviour in README and release notes, but we should not make it the only option.

I see that (comparing to the first version) you added ability to pass an option, but:

  1. It changes :execute() arguments order. So the old code will need to be updated anyway. I would add an opts table argument at the end and make it optional. As the side good effect: we'll not need so much arguments and will able to add more options later.
  2. Ideally I would add the options as on the connection level as well as on the request level. It is how, for example, our json encoder works: you can configure an instance or pass option to particular json.encode() / json.decode() call.
  3. The idea with type decoding hook is interesting. I don't mind to add it (so a user will able to get decimal value in tarantool, that's nice), but I'm not sure that we'll keep such API if more type related works will be planned (IOW, it is possible that we'll deprecate it after a half of the year).

Also I would split the changes into two commits (one regarding numeric decoding, one about cdata numbers encoding), because now it is not quite obvious what actually is changed.

@parihaaraka

Copy link
Copy Markdown
Author

It changes :execute() arguments order. So the old code will need to be updated anyway.

No, this is not connection's execute() - it's internal one. Everything is absolutely backward compatible. Previous behaviour is the default one.

@Totktonada

Copy link
Copy Markdown
Contributor

NB: link #26, check whether we should copy the static buffer before passing it to libpq (in binding parameters handling)

@parihaaraka

Copy link
Copy Markdown
Author

@Totktonada Ъ?

@Totktonada

Copy link
Copy Markdown
Contributor

Sorry, I'm on finishing my current quarter tasks. Hopefully I'll end on this week.

@ligurio
ligurio self-requested a review July 11, 2022 10:12
[REMOVE BEFORE MERGE] Changes proposed in fixup commit: documentation,
regression tests, code style.
Patch adds support of PostgreSQL decimal numbers - it is possible to
choose a Lua/Tarantool type that will be used for casting values with
NUMERIC type [1]. By default Lua "number" type is used, the same
behaviour was used before changes. Additionally user could choose two
other types: Lua "string" and Tarantool's decimal type [2], [3].
Fixestarantool#26Fixestarantool#25
1. https://www.postgresql.org/docs/current/datatype-oid.html
2. https://www.tarantool.io/en/doc/latest/reference/reference_lua/decimal/
3. https://www.tarantool.io/en/doc/latest/book/box/data_model/#data-types
Co-authored-by: Sergey Bronnikov <sergeyb@tarantool.org>
@TotktonadaTotktonada self-assigned this Feb 3, 2023
@ligurio
ligurio removed their request for review June 6, 2023 13:26
@parihaaraka

Copy link
Copy Markdown
Author

@Totktonada Ъ?

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@parihaaraka@ligurio@Totktonada