From 77c8a4244924bd7b23c986886bb598ef5866b709 Mon Sep 17 00:00:00 2001 From: Brian Rowe Date: Mon, 28 Nov 2022 15:40:48 -0800 Subject: [PATCH] addressing review feedback and semantic suggestions --- extension/src/time_vector.rs | 52 +++++++----------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) diff --git a/extension/src/time_vector.rs b/extension/src/time_vector.rs index e2c7e7eb..def1e593 100644 --- a/extension/src/time_vector.rs +++ b/extension/src/time_vector.rs @@ -372,18 +372,19 @@ CREATE AGGREGATE rollup(\n\ pub mod toolkit_experimental { use super::*; - #[pg_extern(immutable, parallel_safe)] + // Only making this available through the arrow operator right now, as the semantics are cleaner that way pub fn asof_join<'a, 'b>( from: Timevector_TSTZ_F64<'a>, into: Timevector_TSTZ_F64<'b>, ) -> TableIterator< 'a, ( - name!(time, crate::raw::TimestampTz), name!(value1, Option), name!(value2, f64), + name!(time, crate::raw::TimestampTz), ), > { + assert!(from.num_points > 0 && into.num_points > 0, "both timevectors must be populated for an asof join"); let mut from = from .into_iter() .map(|points| (points.ts.into(), points.val)) @@ -395,7 +396,7 @@ pub mod toolkit_experimental { for (into_time, into_val) in into { // Handle case where into starts before from if into_time < from_time { - results.push((crate::raw::TimestampTz::from(into_time), None, into_val)); + results.push((None, into_val, crate::raw::TimestampTz::from(into_time))); continue; } @@ -407,9 +408,9 @@ pub mod toolkit_experimental { } results.push(( - crate::raw::TimestampTz::from(into_time), Some(from_val), into_val, + crate::raw::TimestampTz::from(into_time), )); } @@ -445,9 +446,9 @@ pub fn arrow_timevector_asof<'a>( ) -> TableIterator< 'a, ( - name!(time, crate::raw::TimestampTz), name!(value1, Option), name!(value2, f64), + name!(time, crate::raw::TimestampTz), ), > { toolkit_experimental::asof_join(series, accessor.into.clone().into()) @@ -735,41 +736,6 @@ mod tests { Spi::execute(|client| { client.select("SET timezone TO 'UTC'", None, None); - let mut result = client.select( - "WITH s as ( - SELECT timevector(time, value) AS v1 FROM - (VALUES - ('2022-10-1 1:00 UTC'::TIMESTAMPTZ, 20.0), - ('2022-10-1 2:00 UTC'::TIMESTAMPTZ, 30.0), - ('2022-10-1 3:00 UTC'::TIMESTAMPTZ, 40.0) - ) as v(time, value)), - t as ( - SELECT timevector(time, value) AS v2 FROM - (VALUES - ('2022-10-1 0:30 UTC'::TIMESTAMPTZ, 15.0), - ('2022-10-1 2:00 UTC'::TIMESTAMPTZ, 45.0), - ('2022-10-1 3:30 UTC'::TIMESTAMPTZ, 60.0) - ) as v(time, value)) - SELECT toolkit_experimental.asof_join(v1, v2)::TEXT - FROM s, t;", - None, - None, - ); - - assert_eq!( - result.next().unwrap()[1].value(), - Some("(\"2022-10-01 00:30:00+00\",,15)") - ); - assert_eq!( - result.next().unwrap()[1].value(), - Some("(\"2022-10-01 02:00:00+00\",30,45)") - ); - assert_eq!( - result.next().unwrap()[1].value(), - Some("(\"2022-10-01 03:30:00+00\",40,60)") - ); - assert!(result.next().is_none()); - let mut result = client.select( "WITH s as ( SELECT timevector(time, value) AS v1 FROM @@ -793,15 +759,15 @@ mod tests { assert_eq!( result.next().unwrap()[1].value(), - Some("(\"2022-10-01 00:30:00+00\",,15)") + Some("(,15,\"2022-10-01 00:30:00+00\")") ); assert_eq!( result.next().unwrap()[1].value(), - Some("(\"2022-10-01 02:00:00+00\",30,45)") + Some("(30,45,\"2022-10-01 02:00:00+00\")") ); assert_eq!( result.next().unwrap()[1].value(), - Some("(\"2022-10-01 03:30:00+00\",40,60)") + Some("(40,60,\"2022-10-01 03:30:00+00\")") ); assert!(result.next().is_none()); })