Xuanwo commented on code in PR #23831:
URL: https://github.com/apache/datafusion/pull/23831#discussion_r3985795755
##########
datafusion/core/tests/dataframe/mod.rs:
##########
@@ -1521,6 +1521,75 @@ async fn join() -> Result<()> {
Ok(())
}
+#[tokio::test]
+async fn join_asof() -> Result<()> {
+ let ctx = SessionContext::new();
+ let left = ctx
+ .read_batch(record_batch!(
+ ("symbol", Utf8, ["A", "A", "B"]),
+ ("ts", Int64, [1, 4, 2]),
+ ("trade_id", Int32, [1, 2, 3])
+ )?)?
+ .alias("trades")?;
+ let right = ctx
+ .read_batch(record_batch!(
+ ("symbol", Utf8, ["A", "A", "B"]),
+ ("ts", Int64, [2, 4, 1]),
+ ("price", Int32, [20, 40, 101])
+ )?)?
+ .alias("prices")?;
+
+ let results = left
+ .clone()
+ .join_asof(
+ right.clone(),
+ Some(col("trades.symbol").eq(col("prices.symbol"))),
+ col("trades.ts").gt_eq(col("prices.ts")),
+ )?
+ .select(vec![col("trade_id"), col("price")])?
+ .sort(vec![col("trade_id").sort(true, true)])?
+ .collect()
+ .await?;
+
+ assert_batches_eq!(
+ [
+ "+----------+-------+",
+ "| trade_id | price |",
+ "+----------+-------+",
+ "| 1 | |",
+ "| 2 | 40 |",
+ "| 3 | 101 |",
+ "+----------+-------+",
+ ],
+ &results
+ );
+
+ let results = left
+ .join_asof_using(
+ right,
+ vec![datafusion_common::Column::from_name("symbol")],
+ col("trades.ts").gt_eq(col("prices.ts")),
+ )?
+ .select(vec![col("trade_id"), col("price")])?
Review Comment:
added!
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -1380,6 +1380,46 @@ impl DataFrame {
})
}
+ /// Join this `DataFrame` to the closest eligible row in `right`.
+ ///
+ /// Every left row is emitted exactly once. When present, `on` must contain
+ /// equality comparisons combined with `AND`. `match_condition` must be a
+ /// single `<`, `<=`, `>`, or `>=` comparison whose left and right operands
+ /// reference this `DataFrame` and `right`, respectively.
Review Comment:
added!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]