Skip to content

[C++] Share expressions across table and tree queries - #1178

Open
ColinLeeo wants to merge 9 commits into
apache:developfrom
ColinLeeo:refactor/cpp-shared-table-predicate
Open

ColinLeeo wants to merge 9 commits into
apache:developfrom
ColinLeeo:refactor/cpp-shared-table-predicate

Conversation

@ColinLeeo

@ColinLeeo ColinLeeo commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

C++ callers can now define a condition before they know the table schema or the tree series layout. Both query models accept the same storage::Expression. This PR contains the native reader work split out of #1169.

Query behavior

  • Build comparisons, inclusive ranges, null tests and logical combinations from named operands and typed literals. Each query owns a copy of the expression with its leaf operands bound to the query schema. TAG matching, value evaluation and page pruning use the same expression structure. Callers can reuse the expression across queries or release it immediately after preparation.
  • Table queries take tag_filter and field_filter as separate expression pointers after the result parameter. Either can be null. Time bounds restrict the scan, and offset and limit count matching rows. TAG references bind to device-ID segments and retain exact-device lookup and regular-expression support. FIELD references bind to column types and use the existing page pruning and batch evaluation paths.
  • Remove the C++ TagFilterBuilder and the predicate factories on AlignedFieldFilter. C++ callers construct TAG and FIELD conditions with Expression::compare, Expression::between, null tests and logical operators. For standalone device-segment evaluation, bind the expression with TagFilter::bind. The CLI and the C wrapper construct named expressions directly. The C signatures are unchanged. For AND, OR and NOT, success transfers operand ownership to the parent. A null operand or aliased binary operands return a null handle and leave ownership with the caller. Allocation failure during composition terminates the calling process.
  • Tree queries resolve full paths and unambiguous short names. They read predicate-only series alongside the projection, evaluate at each merged timestamp and expose only the requested columns.
  • Preserve the existing behavior for NOT(a = x) on missing data. A missing TAG matches. A null FIELD or tree value is excluded. Existing indexed TAG subclasses and path/time query APIs remain available.

Verification

  • macOS arm64 with LZMA2 enabled. All 1,988 enabled C++ Release tests and 1,989 enabled RelWithDebInfo ASan/UBSan tests passed.
  • New regression cases exercise one expression in both models, schema rebinding, wrong column categories, sparse paths, hidden series, ambiguous names, inclusive and negated ranges with NULLs, NaNs and reversed bounds, and pagination across all four combinations of optional filters.
  • The Python suite passed with 706 tests passing and 16 skipped on macOS. Go tests, vet and race checks passed. Spotless and the Git whitespace check passed.
  • Linux arm64 verified ASan instrumentation in all five Cython extensions and libtsfile. All 15 Python ASan/LSan ownership scenarios passed.
  • Forced the parent allocation to throw in separate processes for C TAG AND, OR and NOT and verified that each invoked the terminate handler.

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.

🟢 Approval recommended

No active review issues are recorded for the shared TAG/FIELD predicate-tree refactor.

No open issues 🎉

What changed in this PR

Refactors C++ TAG and FIELD filters to share a predicate tree, separating the native changes from the Python binding work in #1169.

Changes:

  • Shares comparison and logical operators while preserving distinct TAG and FIELD null semantics.
  • Represents negation explicitly and retains TAG equality direct lookup.
  • Adds regression tests and documents predicate behavior.
File Description
skills/​tsfile/​references/​properties-filters.md Documents shared predicates and null semantics.
cpp/​test/​reader/​filter/​tag_filter_test.cc Tests tree shapes, null handling, and rejected-operand ownership.
cpp/​test/​reader/​filter/​aligned_field_filter_test.cc Tests nested negation after binding.
cpp/​src/​reader/​filter/​tag_filter.h Derives TAG filters from the shared tree.
cpp/​src/​reader/​filter/​tag_filter.cc Centralizes TAG evaluation and validates combinator operands.
cpp/​src/​reader/​filter/​table_predicate.h Introduces shared operators and tree ownership.
cpp/​src/​reader/​filter/​aligned_field_filter.h Adopts the shared tree for FIELD filters.
cpp/​src/​reader/​filter/​aligned_field_filter.cc Unifies evaluation traversal and handles explicit negation.
cpp/​src/​reader/​device_meta_iterator.cc Recognizes shared-tree TAG equality for direct lookup.

Review effort: Balanced

@ColinLeeo ColinLeeo changed the title [C++] Share predicate operators between TAG and FIELD filters [C++] Share expressions across table and tree queries Dec 2, 2026

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 new bind_expression.h file omits quotation marks from the standard ASF license header, which should be restored to preserve the complete notice.

1 open issue

Review effort: Balanced

Comment thread cpp/src/reader/filter/bind_expression.h Outdated
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* License); you may not use this file except in compliance
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