Skip to content

fix(cpp): preserve table time statistics in filtered metadata - #989

Open
ColinLeeo wants to merge 3 commits into
apache:developfrom
ColinLeeo:colin/fix-table-footer-statistics
Open

ColinLeeo wants to merge 3 commits into
apache:developfrom
ColinLeeo:colin/fix-table-footer-statistics

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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. If the timeline is missing or reports fewer rows than a selected field's non-null count, scan the rows before computing null_count.

Regression coverage checks filtered metadata and sparse table fields. Test-only metadata injection exercises missing, zero-count, and undersized timelines alongside an intact footer. Each case verifies the metadata state and complete CSV output, including a positive null count for the sparse field. Field aggregates still come from footer statistics when available; the fallback supplies the entity row count.

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.
  • Before the consistency check, the new zero-count and undersized-timeline cases reproduced negative or incorrect null counts.
  • After the fix, all 119 relevant reader, CLI, statistics, and metadata/empty-file golden tests passed; one existing test remains disabled.
  • Targeted C++ Spotless and whitespace checks passed.

ColinLeeo added a commit to ColinLeeo/tsfile that referenced this pull request Oct 5, 2026
Revert the statistics changes from dbccee3, including their later formatting, now maintained in apache#989. Keep PR apache#970 focused on table read error propagation and preserve its subsequent error handling changes.

Validation: Release build, 136 reader/CLI/statistics/golden/read-failure tests, targeted Spotless, and whitespace checks passed.
@ColinLeeo
ColinLeeo requested a balanced review from Copilot October 5, 2026 11:44

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Unreliable zero-count timelines can still bypass scanning and produce negative null counts, and the fallback branch lacks effective regression coverage.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Preserves aligned time statistics in filtered C++ metadata so CLI table statistics can report numeric null counts.

Changes:

  • Reuses offset-based metadata loading to retain shared time indexes.
  • Adds scan fallback logic for missing timelines.
  • Updates regression tests and golden outputs.
File Description
cpp/​src/​file/​tsfile_io_reader.cc Preserves aligned time metadata.
cpp/​tools/​commands/​cmd_stats.cc Expands scan fallback conditions.
cpp/​test/​reader/​tsfile_reader_test.cc Verifies filtered time indexes.
cpp/​test/​tools/​command_e2e_test.cc Adds sparse-field coverage.
cpp/​test/​tools/​golden/​table_stats_csv.txt Updates CSV null counts.
cpp/​test/​tools/​golden/​table_stats_ndjson.txt Updates NDJSON null counts.
cpp/​test/​tools/​golden/​table_stats_table.txt Updates table null counts.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +383 to +385
if (!it->second.has_timeline_statistic) {
need_scan = true;
break;
Comment thread cpp/test/tools/command_e2e_test.cc Outdated
Comment on lines +173 to +177
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants