Skip to content

Introduce NumberLiteral Field type - #121554

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
Algunenano:number-literal-field-type
Sep 23, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
Algunenano:number-literal-field-type

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

First piece of #102646, split out for review.

Adds a NumberLiteral Field type that holds the unparsed text of a numeric literal, so that parsing to a concrete type can be deferred until the target type is known. It also adds Field::resolveNumberLiteral, which turns the text into a concrete numeric Field (smallest fitting wide integer for integer literals, Float64 otherwise), and NumberLiteral::toFloat64, the single place that converts literal text to a float.

Besides Field itself, this covers every place the new alternative has to be handled for the code to compile: the FieldVisitor* visitors under Common, FieldBinaryEncoding, FieldToDataType, and the partition-hash visitor in MergeTreePartition.

Nothing constructs a NumberLiteral yet, so no behaviour changes. The parser, the resolution paths and the tests come in follow-up pull requests.

Related: #102646
Related: #74312

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...


Workflow [PR]
Sync PR [sync-upstream/pr/121554]

Version info

  • Merged into: 26.10.1.472-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0c2a684]

Summary: ✅


AI Review

Summary

This PR adds NumberLiteral as a new Field alternative and threads it through the core visitors, dump/binary helpers, hashing, and type inference so literal text can be resolved later. The overall split is sensible, but the new resolver does not yet honor its own "smallest fitting integer type" contract once a NumberLiteral is materialized through the serialization paths this PR already adds, so I do not think it is ready as-is.

Findings
  • ⚠️ [src/Core/Field.cpp:868] resolveNumberLiteral only tries Int128 / Int256 or UInt128 / UInt256, so a directly materialized NumberLiteral{"1"} resolves to UInt128 and NumberLiteral{"-1"} resolves to Int128. Because Field::restoreFromDump and AST JSON now preserve NumberLiteral, this widens constant type inference in FieldToDataType / QueryTreeBuilder for no semantic reason instead of preserving the existing narrow integer ladder.
Tests
  • ⚠️ No focused coverage was added for Field::restoreFromDump("Number_...") / AST JSON round-trips into FieldToDataType or FieldVisitorConvertToNumber. A small unit test on 1, -1, and wide-integer cases would close the evidence gap around the new resolver.
Final Verdict

Changes requested: fix the integer-width inference before merging.

LLVM Coverage Report

Measured on commit 0c2a684.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.30% 79.40% +0.10%

Changed lines: Changed C/C++ lines covered: 35/164 (21.34%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 22, 2026
@nikitamikhaylov nikitamikhaylov self-assigned this Sep 22, 2026
Comment thread src/Core/Field.cpp Resolved
Comment thread src/Core/Field.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0c2a684dc with master aa5872d26 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes ⚠️

1780 object files changed (+14.95 MiB total), 0 added.

Object file Master PR Δ
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/moduloOrNull.cpp.o 8.30 MiB 9.41 MiB +1.11 MiB (+13.35%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/modulo.cpp.o 16.83 MiB 17.84 MiB +1.01 MiB (+6.00%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/intDiv.cpp.o 11.28 MiB 12.15 MiB +897.99 KiB (+7.78%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/less.cpp.o 6.94 MiB 7.76 MiB +838.54 KiB (+11.80%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/greater.cpp.o 6.96 MiB 7.78 MiB +837.91 KiB (+11.76%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/equals.cpp.o 6.80 MiB 7.61 MiB +837.24 KiB (+12.03%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/isNotDistinctFrom.cpp.o 6.80 MiB 7.62 MiB +837.23 KiB (+12.03%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/notEquals.cpp.o 6.83 MiB 7.65 MiB +837.14 KiB (+11.96%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/lessOrEquals.cpp.o 7.01 MiB 7.82 MiB +834.12 KiB (+11.63%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/greaterOrEquals.cpp.o 7.02 MiB 7.83 MiB +834.10 KiB (+11.61%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/isDistinctFrom.cpp.o 6.87 MiB 7.69 MiB +833.93 KiB (+11.85%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/divide.cpp.o 10.21 MiB 10.86 MiB +671.95 KiB (+6.43%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/plus.cpp.o 8.77 MiB 9.24 MiB +475.12 KiB (+5.29%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/minus.cpp.o 8.55 MiB 8.97 MiB +431.84 KiB (+4.93%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/multiply.cpp.o 7.88 MiB 8.25 MiB +384.41 KiB (+4.76%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/intDivOrZero.cpp.o 7.80 MiB 8.16 MiB +372.69 KiB (+4.67%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/least.cpp.o 7.22 MiB 7.56 MiB +352.43 KiB (+4.77%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/greatest.cpp.o 7.24 MiB 7.59 MiB +352.36 KiB (+4.75%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/midpoint.cpp.o 7.49 MiB 7.83 MiB +352.33 KiB (+4.59%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/avg2.cpp.o 7.51 MiB 7.84 MiB +339.91 KiB (+4.42%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

3481 translation units recompiled, 17673 s compile time in total, 3481 of them have a recent master baseline.

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-data-types Type system & core datatypes used across query planning/execution. label Sep 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 22, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 22, 2026
Merged via the queue into ClickHouse:master with commit 350963d Sep 23, 2026
176 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-data-types Type system & core datatypes used across query planning/execution. pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants