Skip to content

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.


#### 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.

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