Skip to content

Add a setting to force print decimal point in text formats when printing floats - #62614

Merged
alexey-milovidov merged 16 commits into
masterfrom
approximate_number_force_period
Jun 16, 2026
Merged

alexey-milovidov merged 16 commits into
masterfrom
approximate_number_force_period

Conversation

@qoega

@qoega qoega commented Apr 12, 2024 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Added a setting output_format_always_write_decimal_point_in_float_and_decimal to always print a decimal point for floating-point and Decimal numbers in text formats, even when the value is a whole number. For example, output 1. instead of 1. Disabled by default.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/


Modify your CI run:

NOTE: If your merge the PR with modified CI you MUST KNOW what you are doing
NOTE: Checked options will be applied if set before CI RunConfig/PrepareRunConfig step

Include tests (required builds will be added automatically):

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with Analyzer
  • Add your option here

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Performance tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All with Aarch64
  • Add your option here

Extra options:

  • do not test (only style check)
  • disable merge-commit (no merge from master before tests)
  • disable CI cache (job reuse)

Only specified batches in multi-batch jobs:

  • 1
  • 2
  • 3
  • 4

Version info

  • Merged into: 26.6.1.840

@CLAassistant

CLAassistant commented Apr 12, 2024 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-feature Pull request with new product feature label Apr 12, 2024
Comment thread src/Functions/FunctionsJSON.h Resolved
Comment thread src/Core/Settings.h Resolved
Comment thread src/IO/WriteHelpers.h Resolved

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see often when it is called "period".
"Decimal point" is more common.

@alexey-milovidov alexey-milovidov self-assigned this Dec 29, 2024
@alexey-milovidov

Copy link
Copy Markdown
Member

It should apply to Decimal as well.

@alexey-milovidov alexey-milovidov changed the title Add a setting to force print period in text formats when printing floats Add a setting to force print decimal point in text formats when printing floats Jan 2, 2025
@clickhouse-gh

clickhouse-gh Bot commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

Dear @alexey-milovidov, this PR hasn't been updated for a while. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

alexey-milovidov and others added 2 commits June 3, 2026 17:52
…force_period

# Conflicts:
#	src/Core/Settings.h
#	src/Formats/FormatFactory.cpp
#	src/Formats/FormatSettings.h
#	src/Functions/FunctionsJSON.h
#	src/IO/WriteHelpers.h
… to Decimal

This completes the `output_format_approximate_numbers_with_decimal_point`
setting after merging `master`:

- Move the float fast-path logic to the rewritten `writeFloatTextFastPath`
  in `WriteHelpers.cpp`, threading `force_decimal_point` through all of its
  integer-producing branches. The earlier draft only handled the two
  `isIntegerInRepresentableRange` branches and appended the point at the
  wrong offset (`buffer[1]` instead of the end); both are fixed here, and
  the rounding fast paths (`writeFloatTextFastPathFloat64Rounded` /
  `...Float32Rounded`) now also emit the point for large whole-number floats.
  Special values (`inf`/`nan`) and fractional/scientific outputs go through
  the `zmij` branch and are never affected.

- Declare the setting in `FormatFactorySettings.h` (its modern location) with
  a clearer description, and register it in `SettingsChangesHistory.cpp`.

- Apply the setting to `Decimal` as well, per review feedback: a whole-number
  Decimal value now prints a trailing decimal point when no fractional digits
  are written.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bdcaa74]

Summary: ✅


AI Review

Summary

This PR adds output_format_always_write_decimal_point_in_float_and_decimal, threads it through FormatSettings, and updates serializeText paths so whole-valued floating-point and Decimal outputs can keep a decimal point without changing JSON number output. I did not find any unresolved correctness, compatibility, or safety issue in the current diff; the earlier JSON validity, large-float, changelog, and output_format_float_precision coverage comments are addressed in the current head.

Final Verdict

Status: ✅ Approve

alexey-milovidov and others added 3 commits June 6, 2026 08:53
`SerializationDecimal::serializeTextJSON` delegated to `serializeText`,
so `output_format_approximate_numbers_with_decimal_point` also affected
JSON `Decimal` output. With the default `output_format_json_quote_decimals = 0`,
`SELECT 1::Decimal(10, 2) FORMAT JSONEachRow` would emit a bare `1.`,
which is not a valid JSON number.

Inline the value serialization in `serializeTextJSON` without forcing the
decimal point, mirroring `SerializationNumber::serializeTextJSON` which goes
through `writeJSONNumber` and never forces the point either. Extend the test
with JSON regression cases for both quoted and unquoted `Decimal` output.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The feature-docs CI hook accepts a `*Settings.cpp` change containing the
settings-declaration macro as documentation for a new feature, because the
autogenerated settings docs are produced from the embedded `DECLARE(...)`
description strings. Format settings, however, are declared in the header
`FormatFactorySettings.h`, which the suffix rule does not cover, so adding a
new format setting failed the check even though it carries an embedded
description string. List the header explicitly alongside `ProfileEvents.cpp`
and `CurrentMetrics.cpp`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…force_period

# Conflicts:
#	src/Core/FormatFactorySettings.h
#	src/DataTypes/Serializations/SerializationNumber.cpp
#	src/Formats/FormatFactory.cpp
#	src/Formats/FormatSettings.h
#	src/IO/WriteHelpers.cpp
@alexey-milovidov

Copy link
Copy Markdown
Member

Picked this up via /continue-pr.

Merged master (721 behind) and resolved a non-trivial semantic conflict. Master had meanwhile added output_format_float_precision, which:

  • introduced a new out-of-line writeFloatText(x, buf, const FormatSettings &) overload, and
  • routed both SerializationNumber::serializeText and writeJSONNumber (JSON floats) through it.

I integrated output_format_approximate_numbers_with_decimal_point so the two features compose: force_decimal_point is threaded into that overload as an explicit parameter defaulting to false (not read from settings), so JSON float output is never forced (a bare 1. would be invalid JSON), while the text path passes it through. A small helper centralizes appending the forced point across all of the precision overload's emit sites, including the rounding and scientific-notation fallbacks.

Addressed the review thread about JSON Decimal output: SerializationDecimal::serializeTextJSON no longer forces the point, mirroring the float JSON path. Added JSON regression cases.

CI:

  • Finish Workflow / feature_docs.py — was the only real failure (new-feature PR with no recognized doc change). master independently fixed feature_docs.py to recognize *Settings.h with the DECLARE(...) macro, which now covers FormatFactorySettings.h where the setting's embedded description lives; the merge picks this up.
  • Stress test (arm_release) / Hung check and BuzzHouse / Distributed task iterator is not initialized (STID 4662-4342) — both recur on master (pull_request_number = 0) and across many unrelated PRs in the CI DB; pre-existing flakies, unrelated to a float/decimal formatting setting.

Built clean and verified locally: 04309_approximate_numbers_with_decimal_point matches its reference, and the force × float_precision and JSON-safety interactions all behave correctly (e.g. {"f":1} for forced JSON floats, 1./-5. for whole-number text output).

Comment thread src/IO/WriteHelpers.cpp Resolved
alexey-milovidov and others added 2 commits June 8, 2026 05:46
…entation path

`force_decimal_point` previously fired only for the `itoa`-based fast paths
in `writeFloatTextFastPath`, tracked via an `integer_representation` flag. But
the `zmij` shortest-representation branch can also emit a bare integer for
large magnitudes outside the itoa ranges, e.g. `toFloat32(1.23e20)` ->
`123000000000000000000`. Such values kept `integer_representation = false` and
so missed the forced trailing decimal point.

Replace the branch-tracking flag with the same byte-scan predicate already
used by the `output_format_float_precision` path: append `.` only when the
emitted representation contains no `.`, `e`, or `E`, guarded by `isFinite` so
`inf`/`nan` are left untouched. Add a regression for large `Float32`/`Float64`
values printed through the shortest-representation path.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Continued via /continue-pr.

Merged master (413 behind) — clean, no conflicts. Master had not touched WriteHelpers, SerializationNumber, or SerializationDecimal since the last merge, so the feature's integration with output_format_float_precision and the JSON-safety handling are intact. The SettingsChangesHistory entry remains in the latest unreleased version block.

Fixed the open Bugbot thread (513fdb64f4b). force_decimal_point previously fired only for the itoa fast paths via an integer_representation flag, so a bare integer emitted by the zmij shortest-representation branch for large magnitudes (e.g. toFloat32(1.23e20) -> 123000000000000000000) missed the forced point. Replaced the flag with the same byte-scan predicate the precision path uses (append . only when there is no ./e/E), guarded by isFinite so inf/nan stay untouched. Added a regression for large Float32/Float64 values.

Built clean; 04309_approximate_numbers_with_decimal_point and 03400_output_format_float_precision both pass locally.

alexey-milovidov and others added 2 commits June 9, 2026 18:23
…master

The test number 04309 was taken by 04309_distributed_aggregation_persisted_exchange
and 04309_explain_insert_format on master.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master into the branch (it was 568 commits behind) — clean merge, no conflicts.

Renumbered the test 04309_approximate_numbers_with_decimal_point -> 04327_…: the 04309 prefix had been taken on master by 04309_distributed_aggregation_persisted_exchange and 04309_explain_insert_format.

Rebuilt and verified the feature end-to-end against the fresh binary — all reference cases pass, including the special-value (inf/nan), shortest-representation large-integer (toFloat32(1.23e20) -> 123000000000000000000.), Decimal, and JSON-validity cases.

The only red was Tests/04033_tpc_ds_q11 (Stateless, arm_asan_ubsan). This is unrelated to the change: the test is tagged no-random-settings so output_format_approximate_numbers_with_decimal_point is never randomized into it, the setting is disabled by default, and the query returns only string columns (no float/Decimal output the setting could touch). It is a one-off resource/timeout flake of a heavy 4-way self-join on the slowest CI configuration.

@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master into the branch to resolve the conflict (no file conflicts, and no changes on master touched the files modified by this PR).

Analysis of the CI failures on the previous run (bf7b0ec) — all unrelated to this PR (which only changes float/Decimal text output behind a disabled-by-default setting):

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=62614&sha=bf7b0ecfcdf3719e6017cf449092bcf6959986b1&name_0=PR&name_1=BuzzHouse%20%28arm_asan_ubsan%29 (UBSan null pointer in ASTSelectQuery::formatImpl via logQueryStart from DistributedPlanExecutor) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov investigated. This BuzzHouse UBSan trap (STID 2791-2e42) is a deterministic trunk bug, not fuzzer AST corruption, and your read is correct: it pre-exists on master and is unrelated to this PR.

Root cause: DistributedPlanExecutor::doExecuteTask built an empty make_intrusive<ASTSelectQuery>() stub (the /// FIXME: this is only used to populate query_kind line) and passed it to logQueryStart. An empty ASTSelectQuery has no select expression list, so with log_formatted_queries=1, logQueryStart formats it and ASTSelectQuery::formatImpl (ASTSelectQuery.cpp:104) calls select()->format(), a member call on a null IAST (the UBSan trap). The path is the local distributed-plan task executor (make_distributed_plan + distributed_plan_execute_locally), which BuzzHouse exercises.

Fix status: I opened a separate fix PR #107079 (replace the empty stub with a null ASTPtr; the logQuery* paths already default query_kind to Select when the AST is null, plus a regression test). It is now closed as obsolete: PR #107122 (revert of #106020 "Multistage distributed queries", merged 2026-06-11 01:37 UTC) deleted DistributedPlanExecutor.cpp from master entirely, so the crash path no longer exists. CIDB shows zero hits of this signature on master after that merge.

For this PR: re-merging current master (which you have done) picks up the removal, so the BuzzHouse UBSan will not recur here. Forward guard if #106020 ever re-lands: doExecuteTask must pass a null ASTPtr, not an empty ASTSelectQuery stub.

@alexey-milovidov

Copy link
Copy Markdown
Member

Continued via /continue-pr.

The branch is up to date (merge-base with master is from yesterday, < 1 week old) and has no unresolved review threads, so nothing was pushed. Analysis of the CI failures on the current run (d0242bf0) — all unrelated to this PR, which only changes float/Decimal text output behind a disabled-by-default setting:

  • Stateless tests (arm_asan_ubsan, azure, parallel) — 01852_map_combinator, 00091_union_race_conditions_2, 03100_lwu_29_concurrent_merges: all three failed with the identical Code: 159 ... Timeout exceeded: elapsed 60xxx ms, maximum: 60000 ms (TIMEOUT_EXCEEDED) signature on this slow ASan+UBSan+Azure+parallel config. 01852_map_combinator is the only failure of that test across all PRs in 14 days and its reproducibility check passed (0/3 reruns failed). 00091_union_race_conditions_2 and 03100_lwu_29_concurrent_merges fail across many unrelated PRs. Runner-overload timeout flakes.
  • Stress test (arm_debug) — Hung check failed, possible deadlock found: the lldb backtrace itself timed out after 30 s. Known broad infra/flake class (266 failures across 81 PRs in the last 14 days).
  • BuzzHouse (arm_asan_ubsan) — Logical error: Mutation of Memory table produced incomplete output (STID: 2380-3043): known trunk issue, 85 failures across 68 PRs in 14 days.

Re-ran the failed jobs to clear the timeout flakes.

@alexey-milovidov

Copy link
Copy Markdown
Member

Continued via /continue-pr.

Merged master (1042 behind) to resolve a new conflict. GitHub had flagged the branch as CONFLICTING; the conflict was in SettingsChangesHistory.cpp and git's recursive merge resolved it cleanly (the new setting line landed in the current version block). The only master changes touching this PR's source files since the prior merge-base were the additive Pretty non-breaking-space padding settings in FormatSettings.h/FormatFactorySettings.h — they don't touch the float/Decimal text-write path or any API this PR uses, and merged without overlap. The PR diff is unchanged (same 10 files, +150/-43).

All 5 review threads are resolved and the previous CI run was fully green (141 passed, 0 failed). Fresh CI will run on the re-merged head cd309070c67.

@alexey-milovidov alexey-milovidov self-assigned this Jun 14, 2026
Comment thread src/Core/FormatFactorySettings.h Resolved
Comment thread src/IO/WriteHelpers.cpp Resolved
Comment thread src/IO/WriteHelpers.cpp Resolved

@alexey-milovidov alexey-milovidov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the two changes:

  • setting name;
  • suboptimal memchr;

all LGTM.

@alexey-milovidov

Copy link
Copy Markdown
Member

@qoega, you made a commit from "Ubuntu" instead of your real name. We will need to rewrite it and do push -f.

alexey-milovidov and others added 2 commits June 14, 2026 15:20
…point_in_float_and_decimal

The previous name `output_format_approximate_numbers_with_decimal_point`
was misleading: the values being formatted are not approximate, and
`Decimal` numbers in particular are precise. Rename the setting to
`output_format_always_write_decimal_point_in_float_and_decimal`, which
describes exactly what it does, and rename the corresponding
`FormatSettings` field to `always_write_decimal_point_in_float_and_decimal`.

The setting has not been released yet, so the `SettingsChangesHistory`
entry is renamed in place rather than aliased. The stateless test is
renamed accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When `output_format_always_write_decimal_point_in_float_and_decimal` is
enabled, the float-formatting fast path checked whether the produced text
already contained a `.`, `e`, or `E` before appending a trailing decimal
point. This used three separate `memchr` calls, each rescanning the whole
buffer. Replace them with a single `find_first_symbols<'.', 'e', 'E'>`
scan in both places (the `writeFloatTextFastPath` integer path and the
`write_representation` lambda on the precision path), matching the value
against the end pointer.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov force-pushed the approximate_number_force_period branch from 99ab8af to 860fbe7 Compare June 14, 2026 15:27
Comment thread src/Core/FormatFactorySettings.h Resolved
… in the test

The regression test for `output_format_always_write_decimal_point_in_float_and_decimal`
only exercised the default `output_format_float_precision = 0` fast path. The
precision path in `writeFloatText` appends the forced decimal point in a separate
place (the `write_representation` lambda), and `ToFixed` can strip a value down to a
bare integer before that point is applied.

Added three cases with both settings enabled:
- a whole-valued `Float64` printed via the shortest representation -> `1.`;
- a value that rounds to a whole number at the requested precision, so `ToFixed`
  strips it to a bare integer -> `2.` (this is the case the forced point must cover);
- a fractional value formatted through `ToFixed` -> unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.90% 84.90% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.30% 77.30% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 97/97 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jun 16, 2026
Merged via the queue into master with commit 94e91fc Jun 16, 2026
326 of 328 checks passed
@alexey-milovidov
alexey-milovidov deleted the approximate_number_force_period branch June 16, 2026 01:02
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 16, 2026
alexey-milovidov added a commit that referenced this pull request Jun 18, 2026
The branch was 1106 commits behind master (merge base 2026-06-14) and CI
was red only on known master-wide flakes; merging to refresh CI against
current master. The merge is textually clean: master's touches to the
shared format files are additive (the embedded-format-documentation
refactor in #106181 adds an optional setDocumentation API without changing
the registration signatures, plus the new
output_format_always_write_decimal_point_in_float_and_decimal setting from
#62614), and the native Arrow IPC code under ArrowIPC/ is untouched by
master.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The branch was 1106 commits behind master (merge base 2026-06-14) and CI
was red only on known master-wide flakes; merging to refresh CI against
current master. The merge is textually clean: master's touches to the
shared format files are additive (the embedded-format-documentation
refactor in ClickHouse#106181 adds an optional setDocumentation API without changing
the registration signatures, plus the new
output_format_always_write_decimal_point_in_float_and_decimal setting from
ClickHouse#62614), and the native Arrow IPC code under ArrowIPC/ is untouched by
master.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants