Skip to content

Use TwoFloats when using stats_agg in moving-aggregate#599

Merged
bors[bot] merged 4 commits into
mainfrom
sv/stats_agg-twofloat
Nov 7, 2022
Merged

Use TwoFloats when using stats_agg in moving-aggregate#599
bors[bot] merged 4 commits into
mainfrom
sv/stats_agg-twofloat

Conversation

@syvb

@syvb syvb commented Nov 2, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Comment thread crates/stats-agg/src/stats1d.rs Outdated
Comment thread crates/stats-agg/src/stats1d.rs Outdated
Comment thread extension/src/stats_agg.rs
Comment thread extension/src/stabilization_info.rs

// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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?

Comment thread extension/src/stats_agg.rs Outdated
@syvb syvb requested a review from WireBaron November 3, 2022 20:52

@WireBaron WireBaron left a comment

Copy link
Copy Markdown
Contributor

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

syvb commented Nov 7, 2022

Copy link
Copy Markdown
Contributor Author

bors r+

@bors

bors Bot commented Nov 7, 2022

Copy link
Copy Markdown
Contributor

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