()
| 1757 | |
| 1758 | #[mz_ore::test] |
| 1759 | fn test_eval_range() { |
| 1760 | // Example inspired by the tumbling windows temporal filter in the docs |
| 1761 | let period_ms = MirScalarExpr::literal_ok(Datum::Int64(10), ReprScalarType::Int64); |
| 1762 | let expr = MirScalarExpr::CallBinary { |
| 1763 | func: Gte.into(), |
| 1764 | expr1: Box::new(MirScalarExpr::CallUnmaterializable( |
| 1765 | UnmaterializableFunc::MzNow, |
| 1766 | )), |
| 1767 | expr2: Box::new(MirScalarExpr::CallUnary { |
| 1768 | func: UnaryFunc::CastInt64ToMzTimestamp(CastInt64ToMzTimestamp), |
| 1769 | expr: Box::new(MirScalarExpr::CallBinary { |
| 1770 | func: MulInt64.into(), |
| 1771 | expr1: Box::new(period_ms.clone()), |
| 1772 | expr2: Box::new(MirScalarExpr::CallBinary { |
| 1773 | func: DivInt64.into(), |
| 1774 | expr1: Box::new(MirScalarExpr::column(0)), |
| 1775 | expr2: Box::new(period_ms), |
| 1776 | }), |
| 1777 | }), |
| 1778 | }), |
| 1779 | }; |
| 1780 | let relation = ReprRelationType::new(vec![ReprScalarType::Int64.nullable(false)]); |
| 1781 | |
| 1782 | { |
| 1783 | // Non-overlapping windows |
| 1784 | let arena = RowArena::new(); |
| 1785 | let mut interpreter = ColumnSpecs::new(&relation, &arena); |
| 1786 | interpreter.push_unmaterializable( |
| 1787 | UnmaterializableFunc::MzNow, |
| 1788 | ResultSpec::value_between( |
| 1789 | Datum::MzTimestamp(10.into()), |
| 1790 | Datum::MzTimestamp(20.into()), |
| 1791 | ), |
| 1792 | ); |
| 1793 | interpreter.push_column(0, ResultSpec::value_between(30i64.into(), 40i64.into())); |
| 1794 | |
| 1795 | let range_out = interpreter.expr(&expr).range; |
| 1796 | assert!(range_out.may_contain(Datum::False)); |
| 1797 | assert!(!range_out.may_contain(Datum::True)); |
| 1798 | assert!(!range_out.may_contain(Datum::Null)); |
| 1799 | assert!(!range_out.may_fail()); |
| 1800 | } |
| 1801 | |
| 1802 | { |
| 1803 | // Overlapping windows |
| 1804 | let arena = RowArena::new(); |
| 1805 | let mut interpreter = ColumnSpecs::new(&relation, &arena); |
| 1806 | interpreter.push_unmaterializable( |
| 1807 | UnmaterializableFunc::MzNow, |
| 1808 | ResultSpec::value_between( |
| 1809 | Datum::MzTimestamp(10.into()), |
| 1810 | Datum::MzTimestamp(35.into()), |
| 1811 | ), |
| 1812 | ); |
| 1813 | interpreter.push_column(0, ResultSpec::value_between(30i64.into(), 40i64.into())); |
| 1814 | |
| 1815 | let range_out = interpreter.expr(&expr).range; |
| 1816 | assert!(range_out.may_contain(Datum::False)); |
nothing calls this directly
no test coverage detected