Skip to content

Fix values() table function rejecting lossy floats for narrow float columns - #108055

Merged
alexey-milovidov merged 22 commits into
masterfrom
fix-values-float32-conversion-43144
Jul 13, 2026
Merged

alexey-milovidov merged 22 commits into
masterfrom
fix-values-float32-conversion-43144

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

Closes: #43144

The values table function rejected decimal literals that are not exactly representable in a narrower floating-point column:

SELECT * FROM values('x Float32', 0.1)
-- Code 69: Cannot convert value '0.1' from Float64: it cannot be represented as Float32. (ARGUMENT_OUT_OF_BOUND)

This was inconsistent with INSERT ... VALUES (0.1) into the same Float32 column, which works.

The cause was in convertFieldToType: the numeric narrowing helpers ignored the strict parameter and always required the converted value to be exactly equal to the input. Almost no decimal literal is exactly representable in Float32, so the non-strict callers (the VALUES section, the values table function, INSERT) rejected them. The fix threads strict through these helpers and, in non-strict mode, returns the nearest representable value when converting to a floating-point type — the same behaviour as CAST. The range check is unchanged, so out-of-range values are still rejected (1e300 to Float32 still errors, with no silent overflow to inf), and conversions to integer or Decimal types remain exact.

The IN operator passes strict = true, so its exact-value semantics are preserved and remain consistent with the = operator: toFloat32(0.1) IN (0.1) is 0, exactly like toFloat32(0.1) = 0.1.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fixed the values table function failing with ARGUMENT_OUT_OF_BOUND when a decimal literal that is not exactly representable in a narrow floating-point column (such as 0.1 for a Float32 column) is used, e.g. SELECT * FROM values('x Float32', 0.1). Such values are now accepted and converted to the nearest representable value, consistent with CAST and INSERT ... VALUES.

Version info

  • Merged into: 26.7.1.878 (included in 26.7 and later)

…olumns

The `values` table function rejected decimal literals that are not exactly
representable in a narrower floating-point column, e.g.

    SELECT * FROM values('x Float32', 0.1)
    -- Code 69: Cannot convert value '0.1' from Float64: it cannot be represented as Float32

This was inconsistent with `INSERT ... VALUES (0.1)` into the same column,
which works.

Root cause: `convertNumericType`/`convertNumericTypeImpl` in
`convertFieldToType.cpp` ignored the `strict` parameter and always asked
`accurate::convertNumeric` for an exact-equality check after the conversion.
Almost no decimal literal is exactly representable in `Float32`, so non-strict
callers (the `VALUES` section, the `values` table function, `INSERT`) rejected
them.

Thread `strict` through these helpers and skip the exact-equality check when
converting to a floating-point type in non-strict mode, returning the nearest
representable value like `CAST` does. The range check inside
`accurate::convertNumeric` is unchanged, so out-of-range values are still
rejected (`1e300` to `Float32` still errors, no silent overflow to `inf`), and
conversions to integer or `Decimal` types stay exact.

The `IN` operator passes `strict = true`, so its exact-value semantics are
preserved and stay consistent with the `=` operator:
`toFloat32(0.1) IN (0.1)` is `0`, exactly like `toFloat32(0.1) = 0.1`.

Closes: #43144

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

clickhouse-gh Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4047906]

Summary: ✅


AI Review

Summary

This PR changes convertFieldToType so lossy float narrowing is opt-in via convert_inexact_floats, then enables that opt-in only on true value-materialization paths such as values/VALUES, the INSERT ... VALUES expression fallback, WITH FILL, and window frame offsets. On the current PR head, the exact-by-default behavior is still preserved for optimizer/pruning and partition-resolution callers, strict IN remains exact, and the added regressions cover the previously raised edge cases. I did not find a remaining correctness issue in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 21, 2026
alexey-milovidov and others added 2 commits June 22, 2026 00:04
When converting a `Field` to a `Variant`, `convertFieldToType` falls back to
trying each alternative in turn and returns the first that converts. The
alternatives are listed in sorted order, so e.g. `Array(Float64)` is tried
before `Array(Int64)`.

After this branch enabled non-strict (lossy) conversion to floating-point
types, an exactly-representable integer such as `9223372036854775807` could be
stored lossily in an earlier `Array(Float64)` alternative instead of the exact
`Array(Int64)` one, changing the result of, e.g.,
`arrayRemove([[9223372036854775807, -9223372036854775808], [0.9999, 7]], ...)`.

Make the fallback prefer a lossless alternative: try a strict (exact)
conversion across all alternatives first, and fall back to a lossy conversion
only when no alternative can represent the value exactly. This restores the
previous selection while still accepting lossy values when no exact alternative
exists (e.g. a `Variant(Float32)` column).

This fixes the `04256_arrayRemove_variant_no_throw_on_mismatch` test that
started failing on this branch, and is covered by new `values()` cases in
`04403_values_float32_conversion_and_in`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`SELECT * FROM VALUES('x Float64', toUInt64(-1))` previously failed with
`ARGUMENT_OUT_OF_BOUND` because `18446744073709551615` is not exactly
representable as `Float64`. With non-strict conversion to floating-point types
now returning the nearest representable value (like `CAST`), the value is
within the `Float64` range and is accepted, returning `18446744073709552000`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
alexey-milovidov and others added 2 commits June 23, 2026 08:57
The Variant branch of `convertFieldToTypeImpl` tried each alternative twice -
once strict, then non-strict - regardless of the outer `strict` flag. This
preferred a lossless alternative (the original intent), but it also ran the
lossy pass for strict callers. The `IN` operator builds set elements with
`strict = true` so that values not exactly representable in the target type are
excluded, consistent with the `=` operator. With the unconditional second pass,
a `Variant(Float64)` set could accept e.g. `toUInt64(-1)` by rounding it to
`Float64` on the non-strict pass, so the set contained a value the underlying
`Float64` comparison would never equal.

Run the lossy fallback pass only when `strict` is false. Strict conversion now
only accepts an exact alternative, restoring the pre-change behaviour for `IN`
(an unrepresentable value is rejected) while non-strict callers keep preferring
a lossless alternative and falling back to a lossy one. A regression test is
added in `04403_values_float32_conversion_and_in`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two changes to `04403_values_float32_conversion_and_in`:

- The two `Array(Variant(...))` cases failed under the old query analysis, which
  eagerly computes a common type for the array literal (mixing a large `Int64`
  with `Float64`) and rejects it with `NO_COMMON_TYPE` before the value reaches
  the `Variant` column type. Pin these cases to the analyzer with
  `SETTINGS allow_experimental_analyzer = 1`; the behaviour they check is in the
  `Variant` alternative selection, which the analyzer reaches and the old path
  cannot express.

- Add a regression for the strict-`IN` `Variant` fix: a `Variant(Float64)` `IN`
  set must not round `toUInt64(-1)` to `Float64`, so the unrepresentable value
  is rejected instead of silently matching.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
alexey-milovidov and others added 10 commits June 24, 2026 23:46
…conversion

Master commit 3701b73 (PR #106202) combined the `Time` branches in
`convertFieldToTypeImpl` so both `UInt64` and `Int64` partition values are
routed through `convertNumericType<Int32>(src, type)`. This PR changed
`convertNumericType` to take a `strict` argument with no default value, so
after merging `master` that call site no longer compiled (2 arguments passed
to a 3-argument function).

Pass `strict` through. `Int32` is an integer type, so the conversion stays
exact regardless of the flag (`exact = strict || !is_floating_point<Int32>`
is always `true`), making this change behavior-neutral for the `Time`
partition path while restoring a clean build.
… paths

The original fix overloaded the existing `strict` flag of `convertFieldToType`
so that every non-strict caller rounded an inexact value to the nearest
floating-point value. That leaked into optimizer/pruning callers that pass
`strict = false` but treat the converted constant as an exact comparison bound
- in particular `KeyCondition`. For a `Float64` primary key and a predicate like
`x > toUInt64(-1)`, the literal would be rounded to `static_cast<Float64>(max)`
and the stricter range `x > rounded` could prune the mark holding a row that
actually matches under the accurate comparison used at execution time.

Introduce a dedicated `convert_inexact_floats` flag instead. Conversion to a
floating-point type now stays exact by default (an inexact value returns Null),
so `KeyCondition`, the sharding-key rewrite, the statistics estimator, the
secondary-index conditions and the strict `IN` operator never build a wrong
bound from a rounded constant. Only the value-materialization paths opt in:
`convertFieldToTypeOrThrow` (the `values`/`VALUES` table function, `WITH FILL`,
window frame offsets, ...) and the `INSERT` VALUES expression fallback in
`ValuesBlockInputFormat`, which now matches the streaming literal path and `CAST`.

Add a regression test that a `Float64` primary key compared against `toUInt64(-1)`
is not pruned, and a test that the `INSERT` VALUES expression path rounds an
inexact float to the nearest value.

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

`master` already has several `04403_*` tests, so move the
`values_float32_conversion_and_in` test to a free number.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…kHouse/ClickHouse into fix-values-float32-conversion-43144
…er the pre-existing ColumnVariant order

The AI review's remaining blocker (PR #108055 discussion, `Variant(Float32,
Float64)` with a `Float64` value such as `toFloat64(16777217)`) is a
pre-existing `ColumnVariant::tryInsert` ordering issue, not introduced by this
PR. `convertFieldToType` returns a bare `Field`; the alternative discriminator
is chosen downstream at column-insert time by `ColumnVariant::tryInsert`, which
scans variants in sorted order (`Float32` before `Float64`) and accepts the
`Float64` field lossily into the earlier `Float32` alternative. The exact-first
conversion loop only governs fields that fall through to it, so the converter
cannot influence this selection. Reworking `ColumnVariant::tryInsert` has a far
broader blast radius and is left as a separate design decision.

Following the review's accepted alternative, narrow the contract instead of
making the broad change:
- Explicitly scope the exact-alternative preference to the fall-through
  conversion loop in `convertFieldToType`, documenting that directly-insertable
  fields keep `ColumnVariant`'s pre-existing alternative order.
- Reword the test's section header to "the fall-through Variant conversion
  path" so it no longer promises universal lossless alternative preference.
- Add a `variantType` regression for
  `values('x Variant(Float32, Float64)', toFloat64(16777217))` that documents
  the pre-existing lossy selection (stored as `Float32` = 16777216). The type is
  suspicious (ambiguous float alternatives), so the test sets
  `allow_suspicious_variant_types`.

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

Master added 04417_numeric_indexed_vector_pointwise_multiply_all_ones, which
collides with this PR's 04417_keycondition_float_pk_no_lossy_prune. Move the
latter to the next free prefix 04490 to keep stateless test numbers unique.

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

Copy link
Copy Markdown
Member Author

All non-flaky checks are green and the PR is ready to merge:

  • CH Inc sync, Mergeable Check, Style check: ✅
  • AI Review: ✅ Approve; 0 unresolved review threads
  • LLVM coverage on changed lines: 133/139 (95.68%)

The only red is the aggregate PR status, which fails solely on the Stress test (amd_tsan) and Stress test (arm_tsan) Hung check failed, possible deadlock found rows. Those are the chronic flake tracked in #107941 (comp-query-analyzer/fuzz), unrelated to this change.

I pulled hung_check.log for the arm_tsan run to confirm. The single hung query is

SELECT formatQuery($$SELECT [[[[[[[[[[ ... (a deeply nested array literal) ... $$)

from 04412_deep_nested_literal_format.sh (is_cancelled: 1, elapsed: 1525s, single thread), and its stack is a deep recursion through DB::Field::dispatch<DB::Field::create(...)::'lambda', DB::Field const&> while materializing/symbolizing the literal — exactly the #107941 signature. There are zero convertFieldToType/ValuesBlockInputFormat frames in the hung dump, and this PR touches none of formatQuery, Field::dispatch, or Field::create. The PR's own code shows up in the stress run logs only inside ordinary fuzzer-triggered exception backtraces (out-of-range conversions), never in a hung stack.

Merge-base with master is ~12h old and git merge-tree reports no conflicts, so no re-merge is needed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Status after the latest run (899226f6):

  • The stress jobs were re-run (run_attempt = 2, completed 21:18Z) and the Hung check failed, possible deadlock found recurred on both Stress test (amd_tsan) and Stress test (arm_tsan) — i.e. it is the persistent chronic flake Hung check failed, possible deadlock found #107941, not transient. Everything else is green (152 checks SUCCESS, 18 SKIPPED), AI Review re-confirmed ✅ Approve, 0 unresolved review threads.

  • One heads-up that the git merge-tree no-conflict check does not catch (different filenames): since the earlier 04417 -> 04490 renumber, master has gained 04489_max_threads_auto_parsing_compat, 04490_dict_get_keys_float_signed_zero_consistency and 04490_table_readonly_partition_commands, so this PR's 04489_values_float32_conversion_and_in and 04490_keycondition_float_pk_no_lossy_prune now share those number prefixes once merged. This is cosmetic only — test_numbers_check (check_gaps_in_tests_numbers) is set-based and does not flag duplicate prefixes, and the distinct filenames run independently, so CI stays green either way. If unique prefixes are wanted, the next free slots are 04492/04493 (current master frontier is 04491); I can renumber, though they may re-collide as the frontier advances before merge. No re-merge is needed otherwise.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

The stress jobs were re-executed on the latest run (899226f6, 02:35Z→03:14Z on 07-01, after the previous triage). It is red only on the two TSan stress jobs, and both are the same chronic flakes — neither involves this change:

  • Stress test (amd_tsan) aborted on Logical error: 'Not-ready Set is passed as the second argument for function 'in'' — the known fuzzer flake Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-41a5) #107619 (exact STID 0250-41a5, opened 2026-06-17). I pulled fatal.log to confirm: the fatal stack is FunctionIn::executeImpl (src/Functions/in.cpp:116) ← FilterTransform ← ExpressionActions ← PipelineExecutor, with zero convertFieldToType/ValuesBlockInputFormat frames. The Cannot start clickhouse-server and Check failed rows are just the cascade after that abort.
  • Stress test (arm_tsan) recurred on Hung check failed, possible deadlock found — the chronic Hung check failed, possible deadlock found #107941, same signature as the run analyzed earlier.

This PR's convertFieldToType shows up in the TSan logs only inside ordinary, non-fatal exception backtraces — out-of-range conversions rejected during fuzzing (e.g. convertFieldToTypeCheckEnum → convertFieldToType in SetUtils.cpp), never in a crash or a hung stack. That is exactly the intended behavior: the range check still rejects genuinely out-of-range values.

Everything else is green: CH Inc sync ✅, Style check ✅, Fast test, all Stateless/Integration; AI Review ✅ Approve; 0 unresolved review threads; changed-line coverage 133/139 (95.68%). Mergeable Check is red solely because these two TSan rows flipped it after the reruns. No conflicts, and master touches none of the changed files since the merge-base (~1.3 days), so no re-merge is needed.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

Re-merged master into the branch (899226f6c0f..de581604c65).

Since the previous "no re-merge needed" note (2026-07-01 05:34Z), the QBit-strides work merged into master mainline in #108103 (086d40258a2, 2026-07-02 01:01Z) and touches src/Interpreters/convertFieldToType.cpp — the same file this PR modifies, so the earlier "master touches none of the changed files since the merge-base" statement is now stale. I re-merged so CI validates the two changes composed together, not just each in isolation.

The merge is clean:

  • No conflicts; the net PR diff vs master is byte-identical to before the merge (10 files, +324/−52).
  • The two changes are orthogonal within convertFieldToTypeImpl: this PR threads strict/convert_inexact_floats through the numeric-narrowing helpers (convertNumericType/convertNumericTypeImpl), while Support strides for the QBit data type #108103 rewrites the QBit conversion branch (getStride/getNumStrides/per-stride transpose). The QBit branch does not call convertNumericType, and the public convertFieldToType/tryConvertFieldToType signature changes are default-arg-only (backward compatible), so all call sites remain valid. I verified every convertNumericType<…> call site now uses the 4-arg form and no old 2-arg call survived.

On the test-number prefixes (04489/04490): still cosmetic-only and I did not renumber. The master frontier is now 04497, and prefixes 04489–04496 each already carry 5–12 distinct test files (check_gaps_in_tests_numbers is set-based and does not flag shared prefixes), so any "unique" prefix I picked would re-collide before merge and the distinct filenames run independently regardless.

The only remaining reds were the two TSan Stress test jobs, which your prior triage already attributed to the chronic flakes #107941 (Hung check) and #107619 (Not-ready Set), with zero convertFieldToType/ValuesBlockInputFormat frames in the fatal/hung stacks. Fresh CI on de581604c65 will re-run these.

…ALUES path

Address review feedback on #108055:
the existing `04489` regression only exercised the single-expression fallback
(with `input_format_values_deduce_templates_of_expressions = 0`) and never the
default template-deduction path (setting = 1).

Add cases that leave template deduction enabled and insert inexact float
literals inside `Array`/`Tuple` expressions and into a scalar `Float32` column,
asserting the values are rounded to the nearest representable value (matching
`CAST`), not rejected with `ARGUMENT_OUT_OF_BOUND` or turned into `NULL`.

This path is handled by `ConstantExpressionTemplate::parseLiteralAndAssertType`:
the captured array/tuple literal keeps its own deduced `Array(Float64)` type, so
the per-row `convertFieldToType` there is a lossless `Float64` -> `Float64`
conversion, and the narrowing to the `Float32` column happens afterwards via
`CAST` in `evaluateAll`. It therefore never needed the `convert_inexact_floats`
opt-in, and the behavior is identical on `master` and on this branch.

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

Copy link
Copy Markdown
Member Author

Status after the master re-merge (de581604c65) and the follow-up test commit (281ce07b4bf):

AI Review "⚠️ Request changes" — the flagged gap is a false positive, addressed in this thread. The default input_format_values_deduce_templates_of_expressions = 1 path narrows to the target column via castColumn (CAST) in ConstantExpressionTemplate::evaluateAll, not through the convertFieldToType call at ConstantExpressionTemplate.cpp:691 — whose complex_type is the captured literal's own deduced Array(Float64), a lossless conversion. So it never needed convert_inexact_floats, and the AI's repro (INSERT INTO t VALUES (arrayConcat([0.1], [])), (arrayConcat([0.2], [])) into Array(Float32)) already succeeds on plain master. The reviewer's test point was fair, so 281ce07b4bf extends 04489 with Array/Tuple/scalar Float32 inserts with template deduction left enabled, asserting nearest-value rounding and no NULL.

CI reds — both pre-existing, unrelated flakes (not convertFieldToType):

  • AST fuzzer (amd_debug, targeted) / (amd_debug) — Inconsistent AST formatting (STID 1941-26fa / 1941-1bfa) = tracked flake Logical error: 'Inconsistent AST formatting: the original AST: (STID: 1941-26fa) #108372 (OPEN); 79 hits over 14 days across master and 9+ PRs. Fatal stack is executeQueryImpl AST-format round-trip, zero PR frames.
  • Stress test (amd_tsan) — future_error: The associated promise has been destructed prior to the associated state becoming ready (STID 2508-38c6) = recurring stress flake in MergeTreeBackgroundExecutor/ThreadPool teardown; 16 hits over 14 days across 8 master-based PRs, unrelated stack.

Fresh CI is running on 281ce07b4bf.

…oat32-conversion-43144

# Conflicts:
#	src/Interpreters/convertFieldToType.cpp
#	src/Interpreters/convertFieldToType.h
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
`convertFieldToTypeOrThrow` applied lossy float conversion
(`convert_inexact_floats = true`) unconditionally, so it leaked into
callers that resolve an exact target rather than materialize a value. In
particular `MergeTreeData::getPartitionIDFromQuery` uses it to resolve
`ALTER ... PARTITION` targets: with `allow_floating_point_partition_key`,
`DROP PARTITION 0.1` on a `Float32` partition key rounded the literal to
`toFloat32(0.1)` and could drop a partition instead of rejecting the
unrepresentable value - turning a destructive statement from fail-closed
into lossy matching.

Add a `convert_inexact_floats` parameter to `convertFieldToTypeOrThrow`
(default `false`, i.e. exact) and pass `true` only at the true
value-materialization callers (the `values`/`VALUES` table function,
`WITH FILL`, window frame offsets). Partition resolution, `ConstantNode`
and executable-UDF parameter conversion keep the exact default, which
matches the pre-existing behavior for those paths and the design already
documented in the header.

Add `04509_partition_float32_no_lossy_drop` covering the partition path.

Addresses the review on #108055

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Making `convertFieldToTypeOrThrow` exact by default (previous commit) means the
`ConvertFieldToTypeStrictness.Float64ToFloat32` unit test's bare call for the
inexact value `0.1 -> Float32` now throws `ARGUMENT_OUT_OF_BOUND` instead of
rounding, so the test asserted the pre-change behavior and would fail.

Pass `convert_inexact_floats=true` at the materialization call to exercise the
`values`/`INSERT` rounding semantics the test intends to cover, and add an
`EXPECT_THROW` documenting the exact-by-default contract that protects
`ALTER ... PARTITION` resolution in `getPartitionIDFromQuery`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
Comment thread src/Interpreters/convertFieldToType.cpp Resolved
alexey-milovidov and others added 2 commits July 8, 2026 21:45
…tition literals

Fresh CI on the merge head raised an AI review requesting changes with two
findings on `convertFieldToType.cpp`.

- `convertFieldToType.cpp:80`: claimed `convert_inexact_floats` never activates
  for `BFloat16` because `std::is_floating_point<BFloat16>` is `false`. The code
  uses the ClickHouse `is_floating_point` concept (`base/base/extended_types.h`,
  `std::is_floating_point_v<T> || std::is_same_v<T, BFloat16>`), so `BFloat16` is
  a floating-point type there and already takes the lossy path when
  `convert_inexact_floats` is set. The existing test only used `0.5` (exactly
  representable), which does not exercise it. Added a regression asserting
  `values('x BFloat16', 0.1)` equals `CAST(0.1, 'BFloat16')` and a clarifying
  comment. No code change (the behavior is already correct).

- `convertFieldToType.cpp:958`: noted a quoted string partition literal
  (`DROP PARTITION '0.1'`) bypasses the fail-closed guarantee. The string branch
  parses it into the target type via `deserializeWholeText` (rounding) before the
  exactness check, then recurses. This is pre-existing behavior (verified on
  master), shared with string-to-float value comparisons like `WHERE f = '0.1'`,
  and unchanged by this PR; threading the flags through the string recursion is a
  no-op because the rounding happens during parsing. Narrowed the documented
  contract (the guarantee is for numeric literals) and added a regression
  documenting the quoted-string behavior.

Comments and tests only; no behavior change.

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

clickhouse-gh Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.90% +0.10%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 160/167 (95.81%) · Uncovered code

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Very good!

@alexey-milovidov alexey-milovidov self-assigned this Jul 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 13, 2026
Merged via the queue into master with commit 11a083a Jul 13, 2026
175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-values-float32-conversion-43144 branch July 13, 2026 22:55
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 13, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…er the pre-existing ColumnVariant order

The AI review's remaining blocker (PR ClickHouse#108055 discussion, `Variant(Float32,
Float64)` with a `Float64` value such as `toFloat64(16777217)`) is a
pre-existing `ColumnVariant::tryInsert` ordering issue, not introduced by this
PR. `convertFieldToType` returns a bare `Field`; the alternative discriminator
is chosen downstream at column-insert time by `ColumnVariant::tryInsert`, which
scans variants in sorted order (`Float32` before `Float64`) and accepts the
`Float64` field lossily into the earlier `Float32` alternative. The exact-first
conversion loop only governs fields that fall through to it, so the converter
cannot influence this selection. Reworking `ColumnVariant::tryInsert` has a far
broader blast radius and is left as a separate design decision.

Following the review's accepted alternative, narrow the contract instead of
making the broad change:
- Explicitly scope the exact-alternative preference to the fall-through
  conversion loop in `convertFieldToType`, documenting that directly-insertable
  fields keep `ColumnVariant`'s pre-existing alternative order.
- Reword the test's section header to "the fall-through Variant conversion
  path" so it no longer promises universal lossless alternative preference.
- Add a `variantType` regression for
  `values('x Variant(Float32, Float64)', toFloat64(16777217))` that documents
  the pre-existing lossy selection (stored as `Float32` = 16777216). The type is
  suspicious (ambiguous float alternatives), so the test sets
  `allow_suspicious_variant_types`.

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
…ALUES path

Address review feedback on ClickHouse#108055:
the existing `04489` regression only exercised the single-expression fallback
(with `input_format_values_deduce_templates_of_expressions = 0`) and never the
default template-deduction path (setting = 1).

Add cases that leave template deduction enabled and insert inexact float
literals inside `Array`/`Tuple` expressions and into a scalar `Float32` column,
asserting the values are rounded to the nearest representable value (matching
`CAST`), not rejected with `ARGUMENT_OUT_OF_BOUND` or turned into `NULL`.

This path is handled by `ConstantExpressionTemplate::parseLiteralAndAssertType`:
the captured array/tuple literal keeps its own deduced `Array(Float64)` type, so
the per-row `convertFieldToType` there is a lossless `Float64` -> `Float64`
conversion, and the narrowing to the `Float32` column happens afterwards via
`CAST` in `evaluateAll`. It therefore never needed the `convert_inexact_floats`
opt-in, and the behavior is identical on `master` and on this branch.

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
`convertFieldToTypeOrThrow` applied lossy float conversion
(`convert_inexact_floats = true`) unconditionally, so it leaked into
callers that resolve an exact target rather than materialize a value. In
particular `MergeTreeData::getPartitionIDFromQuery` uses it to resolve
`ALTER ... PARTITION` targets: with `allow_floating_point_partition_key`,
`DROP PARTITION 0.1` on a `Float32` partition key rounded the literal to
`toFloat32(0.1)` and could drop a partition instead of rejecting the
unrepresentable value - turning a destructive statement from fail-closed
into lossy matching.

Add a `convert_inexact_floats` parameter to `convertFieldToTypeOrThrow`
(default `false`, i.e. exact) and pass `true` only at the true
value-materialization callers (the `values`/`VALUES` table function,
`WITH FILL`, window frame offsets). Partition resolution, `ConstantNode`
and executable-UDF parameter conversion keep the exact default, which
matches the pre-existing behavior for those paths and the design already
documented in the header.

Add `04509_partition_float32_no_lossy_drop` covering the partition path.

Addresses the review on ClickHouse#108055

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
…32-conversion-43144

Fix values() table function rejecting lossy floats for narrow float columns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

values() table function with Float32 column: Cannot convert value X from Float64: it cannot be represented as Float32.

2 participants