/Users/andrewlamb/Software/datafusion/datafusion/physical-expr/src/intervals/test_utils.rs
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | //http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | //! Test utilities for the interval arithmetic library |
19 | | |
20 | | use std::sync::Arc; |
21 | | |
22 | | use crate::expressions::{binary, BinaryExpr, Literal}; |
23 | | use crate::PhysicalExpr; |
24 | | use arrow_schema::Schema; |
25 | | use datafusion_common::{DataFusionError, ScalarValue}; |
26 | | use datafusion_expr::Operator; |
27 | | |
28 | | #[allow(clippy::too_many_arguments)] |
29 | | /// This test function generates a conjunctive statement with two numeric |
30 | | /// terms with the following form: |
31 | | /// left_col (op_1) a >/>= right_col (op_2) b AND left_col (op_3) c </<= right_col (op_4) d |
32 | 243 | pub fn gen_conjunctive_numerical_expr( |
33 | 243 | left_col: Arc<dyn PhysicalExpr>, |
34 | 243 | right_col: Arc<dyn PhysicalExpr>, |
35 | 243 | op: (Operator, Operator, Operator, Operator), |
36 | 243 | a: ScalarValue, |
37 | 243 | b: ScalarValue, |
38 | 243 | c: ScalarValue, |
39 | 243 | d: ScalarValue, |
40 | 243 | bounds: (Operator, Operator), |
41 | 243 | ) -> Arc<dyn PhysicalExpr> { |
42 | 243 | let (op_1, op_2, op_3, op_4) = op; |
43 | 243 | let left_and_1 = Arc::new(BinaryExpr::new( |
44 | 243 | Arc::clone(&left_col), |
45 | 243 | op_1, |
46 | 243 | Arc::new(Literal::new(a)), |
47 | 243 | )); |
48 | 243 | let left_and_2 = Arc::new(BinaryExpr::new( |
49 | 243 | Arc::clone(&right_col), |
50 | 243 | op_2, |
51 | 243 | Arc::new(Literal::new(b)), |
52 | 243 | )); |
53 | 243 | let right_and_1 = |
54 | 243 | Arc::new(BinaryExpr::new(left_col, op_3, Arc::new(Literal::new(c)))); |
55 | 243 | let right_and_2 = |
56 | 243 | Arc::new(BinaryExpr::new(right_col, op_4, Arc::new(Literal::new(d)))); |
57 | 243 | let (greater_op, less_op) = bounds; |
58 | 243 | |
59 | 243 | let left_expr = Arc::new(BinaryExpr::new(left_and_1, greater_op, left_and_2)); |
60 | 243 | let right_expr = Arc::new(BinaryExpr::new(right_and_1, less_op, right_and_2)); |
61 | 243 | Arc::new(BinaryExpr::new(left_expr, Operator::And, right_expr)) |
62 | 243 | } |
63 | | |
64 | | #[allow(clippy::too_many_arguments)] |
65 | | /// This test function generates a conjunctive statement with |
66 | | /// two scalar values with the following form: |
67 | | /// left_col (op_1) a > right_col (op_2) b AND left_col (op_3) c < right_col (op_4) d |
68 | 64 | pub fn gen_conjunctive_temporal_expr( |
69 | 64 | left_col: Arc<dyn PhysicalExpr>, |
70 | 64 | right_col: Arc<dyn PhysicalExpr>, |
71 | 64 | op_1: Operator, |
72 | 64 | op_2: Operator, |
73 | 64 | op_3: Operator, |
74 | 64 | op_4: Operator, |
75 | 64 | a: ScalarValue, |
76 | 64 | b: ScalarValue, |
77 | 64 | c: ScalarValue, |
78 | 64 | d: ScalarValue, |
79 | 64 | schema: &Schema, |
80 | 64 | ) -> Result<Arc<dyn PhysicalExpr>, DataFusionError> { |
81 | 64 | let left_and_1 = binary( |
82 | 64 | Arc::clone(&left_col), |
83 | 64 | op_1, |
84 | 64 | Arc::new(Literal::new(a)), |
85 | 64 | schema, |
86 | 64 | )?0 ; |
87 | 64 | let left_and_2 = binary( |
88 | 64 | Arc::clone(&right_col), |
89 | 64 | op_2, |
90 | 64 | Arc::new(Literal::new(b)), |
91 | 64 | schema, |
92 | 64 | )?0 ; |
93 | 64 | let right_and_1 = binary(left_col, op_3, Arc::new(Literal::new(c)), schema)?0 ; |
94 | 64 | let right_and_2 = binary(right_col, op_4, Arc::new(Literal::new(d)), schema)?0 ; |
95 | 64 | let left_expr = Arc::new(BinaryExpr::new(left_and_1, Operator::Gt, left_and_2)); |
96 | 64 | let right_expr = Arc::new(BinaryExpr::new(right_and_1, Operator::Lt, right_and_2)); |
97 | 64 | Ok(Arc::new(BinaryExpr::new( |
98 | 64 | left_expr, |
99 | 64 | Operator::And, |
100 | 64 | right_expr, |
101 | 64 | ))) |
102 | 64 | } |