Repository navigation
Add IPv4/IPv6 auto-inference for JSON shared data insertion - #110766
valerypetrov wants to merge 81 commits into
Conversation
|
Workflow [PR], commit [b251211] Summary: ❌
AI ReviewSummaryAdds opt-in Final VerdictStatus: ✅ Approve |
|
@alexey-milovidov, it seems that some of the flaky tests are failing. Do you want me to retrigger CI? |
…v4/IPv6 disambiguation
…nsertIntoSharedData
…toDynamicPath - Add tryInferIPv4OrIPv6FromString to SchemaInferenceUtils so IPv4/IPv6 detection applies to all text-format schema inference (CSV, TSV, JSONEachRow column detection, etc.), not just JSON shared-data insertion. - Fix early-return condition in insertIntoDynamicPath to include the new IP inference flags so the String short-circuit does not bypass them. - Add IPv4/IPv6 variant handling in insertIntoDynamicPath after the DateTime64(9) block, with the colon guard on IPv6 to prevent a plain IPv4 address from being coerced into ::ffff: form.
- Wire tryInferIPv4OrIPv6FromString into tryInferDataTypeByEscapingRule in EscapingRuleUtils.cpp for all three branches (quoted CSV, unquoted CSV, raw/TSV), so input_format_try_infer_ipv4/ipv6 works for all text formats as intended. - Call tryInferIPv4OrIPv6FromString from DynamicNode::elementToDataTypeImpl in JSONExtractTree.cpp so new JSON dynamic paths and nested structures (e.g. Array of IP strings) infer IPv4/IPv6 instead of String. - Add tests 9-13 covering dynamic-path inference and CSV/TSV inference.
- Add transformIPTypes in SchemaInferenceUtils: IPv4/IPv6 mixed with String or with each other collapses to String during schema inference, matching the transformDatesAndDateTimes pattern. Prevents TYPE_MISMATCH errors when a sample contains both IP and non-IP string values. - Include try_infer_ipv4/try_infer_ipv6 in getAdditionalFormatInfoByEscapingRule so schema-cache keys vary with the new settings; prevents stale cached schemas being reused across different inference configurations. - Add tests 14-15 covering mixed-type collapse behavior.
…ck serializer The fast path was using writeBinaryLittleEndian(static_cast<UInt32>(ipv4_value)) while the fallback dynamic_serialization->serializeBinary path uses writeBinary (host byte order) via SerializationIP<IPv4>::serializeBinary. On big-endian (s390x) these produce different bytes. Use writeBinary(ipv4_value, buf) to stay byte-identical with the fallback and consistent with the IPv6 path on the next line.
The example additional_format_info string predates many schema inference settings, including the new try_infer_ipv4 / try_infer_ipv6 fields. Replace it with the real output of the documented DESCRIBE query on this branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's version is 26.11 now, and the settings-history check requires a new setting to have a record under the current version. With the 26.10 records the Style check fails and every other CI job is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Dynamic path first tries the variants it already has, without type conversion. An IPv6 variant inferred from an earlier row accepted plain IPv4 text, so 192.168.1.1 became ::ffff:192.168.1.1 even with IPv4 inference disabled, and the result depended on row order and on whether the path was dynamic or in shared data. IPv6 inference needs a colon; the reuse now does too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fer IPs from escaped text JSONExtract into Dynamic first tries the variants the column already has. That probe inherited JSONExtract's "insert a default for an invalid element" mode, so an array such as ["10.0.0.1","not-an-ip"] matched an existing Array(Nullable(IPv4)) variant as ['10.0.0.1',NULL]. The probe now refuses such lossy matches, and a new type is inferred. Schema inference decodes string escapes before it looks for an IP address, but IP columns read the raw JSON text, so "192.168.1.1" was inferred as IPv4 and then failed to read. Strings that contain escapes are no longer inferred as IPv4 or IPv6. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TSKV schema reader decodes escapes before it infers a type, but IP columns read the raw bytes, so ip=192.168.1.\x31 was inferred as IPv4 and then failed to read. Such a value already stays a String when it looks like a number; IP addresses now get the same treatment. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ip-types Co-Authored-By: Claude Opus 5.5 <[email protected]>
The TSKV schema reader decodes escapes before inference, but the IPv4/IPv6 text readers inside arrays, tuples, maps and variants parse the original bytes and stop at the backslash. So a value like ['192.168.1.\x31'] inferred Array(Nullable(IPv4)) and then failed to read with CANNOT_PARSE_IPV4. When the field had an escape, nested IP types now fall back to String, which is the schema the same input gets with IP inference disabled. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omotion TSKVSchemaReader previously inherited ISchemaReader::transformTypesIfNeeded, which directly invoked tryGetLeastSupertype. Because IPv4 is represented as UInt32, merging IPv4 with Int64 promoted the column to Nullable(Int64) instead of string, causing subsequent reads to fail parsing dotted IP addresses. The same failure occurred in reverse row order, with floating point, boolean, and arrays of IP and numeric values. Now TSKVSchemaReader overrides transformTypesIfNeeded to run transformInferredTypesByEscapingRuleIfNeeded before generic numeric promotion, ensuring incompatible IP/numeric values (including nested types) convert to String. Co-Authored-By: Claude Opus 5.5 <[email protected]>
TSKVSchemaReader previously ran transformInferredTypesByEscapingRuleIfNeeded unconditionally, which executed generic numeric transformations like transformIntegers and transformIntegersAndFloatsToFloats even when both IP inference settings were disabled. This coerced incompatible numeric samples (e.g. 9007199254740993 and 0.5, or -1 and 18446744073709551615) into Float64 or UInt64 instead of falling back to Nullable(String), losing precision or rejecting negative input. Now TSKVSchemaReader only performs IP normalization (via transformIPTypes) when IP inference is enabled and at least one type is IP-bearing, preserving the original lossless numeric fallback for non-IP samples. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `Build (arm_tidy)` and `Fast test` jobs failed with `-Werror,-Wunused-but-set-variable` on the `variant` binding added in 7129977. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=110766&sha=71299771d6326aec1e80aa46ec543a3cd35440fc&name_0=PR&name_1=Build%20%28arm_tidy%2C%203%2F4%29 PR: ClickHouse#110766 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ip-types Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ed, Raw, TSKV and CSV Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ip-types Master moved the shared data fast path to inferScalar. An inferred IPv4 or IPv6 string now leaves that fast path and takes the generic path, which writes it with the IPv4/IPv6 serialization, as the branch did before. Co-Authored-By: Claude Opus 5.5 <[email protected]>
With the default schema_inference_make_columns_nullable the quoted scalars infer Nullable(String), which LIKE '%String' does not match, so the test failed in every CI job. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…` under version 26.12 The settings are added in 26.12 now that master has moved to that version, so their history records must carry it. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The fast path for strings in `DynamicNode::insertResultToColumn` inserts a `String` directly when date and datetime inference is off, and otherwise reuses an existing variant. Both places must take `input_format_try_infer_ipv4` and `input_format_try_infer_ipv6` into account, and no existing test covered them: without those conditions an IP address is stored as `String` when date inference is off, or once the path has a `String` variant. Co-Authored-By: Claude Fable 5.2 <[email protected]>
Closes #110761
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added
input_format_try_infer_ipv4andinput_format_try_infer_ipv6settings (both disabled by default) that allow ClickHouse to automatically inferIPv4/IPv6types from string fields during schema inference for text formats, following the same pattern asinput_format_try_infer_dates.What does this PR do?
Adds two new opt-in format settings that allow ClickHouse to automatically infer
IPv4/IPv6types from string values during schema inference for text formats, following the same pattern as the existinginput_format_try_infer_dates/input_format_try_infer_datetimessettings.New settings
input_format_try_infer_ipv4falseIPv4from strings matching IPv4 address formatinput_format_try_infer_ipv6falseIPv6from strings matching IPv6 address formatHow it works
In
insertIntoSharedData(JSONExtractTree.cpp), after the existing Date/DateTime inference chain, two new blocks attempt to parse the string as IPv4/IPv6 using the already-existingIPv4Node::tryParse/IPv6Node::tryParsemethods. On a match, the value is encoded with its native binary type (BinaryTypeIndex::IPv4/IPv6) instead of falling back toString.Storage benefit
"192.168.100.200""10.0.0.1"Workflow [PR]
Sync PR [sync-upstream/pr/110766]