jcsherin commented on PR #13169:
URL: https://github.com/apache/datafusion/pull/13169#issuecomment-2445400441
This is possible way to unit test the default implementation of
`expressions()`.
But putting this in test `datafusion/expr/src/udwf.rs` is not possible
because of the dependency on `datafusion_physical_expr::expressions::lit`. So
maybe we can add this to the `functions-window` crate.
```rust
#[cfg(test)]
mod tests {
use arrow::datatypes::{DataType, Field};
use datafusion_common::Result;
use datafusion_expr::{PartitionEvaluator, Signature, Volatility,
WindowUDF, WindowUDFImpl};
use datafusion_functions_window_common::expr::ExpressionArgs;
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
use
datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
use std::any::Any;
use datafusion_physical_expr::expressions::lit;
#[derive(Debug)]
struct ThreeArgWindowUDF {
signature: Signature,
}
impl ThreeArgWindowUDF {
fn new() -> Self {
Self {
signature: Signature::uniform(
3,
vec![DataType::Int32, DataType::Boolean,
DataType::Float32],
Volatility::Immutable,
),
}
}
}
impl WindowUDFImpl for ThreeArgWindowUDF {
fn as_any(&self) -> &dyn Any {
self
}
fn name(&self) -> &str {
"three_arg_window_udf"
}
fn signature(&self) -> &Signature {
&self.signature
}
fn partition_evaluator(&self, _: PartitionEvaluatorArgs) ->
Result<Box<dyn PartitionEvaluator>> {
todo!()
}
fn field(&self, _: WindowUDFFieldArgs) -> Result<Field> {
todo!()
}
}
#[test]
fn test_input_expressions() -> Result<()> {
let udwf = WindowUDF::from(ThreeArgWindowUDF::new());
let input_exprs = vec![lit(1), lit(false), lit(0.5)]; // Vec<Arc<dyn
PhysicalExpr>>
let input_types =[DataType::Int32, DataType::Boolean,
DataType::Float32]; // Vec<DataType>
let actual = udwf.expressions(ExpressionArgs::new(&input_exprs,
&input_types));
assert_eq!(actual.len(), 3);
assert_eq!(
format!("{:?}", actual.first().unwrap()),
format!("{:?}", input_exprs.first().unwrap()),
);
assert_eq!(
format!("{:?}", actual.get(1).unwrap()),
format!("{:?}", input_exprs.get(1).unwrap())
);
assert_eq!(
format!("{:?}", actual.get(2).unwrap()),
format!("{:?}", input_exprs.get(2).unwrap())
);
Ok(())
}
}
```
--
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]