Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change new count model squashing to discard zero counts #5702

Merged
merged 4 commits into from
Nov 27, 2024

Conversation

rowanseymour
Copy link
Member

@rowanseymour rowanseymour commented Nov 27, 2024

We're about to move node counts to the new count model and they have a special property - they all end up zero, and zero is already representable in the count model as non-existence. So let's not even store zeros.

@rowanseymour rowanseymour changed the title Change flow activity squashing to not insert zero sums Change new count model squashing to not insert zero sums Nov 27, 2024
@rowanseymour rowanseymour changed the title Change new count model squashing to not insert zero sums Change new count model squashing to discard zero counts Nov 27, 2024
VALUES (%%s, %%s, GREATEST(0, (SELECT SUM("count") FROM removed)), TRUE);
SELECT * FROM (
SELECT %%s, %%s, GREATEST(0, (SELECT SUM("count") FROM removed)) AS "count", TRUE
) s WHERE s."count" != 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

using != 0 so negative totals would still be possible to support

Choose a reason for hiding this comment

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

we still ignore negative values and consider them 0

Copy link
Member Author

Choose a reason for hiding this comment

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

where?

Choose a reason for hiding this comment

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

GREATEST(0, (SELECT SUM("count") FROM removed))

Copy link
Member Author

Choose a reason for hiding this comment

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

ahh good spot.. I'm gonna remove that. If numbers are adding to something negative we've got a problem and we shouldn't just plaster over that.

Copy link
Member Author

Choose a reason for hiding this comment

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

tho I notice that GREATEST(0, NULL) == 0 so I need to check we're not leaning on that to prevent writing NULLs....

Choose a reason for hiding this comment

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

Then we can change that to COALESCE((SELECT SUM("count") FROM removed), 0) if we need to support negative values

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I added COALESCE tho the way the query is it's not technically needed because WHERE s."count" != 0 isn't true if count is NULL. But I think the query is easier to understand if you know count is a number.

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (950a7df) to head (6cefe52).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5702   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          572       572           
  Lines        25925     25923    -2     
=========================================
- Hits         25925     25923    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rowanseymour rowanseymour merged commit 62eb825 into main Nov 27, 2024
5 checks passed
@rowanseymour rowanseymour deleted the squash_no_zeros branch November 27, 2024 15:52
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants