Skip to content

fix(sql): fix EMA, VWEMA and KSUM failures in combined window queries#7030

Merged
bluestreak01 merged 9 commits into
masterfrom
jh_window_fixed_simpler
May 5, 2026
Merged

fix(sql): fix EMA, VWEMA and KSUM failures in combined window queries#7030
bluestreak01 merged 9 commits into
masterfrom
jh_window_fixed_simpler

Conversation

@jerrinot
Copy link
Copy Markdown
Contributor

@jerrinot jerrinot commented Apr 27, 2026

Fixes #7006

Fixes valid window queries using EMA, VWEMA, or KSUM that could fail when the planner chose cached window execution.

These functions already worked in streaming execution, but some query shapes require cached execution, for example when an incremental window function is used together with another window expression. In those cases, users could hit an execution failure even though the SQL was valid.

Implement pass1 materialization for EMA, VWEMA, and KSUM zero-pass
variants, and clarify the WindowFunction pass-count contract.

Add cached-window regression coverage for reordered EMA, VWEMA, and KSUM.

Fixes #7006
@jerrinot jerrinot added the Bug Incorrect or unexpected behavior label Apr 27, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5beb506d-fba6-40b7-bc0c-47e400d9585f

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.16% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses issue #7006 by implementing pass1 materialization for zero-pass window functions (EMA, VWEMA, KSUM), enabling cached execution for period-mode avg queries that previously caused server unreachability.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing cached execution for zero-pass window functions: implementation changes in three factory classes, interface documentation updates, and regression test coverage for the affected functions.
Description check ✅ Passed The PR description directly addresses the changeset by explaining the fix for window functions (EMA, VWEMA, KSUM) that failed under cached execution, which aligns with all modified files and test additions.
Title check ✅ Passed The PR title accurately describes the main changes: fixing EMA, VWEMA, and KSUM failures in combined window queries, which aligns with the changeset that implements pass1 materialization for these zero-pass window functions.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jh_window_fixed_simpler

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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (4)
core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java (2)

547-548: Method is out of alphabetical order.

Per the project convention, testEmaPeriodCachedWindowPartitionedReorderedReplay should be placed before testEmaPeriodMode (line 472), not after testEmaPeriodOne (line 523).

As per coding guidelines: "Group Java class members by kind (static vs. instance) and visibility, and sort them alphabetically. When adding new methods or fields, insert them in the correct alphabetical position among existing members of the same kind."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java`
around lines 547 - 548, Move the test method
testEmaPeriodCachedWindowPartitionedReorderedReplay so it appears alphabetically
among the other instance test methods: place it before testEmaPeriodMode and not
after testEmaPeriodOne; adjust its position within the class so all instance
test methods remain grouped and sorted alphabetically per the project's member
ordering convention.

551-556: Consolidate into a single multi-row INSERT.

As per coding guidelines: "Use a single INSERT statement to insert multiple rows in tests."

♻️ Proposed change
-            execute("insert into tab values (1::timestamp, 2, 0, 10.0)");
-            execute("insert into tab values (2::timestamp, 2, 1, 100.0)");
-            execute("insert into tab values (3::timestamp, 1, 0, 20.0)");
-            execute("insert into tab values (4::timestamp, 3, 1, 300.0)");
-            execute("insert into tab values (5::timestamp, 3, 0, 30.0)");
-            execute("insert into tab values (6::timestamp, 1, 1, 200.0)");
+            execute("""
+                    INSERT INTO tab VALUES
+                        (1::timestamp, 2, 0, 10.0),
+                        (2::timestamp, 2, 1, 100.0),
+                        (3::timestamp, 1, 0, 20.0),
+                        (4::timestamp, 3, 1, 300.0),
+                        (5::timestamp, 3, 0, 30.0),
+                        (6::timestamp, 1, 1, 200.0)
+                    """);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java`
around lines 551 - 556, Multiple separate execute("insert into tab values ...")
calls violate the guideline to use a single multi-row INSERT in tests; update
the test in EmaWindowFunctionTest by replacing the six individual execute(...)
insert statements that target table "tab" with one execute call that issues a
single INSERT INTO tab VALUES statement containing all six row tuples in the
same order (preserve timestamps and columns) so the test uses one multi-row
insert instead of multiple statements.
core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java (2)

558-559: Method is out of alphabetical order.

testVwemaPeriodCachedWindowPartitionedReorderedReplay should sit near testVwemaPeriodMode (line 450), not in the middle of the time-weighted block.

As per coding guidelines: "Group Java class members by kind (static vs. instance) and visibility, and sort them alphabetically. When adding new methods or fields, insert them in the correct alphabetical position among existing members of the same kind."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`
around lines 558 - 559, The test method
testVwemaPeriodCachedWindowPartitionedReorderedReplay is out of alphabetical
order in VwemaWindowFunctionTest; move the entire method declaration so it sits
near testVwemaPeriodMode (i.e., within the same grouping of test methods) to
maintain alphabetical ordering among instance test methods—ensure you cut the
method starting at "public void
testVwemaPeriodCachedWindowPartitionedReorderedReplay" and paste it in the
correct alphabetical position adjacent to testVwemaPeriodMode, preserving
imports, annotations (`@Test`) and existing formatting.

562-567: Consolidate into a single multi-row INSERT.

As per coding guidelines: "Use a single INSERT statement to insert multiple rows in tests."

♻️ Proposed change
-            execute("insert into tab values ('2024-01-01T00:00:00.000000Z'::timestamp, 2, 'A', 10.0, 3.0)");
-            execute("insert into tab values ('2024-01-01T00:00:01.000000Z'::timestamp, 2, 'B', 100.0, 1.0)");
-            execute("insert into tab values ('2024-01-01T00:00:02.000000Z'::timestamp, 1, 'A', 20.0, 1.0)");
-            execute("insert into tab values ('2024-01-01T00:00:03.000000Z'::timestamp, 3, 'B', 300.0, 4.0)");
-            execute("insert into tab values ('2024-01-01T00:00:04.000000Z'::timestamp, 3, 'A', 30.0, 1.0)");
-            execute("insert into tab values ('2024-01-01T00:00:05.000000Z'::timestamp, 1, 'B', 200.0, 2.0)");
+            execute("""
+                    INSERT INTO tab VALUES
+                        ('2024-01-01T00:00:00.000000Z'::timestamp, 2, 'A', 10.0, 3.0),
+                        ('2024-01-01T00:00:01.000000Z'::timestamp, 2, 'B', 100.0, 1.0),
+                        ('2024-01-01T00:00:02.000000Z'::timestamp, 1, 'A', 20.0, 1.0),
+                        ('2024-01-01T00:00:03.000000Z'::timestamp, 3, 'B', 300.0, 4.0),
+                        ('2024-01-01T00:00:04.000000Z'::timestamp, 3, 'A', 30.0, 1.0),
+                        ('2024-01-01T00:00:05.000000Z'::timestamp, 1, 'B', 200.0, 2.0)
+                    """);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`
around lines 562 - 567, Replace the six separate execute(...) insert calls in
the VwemaWindowFunctionTest with a single execute call that performs a multi-row
INSERT INTO tab VALUES (...),(...),(...),(...),(...),(...); keeping the exact
timestamp literals and ::timestamp casts and the same order of columns/values;
update the test method in VwemaWindowFunctionTest that contains the repeated
execute calls so it uses one execute("insert into tab values (...),(...),...");
instead of multiple execute(...) invocations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java`:
- Around line 547-574: The test only covers EmaOverPartitionFunction.pass1; add
three additional cached-window tests mirroring
testEmaPeriodCachedWindowPartitionedReorderedReplay to exercise the other pass1
variants: EmaTimeWeightedOverPartitionFunction.pass1,
EmaOverUnboundedRowsFrameFunction.pass1, and
EmaTimeWeightedOverUnboundedRowsFrameFunction.pass1. For each new test create
the same table shape and use queries that trigger the specific branch
(partitioned time-weighted: use OVER (partition by i order by sort_key) with
time-weighted EMA; non-partitioned fixed-alpha: use avg(val,'alpha',...) OVER
(order by sort_key); non-partitioned time-weighted: use time-weighted OVER
(order by sort_key)), follow the reordered-replay insert pattern from
testEmaPeriodCachedWindowPartitionedReorderedReplay, and assert using
assertQueryNoLeakCheck the expected output to ensure the
UnsupportedOperationException→computeNext+putDouble fix is exercised for those
factories.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`:
- Around line 558-585: Add three new tests mirroring
testVwemaPeriodCachedWindowPartitionedReorderedReplay to exercise the other
pass1 variants: create methods named e.g.
testVwemaTimeWeightedCachedWindowPartitionedReorderedReplay,
testVwemaPeriodCachedWindowUnboundedReorderedReplay, and
testVwemaTimeWeightedCachedWindowUnboundedReorderedReplay that use the same
table/data setup and assertQueryNoLeakCheck pattern; for
VwemaTimeWeightedOverPartitionFunction use avg(price, 'time', 3, volume) over
(partition by sym order by sort_key), for VwemaOverUnboundedRowsFrameFunction
use avg(price, 'period', 3, volume) over (order by sort_key) (no partition), and
for VwemaTimeWeightedOverUnboundedRowsFrameFunction use avg(price, 'time', 3,
volume) over (order by sort_key); keep the same ordering column ("ts") and the
same expected-result formatting as the existing test to ensure cached-window
(pass1) code paths are exercised.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java`:
- Around line 5117-5138: Add two tests mirroring testKSumRangeCachedWindow to
exercise the cached-window pass1 materialization for EMA and VWEMA: create
testEmaRangeCachedWindow and testVwemaRangeCachedWindow that use the same table
setup and rows, run queries "select ts, sym, val, ema(val) over (order by ts
range between 1 second preceding and current row) as ema_val, avg(val) over ()
as avg_all from tab" and similarly for vwema(val) (use the same window/frame and
expected output pattern), and assert results like the KSUM test; this will
exercise EmaDoubleWindowFunctionFactory and VwemaDoubleWindowFunctionFactory
pass1 paths analogous to testKSumRangeCachedWindow.
- Around line 5119-5137: In the assertMemoryLeak block in WindowFunctionTest
where you call executeWithRewriteTimestamp/create table and multiple
execute("insert into tab values ..."), replace the multiple single-row execute
inserts with one multi-row INSERT (single execute call containing all rows),
change numeric timestamp literals to underscore-separated forms (1_000_000,
2_000_000, 3_000_000, 4_000_000), and replace the final assertSql(...) call with
assertQueryNoLeakCheck(...) (keeping the same SQL and expected result string);
locate and update the code around executeWithRewriteTimestamp, the insert
execute calls, and the assertSql invocation in this test.
- Around line 4818-4835: Replace the use of assertSql(...) with
assertQueryNoLeakCheck(...) for the query assertion (change the call that
currently wraps the "select ts, sym, val, ksum(val) over..." verification),
collapse the four separate execute("insert ...") calls into a single multi-row
execute(...) INSERT statement (i.e. one INSERT with multiple value tuples) and
update numeric timestamp literals in the CREATE/INSERT SQL to use underscore
separators for numbers with 5+ digits (e.g. 1_000_000, 2_000_000, 3_000_000) so
the test uses assertQueryNoLeakCheck, a single multi-row INSERT via
execute(...), and underscore-separated numeric literals.

---

Nitpick comments:
In
`@core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java`:
- Around line 547-548: Move the test method
testEmaPeriodCachedWindowPartitionedReorderedReplay so it appears alphabetically
among the other instance test methods: place it before testEmaPeriodMode and not
after testEmaPeriodOne; adjust its position within the class so all instance
test methods remain grouped and sorted alphabetically per the project's member
ordering convention.
- Around line 551-556: Multiple separate execute("insert into tab values ...")
calls violate the guideline to use a single multi-row INSERT in tests; update
the test in EmaWindowFunctionTest by replacing the six individual execute(...)
insert statements that target table "tab" with one execute call that issues a
single INSERT INTO tab VALUES statement containing all six row tuples in the
same order (preserve timestamps and columns) so the test uses one multi-row
insert instead of multiple statements.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`:
- Around line 558-559: The test method
testVwemaPeriodCachedWindowPartitionedReorderedReplay is out of alphabetical
order in VwemaWindowFunctionTest; move the entire method declaration so it sits
near testVwemaPeriodMode (i.e., within the same grouping of test methods) to
maintain alphabetical ordering among instance test methods—ensure you cut the
method starting at "public void
testVwemaPeriodCachedWindowPartitionedReorderedReplay" and paste it in the
correct alphabetical position adjacent to testVwemaPeriodMode, preserving
imports, annotations (`@Test`) and existing formatting.
- Around line 562-567: Replace the six separate execute(...) insert calls in the
VwemaWindowFunctionTest with a single execute call that performs a multi-row
INSERT INTO tab VALUES (...),(...),(...),(...),(...),(...); keeping the exact
timestamp literals and ::timestamp casts and the same order of columns/values;
update the test method in VwemaWindowFunctionTest that contains the repeated
execute calls so it uses one execute("insert into tab values (...),(...),...");
instead of multiple execute(...) invocations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fb833b9e-42cf-467b-b2aa-e60b6d6bc8b0

📥 Commits

Reviewing files that changed from the base of the PR and between ef5d4ed and 75fe15b.

📒 Files selected for processing (7)
  • core/src/main/java/io/questdb/griffin/engine/functions/window/EmaDoubleWindowFunctionFactory.java
  • core/src/main/java/io/questdb/griffin/engine/functions/window/KSumDoubleWindowFunctionFactory.java
  • core/src/main/java/io/questdb/griffin/engine/functions/window/VwemaDoubleWindowFunctionFactory.java
  • core/src/main/java/io/questdb/griffin/engine/window/WindowFunction.java
  • core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java
  • core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java
  • core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java

Comment thread core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java Outdated
Comment thread core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java Outdated
Comment thread core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java Outdated
@jerrinot jerrinot added the SQL Issues or changes relating to SQL execution label Apr 27, 2026
@jerrinot jerrinot changed the title fix(sql): support cached execution for zero-pass window functions fix(sql): fix EMA, VWEMA and KSUM failures in combined window queries Apr 27, 2026
@jerrinot
Copy link
Copy Markdown
Contributor Author

a CI hiccup:

/usr/bin/bash /home/agent/_work/_temp/eff2643f-02bf-4692-b71a-01167307caa0.sh
+ echo 'OSS-triggered build detected. Updating questdb submodule to commit: c0c33863e7079c4b3c6265ba3e4430c28334a8fd'
+ cd questdb
+ git fetch origin
OSS-triggered build detected. Updating questdb submodule to commit: c0c33863e7079c4b3c6265ba3e4430c28334a8fd
+ git fetch origin c0c33863e7079c4b3c6265ba3e4430c28334a8fd
fatal: unable to access 'https://github.com/questdb/questdb.git/': Failed to connect to github.com port 443 after 134097 ms: Couldn't connect to server

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java (1)

468-468: Drop the banner section heading.

This file already relies on alphabetical method ordering, and these banner comments are explicitly disallowed in QuestDB Java sources.

As per coding guidelines, "Never insert // === or // --- banner comments as section headings in any Java file" and "Methods are sorted alphabetically and will not stay grouped by category."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`
at line 468, Remove the banner comment line "// ========================= Period
and Time-Weighted Mode Tests =========================" from
VwemaWindowFunctionTest (delete the standalone section-heading comment in the
class) so the file relies on the existing alphabetical method ordering; ensure
no other // === or // --- style banner comments remain in that test class.
core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java (1)

4692-4707: Use Java text blocks for long SQL statements.

Both tests build long INSERT/SELECT SQL via concatenation; converting to multiline strings will align with the test SQL conventions and improve readability.

♻️ Suggested refactor (apply similarly in both tests)
-            execute("insert into tab values " +
-                    "(1_000_000::timestamp, 'A', 10.0), " +
-                    "(2_000_000::timestamp, 'B', 100.0), " +
-                    "(2_000_000::timestamp, 'A', 30.0), " +
-                    "(3_000_000::timestamp, 'B', 200.0)");
+            execute("""
+                    insert into tab values
+                            (1_000_000::timestamp, 'A', 10.0),
+                            (2_000_000::timestamp, 'B', 100.0),
+                            (2_000_000::timestamp, 'A', 30.0),
+                            (3_000_000::timestamp, 'B', 200.0)
+                    """);

-                    "select ts, sym, val, ksum(val) over (partition by sym order by ts range between 1 second preceding and current row) as ksum_val, avg(val) over () as avg_all " +
-                            "from tab",
+                    """
+                    select ts, sym, val,
+                           ksum(val) over (partition by sym order by ts range between 1 second preceding and current row) as ksum_val,
+                           avg(val) over () as avg_all
+                    from tab
+                    """,

As per coding guidelines: "Use multiline strings for longer SQL statements (multiple INSERT rows, complex queries), as well as to assert multiline query results in tests."

Also applies to: 5037-5052

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java`
around lines 4692 - 4707, Replace the concatenated SQL strings in the test (the
call to execute(...) that inserts rows and the assertQueryNoLeakCheck(...)
select/expected strings using replaceTimestampSuffix) with Java text blocks
(multiline string literals) to improve readability; specifically convert the
long INSERT statement passed to execute and the expected-result and SELECT SQL
passed to assertQueryNoLeakCheck into """...""" text blocks, preserving the same
SQL content and spacing, and apply the same change to the other occurrence noted
(around lines 5037-5052) so both tests use multiline text blocks instead of
string concatenation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`:
- Around line 35-55: The test method testVwemaAlphaEqualsOne (and the other test
blocks around lines referenced for the same file) currently call
assertQuery(...) — replace those calls with assertQueryNoLeakCheck(...) and wrap
the test body in assertMemoryLeak(() -> { ... }) so the query assertions perform
the package's leak/factory-property checks; update all similar uses in this file
(including the block covering the comment's 143-186 range) to use
assertQueryNoLeakCheck and assertMemoryLeak in the same pattern as the
cached-window regression tests.

---

Nitpick comments:
In
`@core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java`:
- Line 468: Remove the banner comment line "// ========================= Period
and Time-Weighted Mode Tests =========================" from
VwemaWindowFunctionTest (delete the standalone section-heading comment in the
class) so the file relies on the existing alphabetical method ordering; ensure
no other // === or // --- style banner comments remain in that test class.

In
`@core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java`:
- Around line 4692-4707: Replace the concatenated SQL strings in the test (the
call to execute(...) that inserts rows and the assertQueryNoLeakCheck(...)
select/expected strings using replaceTimestampSuffix) with Java text blocks
(multiline string literals) to improve readability; specifically convert the
long INSERT statement passed to execute and the expected-result and SELECT SQL
passed to assertQueryNoLeakCheck into """...""" text blocks, preserving the same
SQL content and spacing, and apply the same change to the other occurrence noted
(around lines 5037-5052) so both tests use multiline text blocks instead of
string concatenation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1d921088-36d1-428f-aa2b-7b55ac53fc3c

📥 Commits

Reviewing files that changed from the base of the PR and between 75fe15b and ed02828.

📒 Files selected for processing (3)
  • core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java
  • core/src/test/java/io/questdb/test/griffin/engine/window/VwemaWindowFunctionTest.java
  • core/src/test/java/io/questdb/test/griffin/engine/window/WindowFunctionTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/src/test/java/io/questdb/test/griffin/engine/window/EmaWindowFunctionTest.java

bluestreak01
bluestreak01 previously approved these changes Apr 28, 2026
Copy link
Copy Markdown
Member

@bluestreak01 bluestreak01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the fix and the cached-window contract change. Empirically confirmed the new tests catch the regression by reverting one pass1() to throw — test fails as expected. Nice fix.

@mtopolnik
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 20 / 20 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/engine/functions/window/VwemaDoubleWindowFunctionFactory.java 8 8 100.00%
🔵 io/questdb/griffin/engine/functions/window/EmaDoubleWindowFunctionFactory.java 8 8 100.00%
🔵 io/questdb/griffin/engine/functions/window/KSumDoubleWindowFunctionFactory.java 4 4 100.00%

Copy link
Copy Markdown
Member

@bluestreak01 bluestreak01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Small, focused, correct fix for #7006 — the new pass1() implementations match the established pattern used by Avg/Max/StdDev/RowNumber/Rank ZERO_PASS factories. Verified all 10 modified variants are reachable via the cached executor when combined with a non-ZERO_PASS function, and hand-checked the new test expectations.

Three minor (non-blocking) nits:

  1. VwemaOverUnboundedRowsFrameFunction.pass1() and VwemaTimeWeightedOverUnboundedRowsFrameFunction.pass1() use getDouble(record) (which recomputes numerator/denominator) instead of a cached field. Inconsistent with the partitioned variants that store vwema. Functionally correct, just an extra divide per row.
  2. New VWEMA cached-path tests run only in micros mode because VwemaWindowFunctionTest is not parametrized over TestTimestampType. Pre-existing pattern in the file, but the gap is now wider versus EMA/KSUM cached tests.
  3. Pre-existing empty reopen() override in KSumOverPartitionRowsFrameFunction (lines ~822-824) — drop in a future cleanup.

@bluestreak01 bluestreak01 merged commit c3d7038 into master May 5, 2026
51 checks passed
@bluestreak01 bluestreak01 deleted the jh_window_fixed_simpler branch May 5, 2026 21:37
nwoolmer added a commit that referenced this pull request May 6, 2026
Brings in 4 upstream commits (c0c5638..8735521):

* feat(core): add local parquet metadata sidecar file for optimized query
  planning (#6913). Introduces the `_pm` sidecar produced by
  `ParquetMetadataWriter`, the qdb-parquet-meta Rust crate, the
  pm_generate / pm_inspect binaries, Mig940 to backfill existing
  partitions, and a refactor of attachPartition / O3 parquet paths to
  derive parquet state from the sidecar.
* fix(sql): EMA, VWEMA and KSUM failures in combined window queries
  (#7030).
* chore(core): another posting index fix avoiding corrupt results (#7062).
* docs(core): bump Java requirement to 25 in core/README (#7036).

Conflict 1: core/src/main/resources/io/questdb/bin/linux-x86-64/libquestdbr.so
is a prebuilt native library; took master's version (same resolution as
prior 046c874 / 4302e10 merges). Other native libs updated
cleanly.

Conflict 2: MemoryTag.java tag-name registration. Took both - the
errand-side NATIVE_MEMFD_STORAGE entry and the new master-side
MMAP_PARQUET_METADATA_READER entry are independent.

Semantic merge: TableWriter.attachPartition. Master refactored the
method to detect parquet partitions from the post-rename `_pm` file
(`parquetFileSize > -1`) and dropped the local `boolean isParquet`.
Auto-merge silently kept errand's three `isParquet` references (skip
attachValidateMetadata, upsert column tops instead of iterateDir, skip
configureAppendPosition) without their declaration. Restored
`boolean isParquet` and the early `PARQUET_PARTITION_NAME` probe so
errand's parquet-attach optimisations stay intact alongside master's
new sidecar generation block. Path is reset via trimTo after the
detection probe.

Also relocated the parquet-testing nested submodule from
core/rust/qdbr/parquet2/testing/parquet-testing to
core/rust/parquet2/testing/parquet-testing per the upstream rename;
removed the now-empty leftover directory under core/rust/qdbr/parquet2.

Build: mvn package -DskipTests -pl core -am succeeds. Tests not run
in this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

QuestDB Unreachable with some avg('period') queries

3 participants