You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@tsfile.apache.org by "ColinLeeo (via GitHub)" <gi...@apache.org> on 2026/10/05 07:54:20 UTC

[PR] fix(cpp): preserve table time statistics in filtered metadata [tsfile]

ColinLeeo opened a new pull request, #989:
URL: https://github.com/apache/tsfile/pull/989

   Filtered table metadata discarded the shared time index, so `tsfile-cli stats` could report an empty `null_count` even when the footer contained the entity row count. Reuse the existing offset-based metadata reader to retain the aligned time statistics, and fall back to scanning when the entity timeline is unavailable even if the selected fields have value statistics.
   
   Add regression coverage for filtered metadata and sparse table fields, and update the CSV, NDJSON, and table output expectations so fields without nulls report `0`.
   
   Validation:
   - Built `TsFile_Test` and `tsfile_cli` in an isolated Release build based on `develop`, with LZ4 enabled and the other optional codecs and ANTLR4 disabled.
   - 116 reader, CLI, statistics, and metadata/empty-file golden tests passed; one existing test remains disabled.
   - Targeted C++ Spotless and whitespace checks passed.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@tsfile.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(cpp): preserve table time statistics in filtered metadata [tsfile]

Posted by "ColinLeeo (via GitHub)" <gi...@apache.org>.
ColinLeeo commented on code in PR #989:
URL: https://github.com/apache/tsfile/pull/989#discussion_r4193118659


##########
cpp/tools/commands/cmd_stats.cc:
##########
@@ -371,20 +371,29 @@ int collect_table_stats(const ParsedArgs& args,
         summary.entity_order.push_back(key);
     }
 
-    bool missing_value_statistics = false;
+    // A row count is required to derive a numeric null_count.  It comes
+    // either from the entity timeline statistic or, when that statistic is
+    // absent/unreliable, from a row scan.  Trigger the scan whenever any
+    // entity still lacks a timeline (even if every selected field carries a
+    // value statistic), otherwise null_count would stay empty.
+    bool need_scan = false;
     for (const std::string& key : summary.entity_order) {
         const auto it = summary.entities.find(key);
         if (it == summary.entities.end()) continue;
+        if (!it->second.has_timeline_statistic) {
+            need_scan = true;
+            break;

Review Comment:
   For the normal aligned-table write path, the time statistic counts every row, while each field statistic counts only non-null values from the same row ranges. These counts are aggregated into the footer, so the time count should be at least each field's non-null count. Partial write failures also prevent successful flush/close.
   
   We have not identified a valid-file case that violates this invariant; the earlier reproduction relied on manually injected inconsistent metadata. We therefore removed the additional scan fallback and its injection tests in 4c5042f3a, keeping this PR scoped to preserving the shared time index in filtered metadata.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@tsfile.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(cpp): preserve table time statistics in filtered metadata [tsfile]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #989:
URL: https://github.com/apache/tsfile/pull/989#discussion_r4183644705


##########
cpp/tools/commands/cmd_stats.cc:
##########
@@ -371,20 +371,29 @@ int collect_table_stats(const ParsedArgs& args,
         summary.entity_order.push_back(key);
     }
 
-    bool missing_value_statistics = false;
+    // A row count is required to derive a numeric null_count.  It comes
+    // either from the entity timeline statistic or, when that statistic is
+    // absent/unreliable, from a row scan.  Trigger the scan whenever any
+    // entity still lacks a timeline (even if every selected field carries a
+    // value statistic), otherwise null_count would stay empty.
+    bool need_scan = false;
     for (const std::string& key : summary.entity_order) {
         const auto it = summary.entities.find(key);
         if (it == summary.entities.end()) continue;
+        if (!it->second.has_timeline_statistic) {
+            need_scan = true;
+            break;

Review Comment:
   `has_timeline_statistic` does not establish that the timeline is reliable: `capture_timeline_statistic` sets it for any non-null statistic, including a zero-count statistic. If a legacy/invalid timeline reports 0 while a selected field has a positive count, this branch skips the scan and later computes a negative `null_count`. Treat a timeline whose row count is below any selected field count as needing a scan.



##########
cpp/test/tools/command_e2e_test.cc:
##########
@@ -165,11 +165,55 @@ TEST(CliE2E, StatsReportsCountAndTimeRange) {
               std::string::npos)
         << out.str();
     EXPECT_NE(out.str().find("table,table1,id1_field_1,id2_field_2,s1,INT64,"
-                             "5,\\N,0,4,0,40,0,40,\\N,statistics"),
+                             "5,0,0,4,0,40,0,40,\\N,statistics"),
               std::string::npos)
         << out.str();
 }
 
+TEST(CliE2E, StatsReportsNumericNullCountForTableFields) {
+    // A FIELD whose value statistic is present but whose entity timeline
+    // statistic is unavailable must still get a numeric null_count by
+    // scanning (TsFile-143): null_count previously stayed empty even though
+    // the field's non-null count was known.

Review Comment:
   This test does not exercise the fallback described in its comment. It writes a current-format table and the reader change in this PR preserves that table's shared time statistic, so `has_timeline_statistic` is true and no scan is required; the substring assertions also omit `stats_source`. Add a fixture or injection with a genuinely missing/unreliable timeline and verify that the scan-derived row count is used.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@tsfile.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(cpp): preserve table time statistics in filtered metadata [tsfile]

Posted by "ColinLeeo (via GitHub)" <gi...@apache.org>.
ColinLeeo merged PR #989:
URL: https://github.com/apache/tsfile/pull/989


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@tsfile.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org