Skip to content

Backport aggregation related enhance#1073

Merged
yokofly merged 22 commits intodevelopfrom
backport-aggregation-related-enhance
Dec 18, 2025
Merged

Backport aggregation related enhance#1073
yokofly merged 22 commits intodevelopfrom
backport-aggregation-related-enhance

Conversation

@yokofly
Copy link
Copy Markdown
Collaborator

@yokofly yokofly commented Dec 18, 2025

gemini:

This appears to be a substantial feature addition and refactoring aimed at supporting Session Windows based on custom start/end events (via EMIT AFTER SESSION CLOSE) and introducing TTL (Time-To-Live) support for Hybrid Hash Tables (spill-to-disk storage) using RocksDB compaction filters.

Here is a summary and review of the changes:

1. RocksDB Integration Refactoring

The existing RocksHandler and Rocks classes are being replaced/renamed to RocksDBColumnFamilyHandler and RocksDB.

  • Purpose: To support per-Column-Family TTLs dynamically.
  • Mechanism:
    • RocksDB class now manages rocksdb::DB and handles the lifecycle of column families.
    • It persists TTL metadata (__tp_meta_ttl__.<cf_name>) into the default column family so that when the DB is reopened, the correct TTLs are applied to specific column families.
    • A custom RocksDBTTLCompactionFilter is implemented to filter out expired keys during RocksDB compaction based on a timestamp suffix appended to the value.
  • Impact: This allows HybridHashTable (used in Joins and Aggregations) to automatically clean up old state on disk without explicit cleanup scans, which is crucial for long-running streaming queries.

2. Hybrid Hash Table Updates

  • Configuration: HybridHashTableConfig now includes ttl and kv_options.
  • Logic:
    • The value serialization logic in HybridHashTable (and HybridKeyList) now optionally appends a timestamp if TTL is enabled.
    • HybridKeyList (used for tracking timeouts) was refactored to support removing specific keys (removeKey) and handling timeouts more efficiently (removeTimedOutKeys), including refilling from disk when the in-memory buffer is exhausted.

3. EMIT AFTER SESSION CLOSE

This is the core functional addition.

  • Syntax: EMIT AFTER SESSION CLOSE IDENTIFIED BY (ts_col, start_cond, end_cond) WITH MAXSPAN ....
  • Logic (HybridAggregator):
    • A new execution path executeAndFinalizeAfterSessionClose is added.
    • It maintains a state machine per key:
      • New Session: If a key is not found and start_cond is true (or implied), a new session is created.
      • Merge: If merge_open_sessions is enabled, new start events merge into existing sessions. Otherwise, the old session is closed (emitted) and a new one starts.
      • End Session: If end_cond is true, the session is finalized and emitted. The include_session_end setting controls if the ending row is included in the aggregate.
      • Timeout/MaxSpan: The HybridKeyList tracks the creation timestamp of sessions. If a session exceeds MAXSPAN (checked per row) or TIMEOUT (checked via removeTimedOutKeys), it is forcibly closed/emitted.

4. Integration

  • The AggregatingStep and AggregatingTransform are updated to initialize the RocksDB/Hybrid configuration with the new TTL settings passed from query settings (aggregate_state_ttl_sec).
  • ParserEmitQuery is updated to parse the new syntax, supporting various overloads of IDENTIFIED BY (e.g., tuple for start/end columns).

Code Quality & Correctness Checks

  • TTL Implementation: Storing TTL metadata in the default CF is a robust way to ensure persistence across restarts. The compaction filter logic looks standard for RocksDB.
  • Session Logic: The implementation in HybridAggregator_ExecuteAndFinalize.cpp covers edge cases like "End event without start" (orphan events) and "Start event while open".
  • Memory Management: The usage of std::shared_ptr for RocksDB instances and handlers seems correct to manage lifecycles.
  • Tests: The SQL test 99109_emit_after_session_close.sql covers many permutations (only maxspan, start/end columns, merging). Unit tests for the new RocksDB wrapper are included.

@yokofly yokofly merged commit 0730ca3 into develop Dec 18, 2025
7 of 11 checks passed
@yokofly yokofly deleted the backport-aggregation-related-enhance branch December 18, 2025 08:10
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.

4 participants