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

Adding asof joins for timevector #635

Merged
merged 1 commit into from
Dec 1, 2022
Merged

Adding asof joins for timevector #635

merged 1 commit into from
Dec 1, 2022

Conversation

WireBaron
Copy link
Contributor

This change adds a new function join_asof which takes two timevectors and outputs the values of the first at the times given in the second (as well as the values in the second).

Fixes #633

.map(|points| (points.ts.into(), points.val))
.peekable();
let into = into.into_iter().map(|points| (points.ts, points.val));
let (mut from_time, mut from_val) = from.next().unwrap();
Copy link
Member

@syvb syvb Nov 28, 2022

Choose a reason for hiding this comment

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

The default error message from .unwrap() isn't particularly user friendly:

Suggested change
let (mut from_time, mut from_val) = from.next().unwrap();
let (mut from_time, mut from_val) = from.next().expect("Must have at least one point in joining column");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, however it's also going to have potentially ugly behavior if the into vector is empty, so I added an assert that neither is empty to the start of this function.

> {
assert!(
from.num_points > 0 && into.num_points > 0,
"both timevectors must be populated for an asof join"
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we test these two errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added...it's actually surprisingly difficult to create an empty timevector.

@@ -7,11 +7,14 @@ This changelog should be updated as part of a PR if the work is worth noting (mo
## Next Release (Date TBD)

#### New experimental features
- [#615](https://github.com/timescale/timescaledb-toolkit/pull/614): Heatbeat aggregate
- [#615](https://github.com/timescale/timescaledb-toolkit/pull/615): Heatbeat aggregate
Copy link
Contributor

Choose a reason for hiding this comment

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

Hehe we caught the same thing! Also "heatbeat" though, and also there are some rendering problems without blank lines. I sent a pull request for these.

Users can use the new `heartbeat_agg(timestamp, start_time, agg_interval, heartbeat_interval)` to track the liveness of a system in the range (`start_time`, `start_time` + `agg_interval`). Each timestamp seen in that range is assumed to indicate system liveness for the following `heartbeat_interval`.
Once constructed, users can query heartbeat aggregates for `uptime` and `downtime`, as well as query for `live_ranges` or `dead_ranges`. Users can also check for `live_at(timestamp)`.
Heartbeat aggregates can also interpolated to better see behavior around the boundaries of the individual aggregates.

- [#635](https://github.com/timescale/timescaledb-toolkit/pull/635): AsOf joins for timevectors
This allows users to join two timevectors with the following semantics `timevectorA -> asof(timevectorB)`. This will return records with the LOCF value from timevectorA at the timestamps from timevectorB. Specifically the returned records contain, for each value in timevectorB, {the LOCF value from timevectorA, the value from timevectorB, the timestamp from timevectorB}.
Copy link
Contributor

Choose a reason for hiding this comment

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

Without a blank line between lines 15 and 16 here, Github squishes it all into one paragraph. The blank does not disrupt the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this and merged your fix for the above. Will merge once I verify everything looks good.

This change adds a new function `join_asof` which takes two timevectors and
outputs the values of the first at the times given in the second (as well as
the values in the second).
@WireBaron
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Dec 1, 2022

Build succeeded:

@bors bors bot merged commit 831f305 into main Dec 1, 2022
@bors bors bot deleted the br/asof_join branch December 1, 2022 22:55
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.

asof_join for timevectors
3 participants