Add SLIDE parameter support to CAPACITY table-valued function#17456
Open
JackieTien97 wants to merge 2 commits intomasterfrom
Open
Add SLIDE parameter support to CAPACITY table-valued function#17456JackieTien97 wants to merge 2 commits intomasterfrom
JackieTien97 wants to merge 2 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #17456 +/- ##
============================================
+ Coverage 39.80% 39.83% +0.02%
Complexity 312 312
============================================
Files 5135 5135
Lines 347075 347085 +10
Branches 44224 44221 -3
============================================
+ Hits 138169 138274 +105
+ Misses 208906 208811 -95 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
463d524 to
7073de7
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
The CAPACITY table-valued function currently only supports the
SIZEparameter to specify the window length (number of rows per window). This PR adds an optionalSLIDEparameter to specify the sliding step, enabling overlapping and gap windows based on row count.Motivation
In time-series analysis, sliding windows are a common pattern. While the
HOPfunction already supports sliding windows based on time, there was no equivalent for row-count-based windows. AddingSLIDEtoCAPACITYfills this gap, enabling users to create:SLIDE < SIZE): A single row can belong to multiple windows, useful for moving averages, rolling aggregations, etc.SLIDE = SIZE): Equivalent to the current behavior (backward compatible).SLIDE > SIZE): Windows with gaps between them, where some rows are discarded.Changes
Core Implementation
CapacityTableFunction.java(iotdb-core/node-commons):New SLIDE parameter: Added as an optional
INT64scalar parameter withPOSITIVE_LONG_CHECKERvalidation. Defaults toSIZEwhen not specified (preserving full backward compatibility).Updated analyze(): Reads and validates the SLIDE value, stores both
SIZEandSLIDEin theMapTableFunctionHandle.Rewritten CapacityDataProcessor: Changed from a deferred batch-output model to per-row window assignment. For each row at index
curIndex, the processor computes all windowsksatisfyingk * slide <= curIndex < k * slide + size(wherek >= 0), and emits a(window_index, passThroughIndex)pair for each matching window.Added POSITIVE_LONG_CHECKER to SIZE: The original SIZE parameter used manual validation in
analyze(). Now usesPOSITIVE_LONG_CHECKERfor consistency with other TVFs (HOP, TUMBLE, etc.).Algorithm
For each row at position
curIndex(0-based within its partition):SQL Syntax
Integration Tests
IoTDBWindowTVFIT.java— Added 7 test scenarios totestCapacityFunction():SIZE=>2, SLIDE=>2SIZE=>2, SLIDE=>1SIZE=>3, SLIDE=>2SIZE=>2, SLIDE=>3SIZE=>2, SLIDE=>1+ aggregationavg(price)computed correctly across overlapping windowsSLIDE=>-1Invalid scalar argument SLIDE, should be a positive valueSLIDE=>0Invalid scalar argument SLIDE, should be a positive valueAll tests pass (verified locally with
TableSimpleITprofile).