Repository navigation
Add evaluateConstantExpressionAsColumn to avoid Field materialization - #110944
yakov-olkhovskiy wants to merge 2 commits into
Conversation
`evaluateConstantExpression` already builds a size-1 `ColumnConst` internally,
then discards it by returning `(*result_column)[0]` as a `Field` — which both
allocates and collapses the exact SQL type through `Field`'s `NearestFieldType`
mapping (`UInt8`->`UInt64`, `Float32`->`Float64`, `DateTime64`->`Decimal`, ...).
Add `evaluateConstantExpressionAsColumn` (and `tryEvaluateConstantExpressionAsColumn`)
returning the value as `{ColumnPtr /*size 1*/, DataTypePtr}`, preserving the exact
type and avoiding the `Field`. The existing `Field`-returning functions become thin
shims over it, so behavior is unchanged for callers not yet migrated.
Migrate the plain `String` literal arguments of `prometheusQuery`/`prometheusQueryRange`
(`StoragePrometheusQuery`) and `timeSeriesSelector` (`StorageTimeSeriesSelector`) to the
new API, reading the value with `IColumn::getDataAt` instead of materializing a `Field`
and calling `safeGet<String>`.
This is the first step of reducing `DB::Field` usage; no behavior change.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [c527ddb] Summary: ✅
AI ReviewSummaryThis PR adds Final Verdict
|
Addresses automated review on #110944: the exact-type column API narrowed the accepted argument types. The previous `Field`-based code read the value via `operator[]`, which flattens wrappers, so a non-NULL `Nullable(String)` / `LowCardinality(String)` constant passed the `Field::Types::String` check. Unwrap via `removeLowCardinalityAndNullable` before the String kind check to keep those accepted, and add an explicit `isNullAt` check so a NULL value is still rejected as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 42/52 (80.77%) · Uncovered code |
|
Superseded by #110945, which folds in this change (evaluateConstantExpressionAsColumn) together with the column-native coercion (convertColumnToType) and the actual Field removal from the numbers/primes/generateSeries table functions, so the whole constant-expression flow is migrated in one reviewable PR. |
Addresses automated review on ClickHouse#110944: the exact-type column API narrowed the accepted argument types. The previous `Field`-based code read the value via `operator[]`, which flattens wrappers, so a non-NULL `Nullable(String)` / `LowCardinality(String)` constant passed the `Field::Types::String` check. Unwrap via `removeLowCardinalityAndNullable` before the String kind check to keep those accepted, and add an explicit `isNullAt` check so a NULL value is still rejected as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Part of a larger effort to eliminate
DB::FieldThis PR is one step in an ongoing, multi-phase effort to remove
DB::Fieldfrom the ClickHouse server, replacing it with type-consistent, copy-free representations (a size-1IColumn+DataTypePtrfor owned values, and a non-owning column-reference for transient reads). The motivation:Field's type tags do not map to ClickHouse SQL types (itsNearestFieldTypemapping collapsesUInt8->UInt64,Float32->Float64,DateTime64->Decimal, ...), which is a recurring source of type bugs, andFieldforces copies of data that already lives in memory as columns. Each PR in the effort is small, self-contained, behavior-preserving, and independently mergeable; this is one of the first.This change
evaluateConstantExpressionalready builds a size-1ColumnConstinternally, then discards it by returning(*result_column)[0]as aField. That both allocates aFieldand collapses the exact SQL type throughField'sNearestFieldTypemapping.This adds
evaluateConstantExpressionAsColumnandtryEvaluateConstantExpressionAsColumn, which return the value as{ColumnPtr /* size 1 */, DataTypePtr}— preserving the exact type and avoiding theFieldmaterialization. The existingField-returningevaluateConstantExpression/tryEvaluateConstantExpressionbecome thin shims over the new functions, so behavior is unchanged for callers that have not been migrated.As a first use, the plain-
Stringliteral arguments ofprometheusQuery/prometheusQueryRange(StoragePrometheusQuery) andtimeSeriesSelector(StorageTimeSeriesSelector) now read their value withIColumn::getDataAtinstead of materializing aFieldand callingsafeGet<String>.There is no user-facing behavior change.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Internal refactor: add a column-returning
evaluateConstantExpressionAsColumnto avoid materializing aFieldfor constant expressions. No user-facing change.Documentation entry for user-facing changes
🤖 Generated with Claude Code