Repository navigation
Support output Hive text format - #107582
Conversation
Add the HiveText output format, mirroring Apache Hive's LazySimpleSerDe text
serialization. Each row is written without quoting; top-level fields are
separated by the fields delimiter ('\001' by default) and rows by the rows
delimiter ('\n', configurable via the new format_hive_text_rows_delimiter
setting). Values of nested types (Array, Map, Tuple) are written without
brackets, separated by a delimiter derived from the fields delimiter by their
nesting level, the same way Hive does it.
Implemented via a new ISerialization::serializeTextHive() method (whose default
throws for types that Hive does not support) and a new HiveTextRowOutputFormat.
Reimplements #60737.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [1ed2085] Summary: ✅
AI ReviewSummaryThis PR adds Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 399/422 (94.55%) · Uncovered code |
`SerializationDate` and `SerializationDateTime` derive from `SerializationNumber`
and so inherited its numeric `serializeTextHive`, which writes the raw underlying
integer. As a result `SELECT toDate('2024-04-09') FORMAT HiveText` emitted `19822`
and `DateTime` emitted epoch seconds, while Hive text output expects date and
timestamp strings.
Override `serializeTextHive` for `SerializationDate` and `SerializationDateTime`
to delegate to `serializeText`, matching what `SerializationDate32` and
`SerializationDateTime64` already do, and fix the `03093` reference that recorded
the buggy `Date` output.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The new `format_hive_text_rows_delimiter` setting was declared as `UInt64` and then truncated with `static_cast<char>` before use, unlike the existing Hive delimiter settings (`input_format_hive_text_fields_delimiter` and friends) which are `Char`. That made it inconsistent to configure and silently accepted invalid values such as `256`. Declare it as `Char` and assign it directly into `FormatSettings::hive_text.rows_delimiter`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Covers `Date`, `Date32`, `DateTime` and `DateTime64` (which must be written as Hive date/timestamp strings rather than the underlying numeric values) and the `format_hive_text_rows_delimiter` setting with a non-default value, complementing the existing `03093` test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI Review ❌ Block verdict (both inline threads resolved):
Also merged One design item left for your call (not changed): |
The new stateless test was numbered 05018, leaving a gap from the previous highest number (4356) larger than 100, which the `test_numbers_check` style check rejects (`Gap (4356, 5018) > 100`). Renumber it to 04402. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`HiveText` output promises that only Hive-supported scalar types are serialized and that types with no natural Hive text representation throw `NOT_IMPLEMENTED`. But `SerializationEnum`, `SerializationTime` and `SerializationInterval` derive from `SerializationNumber` and so inherited its generic numeric `serializeTextHive`, silently emitting the raw underlying integer (the enum's number instead of its name, the time as raw seconds, the interval as a raw count). `SerializationTime64` already threw via the base default, but with a generic message. Hive has no `ENUM`, `TIME` or `INTERVAL` type, so these are not in the documented supported set. Add `serializeTextHive` overrides that throw `NOT_IMPLEMENTED` with a clear per-type message, making the contract hold instead of producing a lossy file. This is the conservative, non-additive direction: declining support rather than presuming a representation; supporting any of these (e.g. emitting the enum name) remains a follow-up decision. Adds `04403_hive_text_output_unsupported_types` covering all four types and documents the rejected types in the `HiveText` format reference. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the remaining AI Review ❌ Block finding and the red
Merged |
…-text-format # Conflicts: # tests/queries/0_stateless/02187_async_inserts_all_formats.python # tests/queries/0_stateless/03251_insert_sparse_all_formats.sh
|
Merged the latest CI failure analysis
Fix submitted to clickhouse-docs: ClickHouse/clickhouse-docs#6461 (escape all three labels with
|
…or nested types The nested `HiveText` output derived every separator from the fields delimiter by character arithmetic (`fields_delimiter + 1`, `fields_delimiter + 2`), which ignored the existing `input_format_hive_text_collection_items_delimiter` and `input_format_hive_text_map_keys_delimiter` settings and corrupted the output for any non-default fields delimiter (for example, fields `,` emitted array elements separated by `-` and map key/values by `.`). Thread an explicit nesting level (`FormatSettings::HiveText::nesting_level`) through the `Array`/`Map`/`Tuple` serializations and resolve each separator from Apache Hive's `LazySimpleSerDe` separator list via the new `getHiveTextDelimiter`: index 0 is the fields delimiter, 1 the collection-items delimiter, 2 the map-keys delimiter, and deeper levels default to consecutive control characters (`\x04`, `\x05`, ...). Data nested deeper than Hive's eight separators now throws `NOT_IMPLEMENTED` instead of emitting an out-of-range byte. Output for the default delimiters is byte-for-byte unchanged. Added `04489_hive_text_output_nondefault_delimiters` covering `Array`, `Map` and `Tuple` with non-default delimiters, and updated the `HiveText` format docs. Addresses the AI Review block on #107582 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Triaged this PR (continue-pr): no code change needed — it is effectively ready.
This PR only adds an output serialization path and does not touch query planning, so the fuzzer failure cannot be caused by it. Blocked solely on a fuzzer re-run (or #107719 landing) and a maintainer merge. |
The most recent merge of `master` brought in `04489_max_threads_auto_parsing_compat`, which collides on the `04489` numeric prefix with this PR's new `04489_hive_text_output_nondefault_delimiters`. Renumber the latter to `04490` (the next free number) so the two tests do not share a prefix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Continued this PR (continue-pr): merged latest What changed since the last triage GitHub flipped the PR to
Verification
Review / CI
Blocked solely on the fresh CI (and the unrelated fuzzer flake) plus a maintainer merge. |
…put_format `SerializationDateTime::serializeTextHive` and `SerializationDateTime64::serializeTextHive` delegated to `serializeText`, which honors `date_time_output_format`. With `date_time_output_format = 'unix_timestamp'` a `DateTime`/`DateTime64` value was emitted as epoch seconds again, and with `iso` it was emitted as `2024-04-09T12:34:56Z` — both forms that Hive cannot parse as a `TIMESTAMP`. So a deployment with a non-default session/server setting could produce `HiveText` files unreadable by Hive. Make the Hive serializers always write the simple Hive timestamp text (`yyyy-MM-dd HH:mm:ss[.fffffffff]`), bypassing `date_time_output_format`. `SerializationDateTime64::serializeTextHive` still honors `date_time_64_output_format_cut_trailing_zeros_align_to_groups_of_thousands`, which only affects the fractional part and stays Hive-parseable. `Date`/`Date32` were already insulated (their `serializeText` writes `writeDateText` unconditionally), so they are unchanged. Add `04491_hive_text_output_datetime_format_setting`, which asserts the output is the simple Hive timestamp text under `date_time_output_format` = `simple`, `unix_timestamp` and `iso`; the existing `04402` test only pinned `simple`, so it could not catch this. Document the behavior in the `HiveText` format reference. Addresses the AI Review "Request changes" verdict on PR #107582. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The change updated the legacy `docs/en/interfaces` pages and the embedded
`setDocumentation` block, but the Mintlify tree that actually backs the public
format reference was still input-only:
- `docs/reference/formats/index.mdx` marked `HiveText` output as `✗`.
- `docs/reference/formats/HiveText.mdx` declared `output_format: false` in its
frontmatter, and its generated body still described the format as input-only
with no mention of `format_hive_text_rows_delimiter`.
The overview-table row and the frontmatter flag are hand-maintained, so they are
edited directly. The page body lives inside an `AUTOGENERATED` region fed by
`system.formats`, so it is regenerated with the in-tree generator rather than
hand-written:
python3 ci/jobs/scripts/docs/autogenerate/autogenerate_docs.py \
--write --binary build/programs/clickhouse --docs-dir docs \
--only format:HiveText
`--check` for the same page now reports it as in sync. Because the diff touches
a generated region, the pull request carries the `pr-autogenerated-docs` label
that `ci/jobs/docs_job_mintlify.py` uses to skip the generated-region guard.
The settings reference under `docs/reference/settings/formats` is left to the
nightly generator: `format_hive_text_rows_delimiter` already carries its
docstring in `src/Core/FormatFactorySettings.h`, which is the only supported
source for those pages.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 389/412 (94.42%) · Uncovered code |
The initial commit excluded `HiveText` from `03251_insert_sparse_all_formats`, which is the end-to-end regression for the one self-compatibility guarantee the documentation and the PR body still make: top-level scalar fields written with the default fields delimiter and the default rows delimiter round-trip through `SELECT ... FORMAT HiveText | INSERT ... FORMAT HiveText`. The exclusion is not needed. `system.formats` is already filtered on `is_input AND is_output`, so builds without `USE_HIVE` (where only the output side is registered) drop `HiveText` from the list on their own. Verified against a local server that the `HiveText` iteration of `03251` produces the same `sum(sipHash64(*))` as every other format, including on the `enable_parsing_to_custom_serialization` path with sparse columns. Also add a focused `04693_hive_text_output_round_trip` regression that pipes a table of top-level scalars (including `Nullable` and `Bool`) through `FORMAT HiveText` and back, since `03251` is tagged `long` and is skipped in several build configurations. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)No arm_release build profile data for commit 1ed2085 - the build was skipped, reused from cache, or predates profile upload. |
…-text-format # Conflicts: # docs/en/interfaces/formats.md # docs/en/interfaces/formats/HiveText.md
The `HiveText` output format always writes `NULL` as Hive's default null sequence `\N`, but the CSV-based input side still read the null token from `format_csv_null_representation`, so with a non-default value of that setting the documented top-level scalar round-trip inserted the literal string `\N` instead of `NULL` (and `Nullable` numerics failed to parse). Pin `csv.null_representation` to `\N` in `updateFormatSettings`, next to the other CSV knobs the format already overrides, so both sides are independent of that setting, matching Hive's `LazySimpleSerDe`. Document it and add a focused regression test. Co-Authored-By: Claude Fable 5 <[email protected]>
| updated.csv.allow_variable_number_of_columns = settings.hive_text.allow_variable_number_of_columns; | ||
| /// Hive's `LazySimpleSerDe` always writes `NULL` as `\N` (and the `HiveText` output format | ||
| /// always emits `\N`), so accept it independent of `format_csv_null_representation`. | ||
| updated.csv.null_representation = "\\N"; |
There was a problem hiding this comment.
Pinning the input null token to \N still leaves one hole in the new top-level-scalar round-trip contract: SerializationNullable::deserializeTextCSVImpl checks settings.csv.null_representation before it delegates to the nested String serializer, so SELECT CAST('\\N', 'Nullable(String)') FORMAT HiveText | INSERT ... FORMAT HiveText comes back as NULL, not the original string. That is distinct from the already-documented Hive-side ambiguity for plain String: here the same-table ClickHouse self-round-trip loses data for a supported scalar type.
Please either narrow the contract/docs/tests to exclude Nullable(String) values equal to \N, or reject that value on output if the strict round-trip guarantee is supposed to hold.
Reimplements #60737.
Adds the
HiveTextoutput format, soSELECT ... FORMAT HiveTextand inserts into file-backed tables can produce the text serialization used by Apache Hive tables (Hive'sLazySimpleSerDe).HiveTextalready existed as an input format; this adds the output side. It targets Hive's defaultLazySimpleSerDe— see Compatibility for what this does and does not guarantee.Format
Each row is written without any quoting:
\x01(Ctrl-A) by default, controlled by the existinginput_format_hive_text_fields_delimitersetting;\nby default, controlled by the newformat_hive_text_rows_delimitersetting;Array,Map,Tuple) are written without brackets and are separated by Hive's separator list indexed by nesting level:\x02for collection items (controlled byinput_format_hive_text_collection_items_delimiter),\x03for map key/value pairs (controlled byinput_format_hive_text_map_keys_delimiter), and Hive's default deeper control characters (\x04,\x05, and so on), the same way Hive does it;Float32/Float64values are written using Hive's Java spellings —NaN,Infinity, and-Infinity— so they round-trip through Hive'sFLOAT/DOUBLEparser.Types that have no natural Hive text representation (for example
AggregateFunction,Dynamic,Variant,LowCardinality,Object) are not supported for output and throwNOT_IMPLEMENTED.Compatibility
The output targets Hive's default
LazySimpleSerDeand is not symmetric with ClickHouse's ownHiveTextinput:Array/Map/Tuplevalues are written with Hive's nested separators (no brackets), but the input format parses each field withCSV/bracketed rules and ignoresinput_format_hive_text_collection_items_delimiter/input_format_hive_text_map_keys_delimiter. So nested output such asSELECT [1, 2] FORMAT HiveTextis not read back byINSERT ... FORMAT HiveText— only top-level scalar fields round-trip, and only with the default\nrow delimiter.\nrow delimiter. Whenformat_hive_text_rows_delimiteris changed, the output separates rows with the configured byte, but the input side is still the newline-basedCSVRowInputFormatand there is no matchinginput_format_hive_text_rows_delimiter. So multi-row scalar output such asSELECT number FROM numbers(3) FORMAT HiveText SETTINGS format_hive_text_rows_delimiter=';'(which produces0;1;2;) is not read back byINSERT ... FORMAT HiveTextas three rows.LazySimpleSerDesubset is implemented: fields are written without escaping (no equivalent of Hive's optionalROW FORMAT DELIMITED ... ESCAPED BY), andNULLis always\N(no equivalent ofNULL DEFINED AS). AStringthat itself contains an active separator is written literally and will be misread when parsed back — this matches how Hive behaves with a non-escaping serde.Implementation
ISerialization::serializeTextHive()virtual method whose default implementation throws, overridden only by the data types Hive supports (numbers up to 64-bit — the 128/256-bit integer domains fit no Hive type and throw, string, decimal up to HiveDECIMAL's maximum precision of 38, date/datetime, bool, and the nestedArray/Map/Tuple/Nullablecontainers);HiveTextRowOutputFormat, registered unconditionally (it does not depend onUSE_HIVE, since output needs no Hive metastore).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added the
HiveTextoutput format that writes data in Apache HiveLazySimpleSerDetext form. Fields are separated by\x01, rows by the newformat_hive_text_rows_delimitersetting (default\n), and nestedArray,Map, andTuplevalues use Hive's separator list. The output targets Hive's defaultLazySimpleSerDeand is not symmetric with ClickHouse'sHiveTextinput for nested values or custom row delimiters.