You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(cpp): keep NULL column for series with no data in query range - #1146
A multi-path query in the C++ (and Python) SDK drops a selected column when the measurement exists in the file but has no data inside the query time range. The following columns then shift into the dropped column's position, silently returning wrong data. Java keeps the column and returns NULL for it.
Root cause
QDSWithoutTimeGenerator::init_internal treated every E_NO_MORE_DATA returned by alloc_ssi as "measurement does not exist" and dropped the path. But alloc_ssi also returns E_NO_MORE_DATA when the measurement exists yet has no data in the range (its timeseries index statistic is pruned by the time filter).
Fix
alloc_ssi now reports a bloom-filter miss (measurement truly absent) as E_NOT_EXIST instead of E_NO_MORE_DATA, so callers can tell the two cases apart. It also exposes the series data type via a new optional out-param for the exists-but-empty-in-range case.
QDSWithoutTimeGenerator::init_internal keeps the column (with a NULL value and the correct data type) when the series exists but is empty in range, and only drops the column when the series does not exist.
QDSWithTimeGenerator::construct_node_tree keeps its leaf for the not-found codes as well, preserving the existing behavior for missing series.
Test
Added TsFileReaderTest.MultiPathKeepsNullColumnForSeriesEmptyInRange: a two-series query where v1 has data only outside the range and v2 has data inside it; asserts 3 columns (time, root.t.v1, root.t.v2) with v1 NULL and v2 values aligned.
A multi-path query dropped the column of a selected measurement that
exists in the file but has no data inside the query time range, shifting
the values of the following columns into the wrong positions. This aligns
C++ with the Java behavior: keep the column and return NULL for it.
alloc_ssi now reports a bloom-filter miss (measurement truly absent) as
E_NOT_EXIST instead of E_NO_MORE_DATA, and exposes the series data type
for the exists-but-empty-in-range case. QDSWithoutTimeGenerator keeps a
NULL column with the correct type for the latter and only drops the
column when the measurement does not exist.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The existing missing-series test never reaches the new predicate branch, leaving OR/AND behavior, safe result destruction, and metadata not-found paths without regression coverage.
This PR fixes column shifting in C++ range-query results, also used by the Python SDK, by retaining NULL columns for existing series with no data in the requested range.
Changes:
Distinguishes missing series from existing series pruned by the time filter and exposes their data types.
Preserves empty-column positions and handles missing-series predicate leaves.
Adds a regression test for column names, types, NULL values, and value alignment.
File
Description
cpp/test/reader/tsfile_reader_test.cc
Adds coverage for retaining an empty-in-range column.
cpp/src/reader/qds_without_timegenerator.cc
Retains typed NULL columns and safely handles null iterator placeholders.
cpp/src/reader/qds_with_timegenerator.cc
Treats missing predicate series as empty leaves.
cpp/src/file/tsfile_io_reader.h
Adds an optional series-type output parameter.
cpp/src/file/tsfile_io_reader.cc
Separates bloom-filter misses from range pruning and reports pruned series types.
The construct_node_tree change keeps a leaf (empty stream) for a series
that does not exist in the file but appears in the query predicate. Add
regression tests for that path: OR preserves the live series' timestamps,
AND returns no rows, and the result set stays destroyable. Cover both a
missing measurement and a missing device.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The regression tests leave the single-path/null-iterator branch and all-empty dataset lifecycle uncovered, including metadata retention, rowless iteration, and safe destruction.
Add tests for single-path and all-empty query lifecycles
cpp/test/reader/tsfile_reader_test.cc:2367
This regression covers an empty column only alongside a live iterator, leaving the new single-path/null-iterator branch and the all-empty dataset lifecycle untested. Please add single-path and all-selected-paths-empty queries that check retained column names and types, next() returning E_OK with no rows, and safe destruction.
The reason will be displayed to describe this comment to others. Learn more.
I verified the column-position fix on dd0981df. The result kept the declared types when one or all selected series were empty in the requested range. It also kept the live value in the correct column when the projection included an empty series, a missing series, and a live series. Please document this distinction in the SDK skill under skills/tsfile/ so callers can rely on the result schema.
The reason will be displayed to describe this comment to others. Learn more.
[P2] Preserve errors while loading predicate metadata.do_load_timeseries_index() overwrites the return code with E_NOT_EXIST whenever found is false, including when TimeseriesIndex::deserialize_from() failed with E_OOM. This branch then turns that error into a successful empty predicate leaf. For a query that selects a and filters on a OR b, a failure to load the index for b can silently drop timestamps matched only by b.
Please return E_NOT_EXIST only after a complete scan of the index range finds no match, and propagate deserialization errors. A regression test should check that a metadata failure on a predicate-only series reaches the caller while a genuinely missing series still yields an empty leaf. Index scan and error handling
The reason will be displayed to describe this comment to others. Learn more.
[P3] Keep the five-argument alloc_ssi symbol for existing C++ clients. I compiled a caller against the previous header. The same object linked with the previous library and failed to link with this PR's library because the five-argument symbol was missing. This affects clients that call TsFileIOReader directly through the installed header. Keeping an out-of-line five-argument overload that forwards nullptr to the new six-argument overload would preserve binary compatibility. The six-argument overload can require its final argument to keep overload resolution unambiguous.
do_load_timeseries_index() only maps a fully-scanned, no-match index range
to E_NOT_EXIST; deserialization errors such as E_OOM now propagate instead
of being swallowed as a missing series.
Keep the five-argument alloc_ssi() overload so clients compiled against the
previous header keep linking; the new six-argument overload carries the
optional series-type out-param.
Add regression tests for a single selected series that is empty in the
query range and for all-selected-series-empty queries, asserting retained
column names/types, no rows, and safe destruction.
Document the tree-model result-column semantics (empty-in-range keeps a
typed NULL column; a missing measurement drops the column) in the SDK
skill so callers can rely on the result schema.
The reason will be displayed to describe this comment to others. Learn more.
[P2] Propagate partial reads inside a timeseries index entry.deserialize_buf_not_enough(ret) also matches E_PARTIAL_READ when the buffer ends halfway through the current entry. Returning E_NOT_EXIST in that case makes the query treat an unreadable predicate series as absent. For an a OR b query, this can silently omit timestamps matched only by b.
Please check bs.has_remaining() before starting each entry, as do_load_timeseries_index_range() does below. Return E_NOT_EXIST only after scanning complete entries without a match, and propagate errors from any entry whose deserialization has started. A regression test should cover both a complete range with no matching measurement and a range ending inside an entry.
do_load_timeseries_index() now only scans complete entries, checking
bs.has_remaining() before each one, and returns E_NOT_EXIST solely after a
full scan without a match. A deserialization error mid-entry
(E_PARTIAL_READ, E_OOM, ...) is propagated instead of being masked as a
missing series.
Start each merged row at the first path with its timestamp. Keep the reader on predicate streams so cleanup releases their scan iterators through the owning reader.
Cover the difference between a missing measurement and an incomplete index entry, and document tree-query projection semantics.
Track the statistic allocation when replacing it so short reads and index reuse release the correct storage. Cover the failure path and the all-null row on a shared aligned timestamp, and clarify the tree query contract.
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
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.
Problem
A multi-path query in the C++ (and Python) SDK drops a selected column when the measurement exists in the file but has no data inside the query time range. The following columns then shift into the dropped column's position, silently returning wrong data. Java keeps the column and returns NULL for it.
Root cause
QDSWithoutTimeGenerator::init_internaltreated everyE_NO_MORE_DATAreturned byalloc_ssias "measurement does not exist" and dropped the path. Butalloc_ssialso returnsE_NO_MORE_DATAwhen the measurement exists yet has no data in the range (its timeseries index statistic is pruned by the time filter).Fix
alloc_ssinow reports a bloom-filter miss (measurement truly absent) asE_NOT_EXISTinstead ofE_NO_MORE_DATA, so callers can tell the two cases apart. It also exposes the series data type via a new optional out-param for the exists-but-empty-in-range case.QDSWithoutTimeGenerator::init_internalkeeps the column (with a NULL value and the correct data type) when the series exists but is empty in range, and only drops the column when the series does not exist.QDSWithTimeGenerator::construct_node_treekeeps its leaf for the not-found codes as well, preserving the existing behavior for missing series.Test
Added
TsFileReaderTest.MultiPathKeepsNullColumnForSeriesEmptyInRange: a two-series query wherev1has data only outside the range andv2has data inside it; asserts 3 columns (time,root.t.v1,root.t.v2) withv1NULL andv2values aligned.