|
15 | 15 | // specific language governing permissions and limitations |
16 | 16 | // under the License. |
17 | 17 |
|
18 | | -use arrow::array::{ArrayRef, ArrowNativeTypeOp, RecordBatch}; |
| 18 | +use arrow::array::{ArrayRef, ArrowNativeTypeOp}; |
19 | 19 | use arrow::compute::SortOptions; |
20 | 20 | use arrow::datatypes::{ |
21 | | - ArrowNativeType, DataType, DecimalType, Field, FieldRef, Schema, ToByteSlice, |
22 | | -}; |
23 | | -use datafusion_common::{ |
24 | | - exec_err, internal_datafusion_err, internal_err, plan_err, DataFusionError, Result, |
25 | | - ScalarValue, |
| 21 | + ArrowNativeType, DataType, DecimalType, Field, FieldRef, ToByteSlice, |
26 | 22 | }; |
| 23 | +use datafusion_common::{exec_err, internal_datafusion_err, Result}; |
27 | 24 | use datafusion_expr_common::accumulator::Accumulator; |
28 | | -use datafusion_expr_common::columnar_value::ColumnarValue; |
29 | | -use datafusion_physical_expr_common::physical_expr::PhysicalExpr; |
30 | 25 | use datafusion_physical_expr_common::sort_expr::{LexOrdering, PhysicalSortExpr}; |
31 | 26 | use std::sync::Arc; |
32 | 27 |
|
@@ -166,55 +161,3 @@ impl<T: DecimalType> DecimalAverager<T> { |
166 | 161 | } |
167 | 162 | } |
168 | 163 | } |
169 | | - |
170 | | -/// Evaluates a physical expression to extract its scalar value. |
171 | | -/// |
172 | | -/// This is used to extract constant values from expressions (like percentile parameters) |
173 | | -/// by evaluating them against an empty record batch. |
174 | | -pub fn get_percentile_scalar_value(expr: &Arc<dyn PhysicalExpr>) -> Result<ScalarValue> { |
175 | | - let empty_schema = Arc::new(Schema::empty()); |
176 | | - let batch = RecordBatch::new_empty(Arc::clone(&empty_schema)); |
177 | | - if let ColumnarValue::Scalar(s) = expr.evaluate(&batch)? { |
178 | | - Ok(s) |
179 | | - } else { |
180 | | - internal_err!("Didn't expect ColumnarValue::Array") |
181 | | - } |
182 | | -} |
183 | | - |
184 | | -/// Validates that a percentile expression is a literal float value between 0.0 and 1.0. |
185 | | -/// |
186 | | -/// Used by both `percentile_cont` and `approx_percentile_cont` to validate their |
187 | | -/// percentile parameters. |
188 | | -pub fn validate_percentile_expr( |
189 | | - expr: &Arc<dyn PhysicalExpr>, |
190 | | - fn_name: &str, |
191 | | -) -> Result<f64> { |
192 | | - let scalar_value = get_percentile_scalar_value(expr).map_err(|_e| { |
193 | | - DataFusionError::Plan(format!( |
194 | | - "Percentile value for '{fn_name}' must be a literal" |
195 | | - )) |
196 | | - })?; |
197 | | - |
198 | | - let percentile = match scalar_value { |
199 | | - ScalarValue::Float32(Some(value)) => { |
200 | | - value as f64 |
201 | | - } |
202 | | - ScalarValue::Float64(Some(value)) => { |
203 | | - value |
204 | | - } |
205 | | - sv => { |
206 | | - return plan_err!( |
207 | | - "Percentile value for '{fn_name}' must be Float32 or Float64 literal (got data type {})", |
208 | | - sv.data_type() |
209 | | - ) |
210 | | - } |
211 | | - }; |
212 | | - |
213 | | - // Ensure the percentile is between 0 and 1. |
214 | | - if !(0.0..=1.0).contains(&percentile) { |
215 | | - return plan_err!( |
216 | | - "Percentile value must be between 0.0 and 1.0 inclusive, {percentile} is invalid" |
217 | | - ); |
218 | | - } |
219 | | - Ok(percentile) |
220 | | -} |
0 commit comments