Skip to content

Bind named TAG and FIELD expressions in C++ table queries - #1186

Open
ColinLeeo wants to merge 4 commits into
developfrom
refactor/cpp-table-filter-input
Open

ColinLeeo wants to merge 4 commits into
developfrom
refactor/cpp-table-filter-input

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Changes

C++ table queries accept a borrowed const Expression* for each of tag_filter and field_filter. Applications can construct the expression by column name before opening the file. Query preparation binds its own copy against the table schema, so the result can outlive the input. The C wrapper keeps its handle and ownership contract.

TAG conditions bind to STRING device-ID segments. Aligned and non-aligned table reads share one FieldFilter. It binds literals to the declared FIELD types and classifies both pages and chunks using the same statistics rules. An aligned page reuses a full FIELD match from chunk or page statistics even when its time predicate selects only some timestamps. The device iterator owns the TAG filter. The result's block reader owns the TIME and FIELD filters and lends them to each per-device reader. The tree query entry points and execution paths are unchanged. The table API no longer exposes positional TAG constructors or the row-filter callback.

Multi-TAG regression

In a table with TAGs site and line, a device with a missing trailing line can be the first index entry. Inferring the TAG count from that entry made site = 'A' omit a device with (site='A', line='B'). A direct device lookup now requires a single TAG in the table schema. The regression checks the exact row values, rejects an ambiguous prepared series and prepares a series when both TAGs select one device.

Upgrading C++ applications

Replace indexed TAG constructors and FIELD filter builders with named expressions. For a TAG-only query with an explicit batch size, pass tag_filter.get(), nullptr, batch_size after the result-set argument. Recompile and relink applications using the headers and library from the same SDK. The package version, ABI epoch (1), and platform library names stay at their existing values.

Verification

  • C++ Release and Python through Maven with LZMA2 enabled (1,952 C++ tests passed, 714 Python tests passed and 16 skipped)
  • C++ RelWithDebInfo with ASan/UBSan and LZMA2 enabled (1,953 tests passed)
  • Linux instrumented Python ownership tests (15 passed with libtsfile.so.1)
  • Go vet, test and race suites against the rebuilt library
  • macOS install name (libtsfile.1.dylib) and MinGW import library target (libtsfile.dll)

@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.20721% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.51%. Comparing base (42f03c6) to head (63924c0).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
cpp/src/reader/filter/field_filter.cc 80.68% 20 Missing and 14 partials ⚠️
cpp/src/cwrapper/tsfile_cwrapper.cc 81.81% 3 Missing and 3 partials ⚠️
cpp/src/reader/filter/bind_expression.cc 90.76% 2 Missing and 4 partials ⚠️
cpp/src/reader/filter/bind_expression.h 69.23% 0 Missing and 4 partials ⚠️
cpp/src/reader/tsfile_reader.cc 80.00% 0 Missing and 4 partials ⚠️
cpp/src/reader/aligned_chunk_reader.cc 91.17% 1 Missing and 2 partials ⚠️
...p/src/reader/block/single_device_tsblock_reader.cc 90.90% 0 Missing and 3 partials ⚠️
cpp/src/reader/expression.cc 94.91% 0 Missing and 3 partials ⚠️
cpp/src/reader/filter/tag_filter.cc 94.23% 1 Missing and 2 partials ⚠️
cpp/src/reader/table_query_executor.cc 81.81% 0 Missing and 2 partials ⚠️
... and 3 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1186      +/-   ##
===========================================
+ Coverage    69.48%   69.51%   +0.03%     
===========================================
  Files          798      798              
  Lines        59120    58721     -399     
  Branches      9639     9562      -77     
===========================================
- Hits         41077    40822     -255     
+ Misses       16254    16116     -138     
+ Partials      1789     1783       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Querying a missing table with a different batch size deletes the executor still borrowed by live results, so advancing or closing them can access freed memory. Separately, retaining ABI epoch 1 despite public symbol, layout, and virtual-table changes allows existing binaries to load an incompatible library; filtered queries also return E_NOT_SUPPORT for previously accepted Java-written tables with TEXT TAG columns.

3 open issues
What changed in this PR

Adds schema-bound, named TAG and FIELD expressions to Apache TsFile’s C++ table-query API.

Changes:

  • Introduces borrowed expressions with query-owned filter bindings.
  • Unifies FIELD evaluation and statistics pruning, and corrects multi-TAG lookup.
  • Updates CLI integration, examples, documentation, and regression tests.
File Description
skills/​tsfile/​references/​properties-filters.md Documents expressions, ownership, and migration.
skills/​tsfile/​references/​advanced-apis.md Updates table-query parameter guidance.
cpp/​tools/​commands/​row_query.cc Uses named TAG expressions.
cpp/​tools/​commands/​commands.h Removes the exposed TAG-building helper.
cpp/​test/​tools/​model_format_e2e_test.cc Tests full-value regex alternatives.
cpp/​test/​reader/​table_view/​tsfile_reader_table_test.cc Migrates queries and tests multi-TAG lookup.
cpp/​test/​reader/​table_read_failure_test.cc Updates expression and C-wrapper queries.
cpp/​test/​reader/​filter/​tag_filter_test.cc Tests TAG binding and null semantics.
cpp/​test/​reader/​filter/​field_filter_test.cc Tests shared FIELD evaluation and classification.
cpp/​test/​reader/​field_filter_regression_test.cc Migrates regressions and adds range coverage.
cpp/​test/​reader/​chunk_reader_resource_test.cc Updates filter-binding and reader setup.
cpp/​test/​reader/​block/​masked_bulk_copy_test.cc Uses bound FIELD filters.
cpp/​test/​reader/​aligned_wide_table_small_block_test.cc Updates executor calls.
cpp/​test/​reader/​aligned_chunk_reader_bulk_test.cc Tests chunk pruning and FIELD-match reuse.
cpp/​test/​cwrapper/​cwrapper_extended_test.cc Tests composition guards and handle lifetime.
cpp/​src/​reader/​tsfile_series_scan_iterator.h Adds shared-filter chunk classification.
cpp/​src/​reader/​tsfile_series_scan_iterator.cc Classifies chunks before reading headers.
cpp/​src/​reader/​tsfile_reader.h Exposes named-expression table-query parameters.
cpp/​src/​reader/​tsfile_reader.cc Binds expressions during query preparation.
cpp/​src/​reader/​tsfile_executor.cc Transfers ownership of prepared TIME filters.
cpp/​src/​reader/​task/​device_task_iterator.h Owns the bound TAG filter.
cpp/​src/​reader/​table_query_executor.h Defines the expression-based executor interface.
cpp/​src/​reader/​table_query_executor.cc Binds and transfers query filters.
cpp/​src/​reader/​meta_data_querier.h Uses typed TAG-filter parameters.
cpp/​src/​reader/​meta_data_querier.cc Updates device-iterator construction.
cpp/​src/​reader/​imeta_data_querier.h Updates the TAG-filter interface contract.
cpp/​src/​reader/​filter/​tag_filter.h Replaces positional filters with bound filters.
cpp/​src/​reader/​filter/​tag_filter.cc Implements named TAG binding and matching.
cpp/​src/​reader/​filter/​table_field_filter.h Removes the row-callback API.
cpp/​src/​reader/​filter/​table_field_filter.cc Removes legacy callback evaluation.
cpp/​src/​reader/​filter/​filter.h Removes the TAG-row virtual callback.
cpp/​src/​reader/​filter/​field_filter.h Defines the shared FIELD-filter interface.
cpp/​src/​reader/​filter/​field_filter.cc Implements typed evaluation and statistics classification.
cpp/​src/​reader/​filter/​bind_expression.h Adds shared expression-tree binding.
cpp/​src/​reader/​filter/​bind_expression.cc Resolves FIELD names and literal types.
cpp/​src/​reader/​filter/​aligned_field_filter.h Removes the aligned-only filter API.
cpp/​src/​reader/​expression.h Adds named operands and expression factories.
cpp/​src/​reader/​expression.cc Implements factories and referenced-column collection.
cpp/​src/​reader/​device_meta_iterator.h Uses schema-derived exact-device lookup.
cpp/​src/​reader/​device_meta_iterator.cc Matches bound TAG filters during iteration.
cpp/​src/​reader/​column_mapping.h Registers bound filter-referenced columns.
cpp/​src/​reader/​block/​single_device_tsblock_reader.h Borrows the shared FIELD filter.
cpp/​src/​reader/​block/​single_device_tsblock_reader.cc Unifies aligned and merged-row filtering.
cpp/​src/​reader/​block/​prepared_series_tsblock_reader.h Owns TIME filters with smart pointers.
cpp/​src/​reader/​block/​prepared_series_tsblock_reader.cc Updates TIME-filter transfer and cleanup.
cpp/​src/​reader/​block/​device_ordered_tsblock_reader.h Owns query TIME and FIELD filters.
cpp/​src/​reader/​block/​device_ordered_tsblock_reader.cc Lends filters to per-device readers.
cpp/​src/​reader/​aligned_chunk_reader.h Tracks pages requiring FIELD evaluation.
cpp/​src/​reader/​aligned_chunk_reader.cc Reuses statistics-proven FIELD matches.
cpp/​src/​file/​tsfile_io_reader.h Accepts borrowed shared FIELD filters.
cpp/​src/​file/​tsfile_io_reader.cc Updates multi-series filter parameters.
cpp/​src/​cwrapper/​tsfile_cwrapper.cc Implements existing handles with expressions.
cpp/​src/​common/​db_common.h Adds string-type classification.
cpp/​examples/​cpp_examples/​demo_read.cpp Demonstrates expressions and result cleanup.

Review effort: Max

const Expression* field_filter, int batch_size) {
result_set = nullptr;
if (!tsfile_executor_ || offset < 0) return E_INVALID_ARG;
ensure_table_query_executor(batch_size);
Comment on lines +121 to +122
const Expression* tag_filter,
const Expression* field_filter = nullptr, int batch_size = 0);
Comment on lines +61 to +63
if (schema.get_column_schema(operand.reference).data_type_ !=
common::STRING)
return common::E_NOT_SUPPORT;
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.

3 participants