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

Use TwoFloats when using stats_agg in moving-aggregate #599

Merged
merged 4 commits into from
Nov 7, 2022

Conversation

syvb
Copy link
Member

@syvb syvb commented Nov 2, 2022

Makes stats_agg use TwoFloats internally for keeping track of the state when in moving-aggregate mode to prevent floating-point error from accumulating. See #595 for some more details.


// expanded from FlatSerializable derive macro and made to work right with generic arg
#[allow(unused_imports)]
unsafe impl<'a> flat_serialize::FlatSerializable<'a> for StatsSummary2D<f64> {
Copy link
Member Author

Choose a reason for hiding this comment

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

#[derive(FlatSerializable)] doesn't seem to be able to handle types with generics, so I manually expanded it and fixed the output.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be cleaner to use the TypeHack workaround you use below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Rust doesn't support applying derive macros on type aliases so that wouldn't work here. The ideal solution would be to fix the derive macro.

@syvb syvb force-pushed the sv/stats_agg-twofloat branch from 046f2cb to dce3089 Compare November 2, 2022 15:25

// expanded from FlatSerializable derive macro and made to work right with generic arg
#[allow(unused_imports)]
unsafe impl<'a> flat_serialize::FlatSerializable<'a> for StatsSummary2D<f64> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be cleaner to use the TypeHack workaround you use below?

}

fn pg2d_agg(agg: &str) -> String {
format!("SELECT {}(test_y, test_x) FROM test_table", agg)
format!("SELECT {agg}(test_y, test_x), (SELECT {agg}(test_y, test_x) OVER (ORDER BY test_x ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) FROM test_table LIMIT 1 OFFSET 3) FROM test_table", agg = agg)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is going to be enough rows to actually see a difference and possibly will never even call the twofloat version because the condition that stops us from using the moving agg will be triggered here, I think we probably need to test with a bit more data...

Copy link
Member Author

Choose a reason for hiding this comment

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

I made the floating point error threshold f64::INFINITY in test mode – hopefully that should do the trick here?

@syvb syvb requested a review from WireBaron November 3, 2022 20:52
Copy link
Contributor

@WireBaron WireBaron left a comment

Choose a reason for hiding this comment

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

Looks good

@syvb syvb force-pushed the sv/stats_agg-twofloat branch from 30f00a1 to 32598c4 Compare November 4, 2022 13:44
@syvb syvb requested a review from davidkohn88 November 4, 2022 15:22
@syvb
Copy link
Member Author

syvb commented Nov 7, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 7, 2022

Build succeeded:

@bors bors bot merged commit 308ee7f into main Nov 7, 2022
@bors bors bot deleted the sv/stats_agg-twofloat branch November 7, 2022 20:02
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.

3 participants