Skip to content

Add setting to omit CSV quotes for date and time types - #107292

Closed
cristhiank wants to merge 33 commits into
ClickHouse:masterfrom
cristhiank:users/crilopez/csv-quote-date-time-types
Closed

cristhiank wants to merge 33 commits into
ClickHouse:masterfrom
cristhiank:users/crilopez/csv-quote-date-time-types

Conversation

@cristhiank

@cristhiank cristhiank commented Jun 11, 2026 •

Copy link
Copy Markdown

Related: #34668

Adds output_format_csv_quote_date_time_types, a backward-compatible CSV output setting for users that need date and time values emitted without surrounding double quotes while keeping existing CSV behavior by default.

The setting applies to Date, Date32, DateTime, DateTime64, Time, and Time64 values in CSV output. Strings remain quoted according to the existing CSV serializer and numbers are unchanged. CSV input parsing is unchanged and already accepts both quoted and unquoted date and time values.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Adds the setting output_format_csv_quote_date_time_types. When disabled, Date, Date32, DateTime, DateTime64, Time, and Time64 values are written without surrounding double quotes in CSV output, while preserving the existing quoted behavior by default.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Workflow [PR]
Sync PR [sync-upstream/pr/107292]

@CLAassistant

CLAassistant commented Jun 11, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Add a backward-compatible CSV output setting that lets users emit date and time values without surrounding double quotes while preserving the existing quoted behavior by default.

Co-authored-by: Copilot <[email protected]>
@cristhiank
cristhiank force-pushed the users/crilopez/csv-quote-date-time-types branch from 2bd5ffa to e4dc85e Compare June 11, 2026 23:27
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [de8e1bf]


AI Review

Summary

Adds output_format_csv_quote_date_time_types and delimiter-aware CSV tuple framing. Two remaining boundary errors prevent round trips; one also breaks existing non-temporal input with default settings.

Findings

❌ Blockers

  • SerializationDateTime64.cpp:41: A . separator is still ambiguous when no fractional suffix is emitted. In CustomSeparated, DateTime64(0) followed by 42 emits 2024-01-18 09:45:01.42; the timestamp reader consumes .42 and loses the next field. Trimmed whole-second values and flattened tuples have the same problem. Preserve quoting or bound the read to the field.
  • SerializationTuple.cpp:939: Legacy flattened parsing takes precedence only for temporal-capable tuples. With tuple delimiter ., outer delimiter .-, and Tuple(String, Int8), valid bytes "('y',-5)".-5.-42 are misread as a whole tuple followed by another field. This breaks previously accepted input with default quoting. Apply the ambiguity handling to non-temporal tuples too.
Tests
  • ⚠️ Add CustomSeparated output-to-input round trips for DateTime64(0) and trimmed whole-second DateTime64(3) with a . boundary, including a flattened tuple.
  • ⚠️ Add a non-temporal tuple regression with a tuple-shaped first string and a prefixed outer delimiter; retain default quoting.
Missing context / blind spots
  • ⚠️ Local SQL reproductions were not executed: this checkout has no built binary, and the current CI build reports expose no binary artifact. The findings follow concrete traces through the current writer and reader; running the supplied inline SQL would provide runtime confirmation.
Final Verdict

❌ Block — Fix both framing errors and add the focused round-trip regressions above.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 12, 2026
@cristhiank

Copy link
Copy Markdown
Author

Gentle reminder on this one. This is my first time contributing, so please let me know if there’s anything else I need to do on my end. @nikitamikhaylov Thanks!

@yariks5s yariks5s self-assigned this Jul 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR adds the output_format_csv_quote_date_time_types setting and reworks CSV serialization of Date/DateTime/Time types — it does not touch the query-execution path that ClickBench SELECTs run. Both flagged ClickBench queries (Q4 -17.6%, Q15 -19.8%) show apparent speedups, but the deterministic gates correctly kept them as no_change: both medians sit inside master's current variance band and the small source sample (6 runs) makes a consistent ~18-20% dip look like noise rather than signal. No real PR-attributable change here; nothing to action.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: bfad5701-aebf-4f17-8740-6468484166c3
  • MIRAI run: f7f85cef-e19e-4831-8831-e47439ff20d6
  • PR check IDs:
    • clickbench_330398_1783859685
    • clickbench_330404_1783859685
    • clickbench_330411_1783859685
    • tpch_adapted_1_official_330421_1783859685
    • tpch_adapted_1_official_330427_1783859685
    • tpch_adapted_1_official_330436_1783859685

@yariks5s

yariks5s commented Jul 7, 2026

Copy link
Copy Markdown
Member

@cristhiank could you please update your branch with master? The current branch is 26.7 so we should add the new setting to a 26.7 block in SettingsChangesHistory.cpp

@yariks5s yariks5s added the close in a month if not active This will be closed in case of no information label Jul 8, 2026
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
@cristhiank

Copy link
Copy Markdown
Author

Thanks @yariks5s , I've pushed the changes to match the latest branch.

@alexey-milovidov alexey-milovidov removed the close in a month if not active This will be closed in case of no information label Jul 11, 2026
Review: ClickHouse#107292 (comment)

PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
Review: ClickHouse#107292 (comment)

PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
Comment thread src/Formats/EscapingRuleUtils.cpp Resolved
Review: ClickHouse#107292 (comment)

PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
Review: ClickHouse#107292 (comment)

PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
PR: ClickHouse#107292

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 91cf4795-752a-44db-97d3-4a513bf1a63c
@clickhouse-gh

clickhouse-gh Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Dear @yariks5s, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
auto-merge was automatically disabled August 9, 2026 19:17

Head branch was pushed to by a user without write access

@cristhiank
cristhiank requested a review from yariks5s August 9, 2026 20:00
Use the outer field settings for the final tuple element in both the writer and reader whole-field gates. Add direct and inverse-delimiter regressions for `CustomSeparated` and `Template`.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
Make `SerializationTuple` quote-capability checks mirror its own interior and final-element settings. This prevents a nested whole-field fallback from creating a partially quoted outer tuple field while preserving safe flattened output.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
@clickhouse-gh

clickhouse-gh Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 8ad8e5250c49e347d60842202ca689060f89343b was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

cristhiank and others added 2 commits August 10, 2026 16:01
Match CSV quote capability checks to the single-field representation used by `SerializationNullable`, and cover leading, trailing, and nested tuple boundaries.

Review: ClickHouse#107292 (comment)

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
Reuse the format-owned `PeekableReadBuffer` so ambiguous `Template` and `CustomSeparated` tuple fields can retry without losing delimiter bytes across input chunks.

Review: ClickHouse#107292 (comment)

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
ClickHouse#107292

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
ClickHouse#107292 (comment)

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
Propagate row-aware CSV quote decisions through `Variant` and `Dynamic` while preserving flattened safe and NULL rows.

Related: ClickHouse#107292 (comment)

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 2b8fb69c-169e-45bf-8ff9-c78ca9dd6a9f
@abashkeev abashkeev added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Sep 4, 2026
alexey-milovidov and others added 2 commits September 26, 2026 23:29
…quote-date-time-types

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

- retargeted PR record [email protected] to 26.10 (settings-history check rule)

Also resolved conflicts in:
- `src/DataTypes/Serializations/SerializationDynamic.cpp`
- `src/Formats/EscapingRuleUtils.cpp`

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…quote-date-time-types

# Conflicts:
#	src/DataTypes/Serializations/SerializationTuple.cpp
const bool writes_fractional_part = scale > 0
&& (!cut_trailing_zeros_align_to_groups_of_thousands
|| value.value % DecimalUtils::scaleMultiplier<DateTime64::NativeType>(scale) != 0);
return delimiter == '-' || delimiter == ':' || delimiter == ' ' || (writes_fractional_part && delimiter == '.');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve dot delimiters even when the timestamp has no fractional output

The quote decision must also account for what the reader can consume. readDateTimeTextImpl for DateTime64 always accepts a following . and consumes the subsequent digits, including when scale == 0. Thus an otherwise valid CustomSeparated round trip now fails:

SELECT * FROM format(
    CustomSeparated, 'dt DateTime64(0), n UInt8',
    formatRow('CustomSeparated', toDateTime64('2024-01-18 09:45:01', 0), 42::UInt8))
SETTINGS output_format_csv_quote_date_time_types = 0,
    format_custom_escaping_rule = 'CSV',
    format_custom_field_delimiter = '.',
    format_custom_row_after_delimiter = '\n',
    input_format_custom_detect_header = 0;

The writer emits 2024-01-18 09:45:01.42, and the timestamp reader consumes .42, leaving no separator or second column. The same problem affects whole-second DateTime64(3) values with trailing-zero cutting enabled, including the flattened tuple output asserted by the new test. Please retain quotes for this boundary or make the reader field-bounded, and add round-trip coverage rather than only checking the emitted bytes.

&& *peekable_buf.position() == settings.csv.tuple_delimiter
&& !settings.csv.tuple_delimiter_matches_field_delimiter;

if (tuple_delimiter_follows && boundary_follows && may_use_whole_csv_field)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve ambiguous flattened tuples without temporal leaves

Whole-field detection runs for quoted non-temporal tuples too, but the legacy-flattened preference here is restricted to may_use_whole_csv_field. For Tuple(String, Int8) that flag is false, so a tuple-shaped first string is mistaken for the entire tuple when the outer delimiter matches the beginning of the interior delimiter plus the next value. This breaks existing input even with the new setting left at its default:

SELECT * FROM format(
    CustomSeparated, 't Tuple(String, Int8), n UInt8',
    formatRow('CustomSeparated', tuple('(''y'',-5)', -5::Int8), 42::UInt8))
SETTINGS format_csv_delimiter = '.',
    format_custom_escaping_rule = 'CSV',
    format_custom_field_delimiter = '.-',
    format_custom_row_after_delimiter = '\n',
    input_format_custom_detect_header = 0;

The valid flattened bytes are "('y',-5)".-5.-42. Both boundary checks succeed after the first quoted string, but this condition skips the flattened parse; tryDeserializeText then accepts ('y',-5) as the whole tuple. The reader consumes the wrong boundary and subsequently fails. Preserve the flattened interpretation for non-temporal tuples as well, and add this variant alongside the existing temporal ambiguity regression.

@cristhiank cristhiank closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants