Skip to content

test(cpp): cover QDSWithTimeGenerator expression queries - #1117

Open
ColinLeeo wants to merge 2 commits into
apache:developfrom
ColinLeeo:colin/cpp-qds-expression-tests
Open

ColinLeeo wants to merge 2 commits into
apache:developfrom
ColinLeeo:colin/cpp-qds-expression-tests

Conversation

@ColinLeeo

Copy link
Copy Markdown
Contributor

Summary

Add coverage for the tree-view expression query path (QDSWithTimeGenerator), which previously had 0% line coverage because no test built a non-global-time QueryExpression.

New tests (cpp/test/reader/qds_with_timegenerator_test.cc, 13 cases):

  • single-series time filter, result metadata, is_null by name/index
  • AND intersection / OR union, including NULL padding for series missing a timestamp
  • every AND/OR cursor direction (left-first, right-first, equal, one side exhausted, both exhausted)
  • multi-block scans across TsBlock boundaries
  • ValueAt exhaustion (INT64_MAX short-circuit) and first-lookup-past-range
  • statistics-pruned filter, row-filtered series, missing series

The new tests exposed three defects in the untested path, fixed here:

  • QDSWithTimeGenerator::init() dereferenced an uninitialized value_col_iter_ to build the result-set metadata, crashing every expression query; use ssi_->get_data_type() instead.
  • QueryExpression::optimize() allocated a second AND/OR node wrapping the same children and returned it, so it was owned by both expression_ and my_exprs_ and freed twice on close; reuse the node being optimized.
  • SeriesScanStream / ValueAt reused a TsBlock without resetting it, so once the block filled the scan made no progress and looped forever; delete the iterators and reset() the block before the next get_next().

Coverage of qds_with_timegenerator.cc: 0% -> 98.6% lines, 100% functions.

Test plan

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

Exercise the tree-view query path for series expressions, AND/OR
combinations, empty results and multi-block scans, which previously had
no test coverage.

Fixes surfaced by the new tests:
- init() dereferenced an uninitialized value_col_iter_ to build
  result-set metadata, crashing every expression query
- optimize() allocated a second AND/OR node wrapping the same children
  and returned it, double-freeing on close
- SeriesScanStream and ValueAt reused a TsBlock without resetting it,
  looping forever once the block filled up
@ColinLeeo
ColinLeeo requested a balanced review from Copilot November 16, 2026 06:24

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

3 open issues
What changed in this PR

Adds comprehensive C++ test coverage for the QDSWithTimeGenerator non-global-time expression query execution path, and fixes multiple defects uncovered by the new tests.

Changes:

  • Added qds_with_timegenerator_test.cc with 13 cases covering AND/OR cursor behavior, NULL padding, multi-block scanning, pruning, and missing series failures.
  • Fixed SeriesScanStream/ValueAt iteration to avoid infinite loops by resetting TsBlock state between get_next() calls.
  • Fixed expression-query metadata/type handling and QueryExpression::optimize() ownership to prevent crashes and double-free.
File Description
cpp/​test/​reader/​qds_with_timegenerator_test.cc Adds targeted tests to cover previously untested expression-query paths (including multi-block and edge cases).
cpp/​src/​reader/​qds_with_timegenerator.cc Fixes iterator/TsBlock lifecycle and metadata type derivation used by expression queries.
cpp/​src/​reader/​expression.cc Reworks optimization to reuse nodes and avoid double-ownership/double-free.

Review effort: Lite

RowSnapshot has default member initializers, so GCC and MSVC in C++11
mode reject the brace-enclosed aggregate initialization used when
appending a row; every non-clang CI job failed to compile the new test.
Construct the snapshot explicitly instead.

Also address review feedback:
- keep ValueAt::at()'s allocate-when-null contract and only reset an
  already materialized TsBlock
- drop the is_null() assertions made after the result set was exhausted
- restore tsblock_max_memory_ only when the test actually changed it
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