Repository navigation
[Fix] Support unordered query results in COPY TO TsFile - #18928
Conversation
Sort COPY TO input by target tags and time before TsFile writing, preserving the inner query's LIMIT and OFFSET semantics. Skip sorting when timestamps are generated. Add planner unit tests for streaming sort, distributed merge, TopK and offset, aliases, and generated timestamps. Tests and compilation were not run as requested.
Cover descending time, field ordering, LIMIT and OFFSET, aliased timestamps and reordered tags, and exports without tags. Read back all rows and use small TsBlocks to exercise multiple write batches. Set MEMORY_THRESHOLD to 1000000 for the new cases. All five integration tests passed according to user validation; tests and compilation were not rerun by the agent.
Add integration coverage for plan output and normalize writer initialization failures to COPY_TO_WRITE_ERROR.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #18928 +/- ##
============================================
+ Coverage 46.42% 46.85% +0.43%
Complexity 713 713
============================================
Files 5537 5537
Lines 404332 404719 +387
Branches 52852 52915 +63
============================================
+ Hits 187717 189647 +1930
+ Misses 216615 215072 -1543 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JackieTien97
left a comment
There was a problem hiding this comment.
Requesting changes for the reproducible no-FROM COPY regression and the stale EXPLAIN error-message assertions that already fail CI.
Validation: a clean reactor run of OrderingPropertyPropagationTest (25 tests passed), a clean TableClusterIT run of IoTDBCopyToTsFileIT (27 tests passed on 1C3D), and targeted live 1C1D probes.
JackieTien97
left a comment
There was a problem hiding this comment.
Both previously reported issues are fixed in 600ba96.
Revalidated with a clean reactor build: all 26 OrderingPropertyPropagationTest tests and the two targeted integration tests passed, including IoTDBInsertQueryIT.testExplain. Six live 1C1D checks also passed, covering constant-query COPY, EXPLAIN and EXPLAIN ANALYZE in text/JSON formats, exported-file readback, expected file-creation behavior, and missing TIME-column validation.
No remaining blocking findings from this review.
Description
COPY TO TsFile currently fails when a SQL query returns timestamps out of order within a target device, for example with
ORDER BY time DESC. Add an outer sort by the target TAG columns and TIME after planning the complete inner query, so existing optimizers can use streaming scans, eliminate redundant sorts, and merge ordered region results. The inner query's ORDER BY, LIMIT, and OFFSET semantics are preserved.Both table shorthand and SQL query exports use this path. Exports with generated timestamps retain their existing behavior, and duplicate timestamps for the same target device remain subject to TsFile writer validation. No SQL option is added.
Support
EXPLAIN COPY ... TO ...andEXPLAIN ANALYZE COPY ... TO ...for both table shorthand and SQL query exports.EXPLAINdisplays the export plan without creating a file.EXPLAIN ANALYZEexecutes the export, creates the TsFile, and returns runtime statistics for the scan and COPY TO operators. Existing output formats andVERBOSEare supported where applicable. Preserve the inner query headers and export summary symbols through optimization and distributed planning.Normalize IOException failures during target-file creation and writer initialization to
COPY_TO_WRITE_ERROR (725), matching existing write and seal failures and preserving the concrete error message, such as an existing target file, during cascading task failure.Validation
MEMORY_THRESHOLD 1000000for the new integration cases, matching existing COPY TO tests.TableScanandCopyTo; useMEMORY_THRESHOLD 1000000and clean up temporary export files.This PR has: