Repository navigation
Fix toFloat64/toUInt32/toString/etc. on Dynamic ignoring cast_keep_nullable - #105467
Conversation
…keep_nullable` When `cast_keep_nullable=1`, conversion functions like `toFloat64` on Dynamic columns containing NULLs returned non-nullable results (NULLs silently converted to 0), while `CAST` correctly returned `Nullable` with NULLs preserved. The root cause was two-fold: 1. `FunctionConvert::getReturnTypeImpl` used `getNullPresense` which only checks `isNullable()`, missing Dynamic (and Variant) types that can also contain NULLs. Fixed by adding a `canContainNull` check when `cast_keep_nullable` is enabled. 2. `FunctionConvert::executeImpl` had a nullable handling block that extracted null maps only from `Nullable` arguments, not from Dynamic. Also, `toString` was excluded from this block entirely. Fixed by also extracting null maps from Dynamic arguments via a new `ColumnVariant::createNullMap` method, and removing the String exclusion to handle all types uniformly. Closes #104789 Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Workflow [PR], commit [447d0c4] Summary: ✅
AI ReviewSummaryThis PR fixes Findings❌ Blockers
Final VerdictStatus: ❌ Block Minimum required action: restore default-off |
m-selmi
left a comment
There was a problem hiding this comment.
LGTM besides the Variant point made by the AI review.
…r Dynamic/Variant The `toFloat64`/`toUInt32`/`toString`/etc. functions and `CAST` now handle NULL values in Variant columns the same way they handle NULLs in Nullable and Dynamic columns: - `FunctionConvert` (`toFloat64`, `toString`, etc.) always wraps the result in Nullable when the source is Dynamic or Variant, matching how it already handles Nullable sources via `getNullPresense`. - `FunctionCast` (`CAST`/`::` syntax) wraps the result in Nullable when `cast_keep_nullable = 1`, using `canContainNull` instead of manually enumerating type checks (which missed Variant). - `createVariantToColumnWrapper` now throws on NULL when the result type cannot contain NULL, matching `createDynamicToColumnWrapper` behavior. - Added `ConvertImplFromVariantToColumn` with optimized paths for: all-NULLs, single variant without NULLs, single variant with NULLs, and general multi-variant case. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
I added additional fixes for Variant type as well |
In `FunctionConvert::executeImpl`, the Dynamic and Variant branches
assumed `arg.column` is a concrete `ColumnDynamic`/`ColumnVariant`,
but in mixed-const calls (e.g. `toUnixTimestamp(CAST(NULL AS Dynamic),
materialize('UTC'))`) it can be `ColumnConst` wrapping them.
Mirror the Nullable handling: check `isColumnConst` first, return
all-default if `onlyNull`, otherwise skip (const non-NULL contributes
no NULLs to the null map).
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace `std::vector` with `VectorWithMemoryTracking` to satisfy the style check. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…:ClickHouse/ClickHouse into fix-cast-keep-nullable-dynamic
…e/ClickHouse into fix-cast-keep-nullable-dynamic
The previous commits unconditionally treated Dynamic/Variant as Nullable in `toXxx` functions and threw on NULL in CAST wrappers, breaking backward compatibility when `cast_keep_nullable = 0` (the default). Now all nullable-preserving behavior is gated by the setting: - `getReturnTypeImpl` / `executeImpl`: only wrap the result in Nullable for Dynamic/Variant input when `cast_keep_nullable` is enabled. - `executeInternal` / CAST wrappers: use `shouldThrowOnNull` which only throws when `cast_keep_nullable` is on AND the result type is neither nullable-like nor wrappable in Nullable (e.g. Array). - Restore the `toString` exception for the nullable branch: `toString` handles regular Nullable arguments itself (via `ConvertImplGenericToString`), but for Dynamic/Variant we still enter the nullable branch to extract their null map. Revert `03780_function_variant_adaptor` reference to master (test uses default `cast_keep_nullable = 0`). Update `04260` / `04268` tests to expect default values for NULLs when the setting is off. Related: #105467 Co-Authored-By: Claude Opus 4.6 <[email protected]>
In `ConvertImplFromVariantToColumn::execute`, the general multi-variant path passes secondary arguments (e.g. timezone for `toDateTime`) to `nested_convert` without filtering them to match the compact variant subcolumn. This mirrors the existing filtering in the single-variant- with-NULLs optimization path. Co-Authored-By: Claude Opus 4.6 <[email protected]>
| ConvertImplFromDynamicToColumn::shouldThrowOnNull(settings.cast_keep_nullable, result_type)); | ||
| } | ||
|
|
||
| if (isVariant(from_type)) |
There was a problem hiding this comment.
cast_keep_nullable = 0 is the compatibility mode, but this unconditional Variant path now changes existing toString results even when the setting is off. The updated 03780_function_variant_adaptor.reference shows the regression: rows that used to print ᴺᵁᴸᴸ now print an empty string because ConvertImplFromVariantToColumn substitutes defaults for NULL_DISCRIMINATOR. Please keep the old FunctionBaseVariantAdaptor behavior when cast_keep_nullable is disabled, and only apply the new null-map/default-substitution path when cast_keep_nullable = 1.
There was a problem hiding this comment.
It's intended. The old behaviour was incorrect. Now Variant is consistent with Dynamic
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 136/188 (72.34%) | Lost baseline coverage: none · Uncovered code |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
toFloat64/toUInt32/toString/etc. on Dynamic ignoringcast_keep_nullable. Closes #104789Version info
26.6.1.502