Repository navigation
fix: pass the second state to Pivot's Difference - #187
Open
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Open
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Peter Shrosbree (pcshrosbree) wants to merge 1 commit into
Conversation
Pivot combines one aggregate per output field into a single aggregate whose state is an array. Its Difference passed the first state array as both arguments, so each field computed Difference(state1, state1) instead of Difference(state1, state2). The engine calls Difference when an interval event ends while another event of its group is still alive. For Sum and Average, Difference(state1, state1) is an empty state, so the group's result then left out the events still alive. With a:1 over [1,6) and a:3 over [3,8), Pivot reported 0 with Sum and NaN with Average from time 6 to time 8; the right result is 3. An event that ends through an end edge goes through Deaccumulate instead, so it was not affected. PivotDifferenceTests runs in row and columnar mode. Its three tests fail before this change and pass after it.
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.
Fixes #184.
Pivotbuilds one combined aggregate whosedifferencecalls each attribute'sDifference(). It passedstate1for both arguments, so each attribute computedDifference(state1, state1)(PivotExtensions.csline 84). The snapshot window callsdifferencewhen an interval event ends while another event of its group is still alive. After that, the group's result left out the events still alive: 0 withSumandNaNwithAveragein the example in #184. This change passesstate2as the second argument.The new test file
PivotDifferenceTests.csruns three tests in two configurations: one forces row mode, and the other requests columnar mode with fallback disabled. In both, the aggregate itself runs in row mode, because it returns an array and Trill cannot hold an array result in columns (SnapshotWindowStreamable.csline 378). That check comes before code generation, so the columnar configuration does not throw. The tests:Sumovera:1[1,6) anda:3[3,8) gives 3 from time 6;Averageover the same events gives 3 from time 6;a:5[6,8) added,Sumgives 8 from time 6.On this branch's base, with only the test file added, all 6 runs fail on the output at time 6. With the fix, all 6 pass. I ran them on
netcoreapp3.1, rolled forward to .NET 10.0.13 on Linux x64, because only .NET 10 runtimes are installed here.Note
Prepared with AI assistance (Anthropic Claude, OpenAI Codex). I reviewed it before posting.