Skip to content

test(cpp): cover the extended C wrapper API - #1130

Merged
ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/cpp-cwrapper-tests
Nov 20, 2026
Merged

ColinLeeo merged 2 commits into
apache:developfrom
ColinLeeo:colin/cpp-cwrapper-tests

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The C wrapper is the surface the Python bindings call, but several of its entry points had zero C++ test coverage (41 of 168 functions in tsfile_cwrapper.cc at the time of writing).

cpp/test/cwrapper/cwrapper_extended_test.cc now covers:

  • global time encoding/compression setters and getters, plus set_allow_non_decreasing_timestamps
  • tablet_get_cur_row_size, typed adders by name/index (float, bool, int32)
  • tsfile_writer_flush
  • result-set getters by index (int32/int64/float/double/bool), is_null_by_index, binary cell copies, get_metadata plus the metadata accessors, and free_result_set_meta_data
  • tsfile_reader_query_table (offset/limit pages are compared against the full result by row identity), tsfile_query_table_batch, and tsfile_result_set_get_next_tsblock_as_arrow
  • an Arrow write through tsfile_writer_write_arrow, verified by reopening the file and checking row count, timestamps and every typed value
  • tag filter and/or/not composition and tsfile_query_table_with_tag_filter
  • schema-array release helpers (tsfile_free_table_schema_array, tsfile_free_device_schema_array)
  • the legacy device/record path (_tsfile_writer_register_device, typed record inserts, _tsfile_writer_write_ts_record, _tsfile_writer_flush) and tsfile_query_table_on_tree
  • generic-writer table write via _tsfile_writer_write_table

Measured with this build: tsfile_cwrapper.cc 71.8% lines (1507/2099) and 162/171 functions; arrow_c.cc 77.5% lines (527/680) and 27/28 functions. The remaining prepared-series functions require a dataset-index locator that the C API does not expose. _tsfile_writer_write_arrow_table is not asserted: the generic writer does not persist Arrow field values for this tablet layout, so the test does not encode that behavior.

Test plan

  • ./mvnw -B clean verify -P with-java,with-python -Denable.lzma2=ON (Java, C++, Python; 1858 C++ tests passed)
  • ./mvnw -B clean verify -P with-cpp -Denable.asan=ON -Dbuild.type=RelWithDebInfo -Denable.lzma2=ON (1859 tests, 0 failed; macOS run used the Xcode 26.6 toolchain with ASAN_OPTIONS=detect_container_overflow=0 for the uninstrumented ANTLR runtime)
  • ./mvnw spotless:check -P with-java,with-python

Exercise the C parts of the wrapper that the Python bindings use but the
C++ suite never reached: global time encoding/compression setters and
getters, tablet row-count/typed adders, writer flush, result-set value
getters and metadata accessors, binary cell copies, reader query
variants (offset/limit, inverted range, batch), Arrow block export and
Arrow table writes through both writers, tag filter and/or/not
composition, schema-array release helpers, and the legacy device/record
write path.

tsfile_cwrapper.cc: 62.5% -> 73.5% line coverage (163/168 functions);
arrow_c.cc: 69.9% -> 77.5% (27/28 functions). The remaining prepared-series
entry points need a dataset-index locator that is not exposed through the
C API.

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.

🟡 Changes recommended

The tests can pass despite ignored offsets, missing Arrow output data, or query execution errors, leaving key wrapper behavior unverified.

3 open issues
What changed in this PR

This PR expands C++ test coverage for the C wrapper used by Python bindings, covering previously untested entry points without changing production code.

Changes:

  • Adds coverage for configuration, tablet helpers, typed result getters, metadata, and schema cleanup.
  • Exercises pagination, batch and Arrow queries, and composed tag filters.
  • Tests legacy record writes, generic table writes, and both Arrow writer APIs.
File Description
cpp/​test/​cwrapper/​cwrapper_extended_test.cc Adds shared fixtures and eight tests covering extended C wrapper APIs.

Review effort: Balanced

Address review feedback:
- compare the offset/limit page against the full result by row identity so
  a wrapper that ignores the offset cannot pass
- make count_result_rows fail when next() returns an error instead of
  mistaking it for an empty result set
- read the Arrow-written table back and check the row count, timestamps and
  typed values

The legacy _tsfile_writer_write_arrow_table path is no longer asserted: the
generic writer does not persist Arrow field values for this tablet layout,
so asserting its output would enshrine a defect in an unused internal API.

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.

🔵 Needs a closer look

Tests lack assertions for the batch-size limit, negated-filter tag identity, and timestamp-policy state, allowing regressions in all three behaviors to pass.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity Verify wrapper toggles update the native timestamp policy

cpp/​test/​cwrapper/​cwrapper_extended_test.cc:294

These assertions only check return codes, so a wrapper that always returns RET_OK without changing the timestamp policy passes both calls. Please assert the native configuration after each toggle so this test verifies that the C wrapper actually enables and disables the option.

Medium severity Test that each returned batch respects the requested size

cpp/​test/​cwrapper/​cwrapper_extended_test.cc:403

The query requests a batch size of 3, but this loop only checks that batches are nonempty and total 10 rows. A regression that substitutes a larger positive batch size would still pass (for example, returning each device's five rows in one block). Please assert that every returned block contains at most 3 rows so this test verifies the batch-size argument as well as row preservation.

Medium severity Verify the negated tag filter returns only devB rows

cpp/​test/​cwrapper/​cwrapper_extended_test.cc:521

Both devA and devB have five rows, so this assertion passes even if tsfile_tag_filter_not simply returns its input without negating it: the query would return five devA rows instead of five devB rows. Please also check that every returned TAG is devB to distinguish the predicate from its complement.

3 resolved since last review

Review effort: Balanced

@ColinLeeo
ColinLeeo merged commit 6c4ad79 into apache:develop Nov 20, 2026
36 checks passed
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