Skip to content

feat(sql): volume-weighted exponential moving average (VWEMA) window function#6651

Merged
bluestreak01 merged 3 commits intomasterfrom
vi_vwema
Jan 15, 2026
Merged

feat(sql): volume-weighted exponential moving average (VWEMA) window function#6651
bluestreak01 merged 3 commits intomasterfrom
vi_vwema

Conversation

@bluestreak01
Copy link
Copy Markdown
Member

Summary

  • Adds Volume-Weighted Exponential Moving Average (VWEMA) as a new window function
  • New avg(price, kind, param, volume) signature for computing VWEMA
  • Supports three smoothing modes:
    • 'alpha': Direct smoothing factor (0 < α ≤ 1)
    • 'period': EMA-style period (α = 2/(period+1))
    • Time units ('second', 'minute', 'hour', 'day'): Time-weighted decay with tau parameter

VWEMA Formula

numerator   = α × price × volume + (1-α) × prev_numerator
denominator = α × volume + (1-α) × prev_denominator
VWEMA       = numerator / denominator

For time-weighted mode: α = 1 - exp(-Δt / τ)

Test plan

  • Comprehensive unit tests covering all modes and edge cases
  • Explain plan tests for all function variants
  • Tests for invalid inputs (NaN price, NaN volume, zero volume, same timestamps)
  • Partitioned and non-partitioned queries

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 15, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This PR introduces a VWEMA (Volume-Weighted Exponential Moving Average) window function implementation with alpha-based, period-based, and time-weighted modes. Supporting changes include keyword detection utilities, window context API extension with timestamp type tracking, and comprehensive test coverage.

Changes

Cohort / File(s) Summary
VWEMA Window Function Implementation
core/src/main/java/io/questdb/griffin/engine/functions/window/VwemaDoubleWindowFunctionFactory.java, core/src/main/resources/function_list.txt
Adds new VWEMA factory (~742 lines) supporting three modes: alpha (direct smoothing), period (N+1 formula), and time-weighted (tau-based). Includes partitioned/unpartitioned variants with separate function implementations. Validates window context, parses arguments, handles NaN/invalid inputs, and manages internal state via column types. Registers factory in function list.
Window Context API Extension
core/src/main/java/io/questdb/griffin/engine/window/WindowContext.java, core/src/main/java/io/questdb/griffin/engine/window/WindowContextImpl.java
Adds getTimestampType() method to both interface and implementation to expose timestamp type information required by time-weighted VWEMA calculations.
SQL Keywords
core/src/main/java/io/questdb/griffin/SqlKeywords.java
Adds two case-insensitive keyword detectors: isAlphaKeyword() and isWeeksKeyword() following existing pattern of length checks and per-character bitwise comparisons.
VWEMA Test Suite
core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java
Comprehensive test class (~1103 lines) covering alpha, period, and time-weighted modes across unpartitioned and partitioned windows; includes NaN/zero volume handling, multiple time units (seconds, days, hours, microseconds, milliseconds, minutes, weeks), explain-plan validation, and error condition assertions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

New feature, SQL

Suggested reviewers

  • puzpuzpuz
  • kafka1991
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.74% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new VWEMA (volume-weighted exponential moving average) window function to the SQL engine.
Description check ✅ Passed The description is detailed and directly related to the changeset, covering the new VWEMA window function, supported modes, formula, and test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bluestreak01
Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 15, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 295 / 301 (98.01%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/functions/window/VwemaDoubleWindowFunctionFactory.java 280 286 97.90%
🔵 io/questdb/griffin/SqlKeywords.java 12 12 100.00%
🔵 io/questdb/griffin/engine/window/WindowContextImpl.java 3 3 100.00%

@bluestreak01 bluestreak01 merged commit a04b64e into master Jan 15, 2026
43 checks passed
@bluestreak01 bluestreak01 deleted the vi_vwema branch January 15, 2026 22:45
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