@@ -1688,3 +1688,70 @@ fn test_pivot() {
16881688 "ORDER BY region" ,
16891689 ) ) ;
16901690}
1691+
1692+ #[ test]
1693+ fn asof_joins ( ) {
1694+ #[ rustfmt:: skip]
1695+ let query = snowflake_and_generic ( ) . verified_only_select ( concat ! (
1696+ "SELECT * " ,
1697+ "FROM trades_unixtime AS tu " ,
1698+ "ASOF JOIN quotes_unixtime AS qu " ,
1699+ "MATCH_CONDITION (tu.trade_time >= qu.quote_time)" ,
1700+ ) ) ;
1701+
1702+ assert_eq ! (
1703+ query. from[ 0 ] ,
1704+ TableWithJoins {
1705+ relation: table_with_alias( "trades_unixtime" , "tu" ) ,
1706+ joins: vec![ Join {
1707+ relation: table_with_alias( "quotes_unixtime" , "qu" ) ,
1708+ join_operator: JoinOperator :: AsOf {
1709+ match_condition: Expr :: BinaryOp {
1710+ left: Box :: new( Expr :: CompoundIdentifier ( vec![
1711+ Ident :: new( "tu" ) ,
1712+ Ident :: new( "trade_time" ) ,
1713+ ] ) ) ,
1714+ op: BinaryOperator :: GtEq ,
1715+ right: Box :: new( Expr :: CompoundIdentifier ( vec![
1716+ Ident :: new( "qu" ) ,
1717+ Ident :: new( "quote_time" ) ,
1718+ ] ) ) ,
1719+ } ,
1720+ constraint: JoinConstraint :: None ,
1721+ } ,
1722+ } ] ,
1723+ }
1724+ ) ;
1725+
1726+ #[ rustfmt:: skip]
1727+ snowflake_and_generic ( ) . verified_query ( concat ! (
1728+ "SELECT t.stock_symbol, t.trade_time, t.quantity, q.quote_time, q.price " ,
1729+ "FROM trades AS t ASOF JOIN quotes AS q " ,
1730+ "MATCH_CONDITION (t.trade_time >= quote_time) " ,
1731+ "ON t.stock_symbol = q.stock_symbol " ,
1732+ "ORDER BY t.stock_symbol" ,
1733+ ) ) ;
1734+
1735+ #[ rustfmt:: skip]
1736+ snowflake_and_generic ( ) . verified_query ( concat ! (
1737+ "SELECT t.stock_symbol, c.company_name, t.trade_time, t.quantity, q.quote_time, q.price " ,
1738+ "FROM trades AS t ASOF JOIN quotes AS q " ,
1739+ "MATCH_CONDITION (t.trade_time <= quote_time) " ,
1740+ "USING(stock_symbol) " ,
1741+ "JOIN companies AS c ON c.stock_symbol = t.stock_symbol " ,
1742+ "ORDER BY t.stock_symbol" ,
1743+ ) ) ;
1744+
1745+ #[ rustfmt:: skip]
1746+ snowflake_and_generic ( ) . verified_query ( concat ! (
1747+ "SELECT * " ,
1748+ "FROM snowtime AS s " ,
1749+ "ASOF JOIN raintime AS r " ,
1750+ "MATCH_CONDITION (s.observed >= r.observed) " ,
1751+ "ON s.state = r.state " ,
1752+ "ASOF JOIN preciptime AS p " ,
1753+ "MATCH_CONDITION (s.observed >= p.observed) " ,
1754+ "ON s.state = p.state " ,
1755+ "ORDER BY s.observed" ,
1756+ ) ) ;
1757+ }
0 commit comments