Normalize `Numeric` (No scale or precision) Values
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start in the pg-clickhouse-c code that reads tuples: pgch__read_tuple() and pgch_read_value(), down to pgch__read_decimal(), and compare the regression outputs in test/expected/aggregates.out and aggregates_2.out. Done means a precision-free NUMERIC result drops trailing zeros the way Postgres does, via numeric_normalize, while the Decimal(76, 38) path and its precision stay unchanged. Check the tests still pass for both expected files.
Written by the indexing model from the issue text.
Description
#396 demonstrates how round(numeric) when pushed down returns the full 38 decimal places of precision with trailing zeros, while when run in Postgres it omits the trailing zeros:
Compare the output of
round(regr_syy(b, a)::numeric, 4)intest/expected/aggregates.out, where it pushes down:68756.21570000000000000000000000000000000000To
test/expected/aggregates_2.out, where it does not:68756.2157
It remains accurate of course, but somewhat unexpected relative to Postgres. This happens because Postgres numeric has a display scale but we don't set it. IOW, we see all the zeros because we've mapped numeric to Decimal(76, 38) and pg-clickhouse-c thus decides it's NUMERIC(76, 38).
We need a way to normalize such values without actually losing precision. Thus, when pg_clickhouse handles NUMERIC without scale or precision, we need to convert the value returned from ClickHouse to the normalized value.
Perhaps we should apply numeric_normalize?
This should happen only for precision-free NUMERIC. We have to track that we've told ClickHouse that it's Decimal(76, 38) and treat it as numeric when the output type has no precision.
My guess? We need to pass the target Postgres data type (OID and typdef; neither seems to be there now --- add to chc_type?) to pgch_read_value() (and from there to pgch__read_decimal()) in pgch__read_tuple() in pg-clickhouse-c. Then have pgch__read_decimal() apply numeric_normalize when the datum has no precision.
- Dominant language
- C
- Stars
- 294
- Forks
- 23
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 37
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ClickHouse/pg_clickhouse
-
documentation drivers enhancement
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
ClickHouse/pg_clickhouse#383 · 1 comment ·
Maintainers usually reply within 1 day
-
Pushed-down concat_ws() returns NULL when any value is NULLPossibly taken @RaphaelFakhri claimed this 12 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
ClickHouse/pg_clickhouse#444 ·
Maintainers usually reply within 1 day
-
functions pushdown
Difficulty 4/5 3-5 days Newbie friendliness 30/100
ClickHouse/pg_clickhouse#409 · 1 comment ·
Maintainers usually reply within 1 day
-
Drop HTTP driverOpendrivers
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ClickHouse/pg_clickhouse#391 ·
Maintainers usually reply within 1 day
-
enhancement pushdown sql
Difficulty 5/5 Over a week Newbie friendliness 35/100
ClickHouse/pg_clickhouse#387 ·
Maintainers usually reply within 1 day
All issues in ClickHouse/pg_clickhouse
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cyrusimap/cyrus-imapd#6640 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 60/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
GalusPeres/HomeTiles#139 · 1 comment ·
Maintainers usually reply within 3 days
-
Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
apache/nuttx-apps#3942 ·
Maintainers usually reply within 1 day
-
coders/mat.c: ReadMATImageV4 leaves a trailing 0x0 frame, so converting a valid level-4 .mat failsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ImageMagick/ImageMagick#9077 ·
Maintainers usually reply within 1 day