Re: custom function for converting human readable sizes to bytes
Vitaly Burovoy <vitaly.burovoy@gmail.com>
From: Vitaly Burovoy <vitaly.burovoy@gmail.com>
To: Pavel Stehule <pavel.stehule@gmail.com>
Cc: "Shulgin, Oleksandr" <oleksandr.shulgin@zalando.de>,
Robert Haas <robertmhaas@gmail.com>,
Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>,
Alvaro Herrera <alvherre@2ndquadrant.com>,
Tom Lane <tgl@sss.pgh.pa.us>, Jim Nasby <Jim.Nasby@bluetreble.com>,
Corey Huinker <corey.huinker@gmail.com>,
Guillaume Lelarge <guillaume@lelarge.info>,
PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2016-01-31T04:24:38Z
Lists: pgsql-hackers
Hello,Pavel!
On 1/26/16, Pavel Stehule <pavel.stehule@gmail.com> wrote:
> I am grateful for review - now this patch is better, and I hope near final
> stage.
>
> Regards
> Pavel
I'm pretty sure we are close to it.
Now besides a code design I mentioned[1] before (and no one has
answered me about it), there are a few small notes.
Now you have all messages in one style ("invalid size: \"%s\"") except
size units ("invalid unit \"%s\", there are two places). I guess
according to the Error Style Guide[2] it should be like
"errmsg("invalid size: \"%s\"", str), errdetail("Invalid size unit
\"%s\"", unitstr),".
If it is not hard for you, it'll look better if "select" is uppercased
in tests and a comment about sharing "memory_unit_conversion_table" is
close to the "SELECT pg_size_bytes('1PB');". Moreover your comment has
a flaw: "pg_size_pretty" doesn't use that array at all, so the phrase
"These functions shares" is wrong.
Also I've just found that numeric format supports values with exponent
like "1e5" which is not allowed in pg_size_bytes. I guess the phrase
"The format is numeric with an optional size unit" should be replaced
to "The format is a fixed point number with an optional size unit" in
the documentation.
Have a look for a formatting: in the rows "num = DatumGetNumeric",
"mul_num = DatumGetNumeric", "num = DatumGetNumeric" and in error
reporting close to the "/* only alphabetic character are allowed */"
parameters in the next lines are not under the first parameters.
I insist there is no reason to call "pfree" for "str" and "buffer".
But if you do so, clean up also buffers from numeric_in, numeric_mul
and int8_numeric. If you insist it should be left as is, I leave that
decision to a committer.
P.S.: Have you thought to wrap the call "numeric_in" by a
PG_TRY/PG_CATCH instead of checking for correctness by yourself?
[1]http://www.postgresql.org/message-id/CAKOSWNm+SSgGKYsv09n_6HhfWzmRr+cSjpgfhBPFf5nNPfJ5JQ@mail.gmail.com
[2]http://www.postgresql.org/docs/devel/static/error-style-guide.html#AEN111165
--
Best regards,
Vitaly Burovoy
Commits
-
Add pg_size_bytes() to parse human-readable size strings.
- 53874c5228fe 9.6.0 landed
-
Refactor check_functional_grouping() to use get_primary_key_attnos().
- f144f73242ac 9.6.0 cited
-
Correct comment in GetConflictingVirtualXIDs()
- 1129c2b0ad27 9.6.0 cited
-
Make extract() do something more reasonable with infinite datetimes.
- 647d87c56ab6 9.6.0 cited
-
pg_size_pretty: Format negative values similar to positive ones.
- 8a1fab36aba7 9.6.0 cited
-
pg_size_pretty(numeric)
- 4a2d7ad76f5f 9.2.0 cited