fix: scan Enum8/Enum16 columns into integer destinations#1921
Open
polyglotAI-bot wants to merge 1 commit into
Open
fix: scan Enum8/Enum16 columns into integer destinations#1921polyglotAI-bot wants to merge 1 commit into
polyglotAI-bot wants to merge 1 commit into
Conversation
Enum8/Enum16 ScanRow only accepted *string/**string destinations, so scanning an enum column into an integer (its underlying ordinal) returned a ColumnConverterError, even though the write side already accepts int8/int16/int values (PR #802). Add integer destination cases that return the numeric ordinal: Enum8 -> *int8/*int16/*int32/*int64/*int (+ **... variants) Enum16 -> *int16/*int32/*int64/*int (+ **... variants) int8 is intentionally not offered for Enum16 because Enum16 ordinals can exceed the int8 range and would silently truncate; that destination remains an explicit ColumnConverterError. Nullable(Enum) inherits the fix via Nullable.ScanRow delegation. Fixes: #1918
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1918.
Enum8.ScanRow/Enum16.ScanRowonly accepted*string/**stringdestinations (plus
sql.Scanner). Any integer destination fell through to aColumnConverterError, so reading an enum column into its underlying numericordinal was impossible — even though the write side has accepted integer
values since #802 ("Support inserting Enums as int8/int16/int values"). This
restores read/write symmetry.
proto.Enum8isint8-based andproto.Enum16isint16-based, so the rawvalue returned by
col.col.Row(row)is the ordinal. The fix adds integerdestination cases that return it.
Changes
lib/column/enum8.go—ScanRownow handles*int8,*int16,*int32,*int64,*int(and the**pointer-to-pointer variants). All are losslesswidenings of the
int8base.lib/column/enum16.go—ScanRownow handles*int16,*int32,*int64,*int(and**variants).int8is intentionally not offered forEnum16: anEnum16ordinal can exceed theint8range (e.g.1000) andwould silently truncate, so an
int8destination forEnum16stays anexplicit
ColumnConverterErrorrather than corrupting data (consistent withthe "hard to use incorrectly" design principle). Only signed integer types are
added, matching the signed enum ordinals and the write side.
Nullable(Enum)inherits the fix automatically —Nullable.ScanRowdelegates element scanning to the base
Enumcolumn'sScanRow.Test
tests/issues/1918_test.go(native round-trip against a real server):Enum8scanned into every signed width (int8/int16/int32/int64/int).Enum16scanned intoint16/int32/int64/int, using ordinal1000(outsideint8range) to prove the wider destinations are not truncated.-5,-300) preserve their sign.**int8etc.).stringdestinations still work unchanged, andEnum16 -> int8remains an error (no silent truncation).Nullable(Enum)into integer destinations (value scanned;NULLleaves apointer destination nil).
Each integer subtest fails on
mainwithclickhouse [ScanRow]: converting Enum8 to *int8 is unsupportedand passeswith this change; the surrounding existing enum unit and integration tests
continue to pass unchanged.
Known limitation / follow-up (out of scope here)
Array(Enum)→[]intandMap(String, Enum)→map[string]intare notaddressed by this PR: they use a different, reflection-based element-scan path
(
Array.scanSlice→setJSONFieldValue, andMap.ScanRow's whole-type match),not
Enum.ScanRow. Neither has ever worked, neither is a regression, and fixingthem touches shared code used by all container element types — so it belongs in a
separate change (and, for
Map, may be intentional). Kept this PR to one focusedfix.
Pre-PR validation gate
main, pass here)ScanRowtype switch)AGENTS.md(regression test intests/issues/, pointer receivers,t.Cleanupfor connections)