Omega359 commented on code in PR #9040:
URL: https://github.com/apache/arrow-datafusion/pull/9040#discussion_r1470302230
##########
datafusion/physical-expr/src/datetime_expressions.rs:
##########
@@ -497,6 +502,99 @@ pub fn make_current_time(
move |_arg| Ok(ColumnarValue::Scalar(ScalarValue::Time64Nanosecond(nano)))
}
+/// make_date(year, month, date) SQL function implementation
+pub fn make_date(args: &[ColumnarValue]) -> Result<ColumnarValue> {
+ if args.len() != 3 {
+ return exec_err!(
+ "make_date function requires 3 arguments, got {}",
+ args.len()
+ );
+ }
+
+ // first, identify if any of the arguments is an Array. If yes, store its
`len`,
+ // as any scalar will need to be converted to an array of len `len`.
+ let len = args
+ .iter()
+ .fold(Option::<usize>::None, |acc, arg| match arg {
+ ColumnarValue::Scalar(_) => acc,
+ ColumnarValue::Array(a) => Some(a.len()),
+ });
+
+ let is_scalar = len.is_none();
+ let array_size = if is_scalar { 1 } else { len.unwrap() };
+
+ let years = cast_column(&args[0], &DataType::Int32, None)?;
+ let months = cast_column(&args[1], &DataType::Int32, None)?;
+ let days = cast_column(&args[2], &DataType::Int32, None)?;
+
+ let value_fn = |col: &ColumnarValue, pos: usize| -> Result<i32> {
Review Comment:
Initially I was tempted to try adding an IntoIterator for ColumnarValue that
accepted an optional size (for scalar) which returns an option of either the
array value at the current pos or the scalar value. That seemed a bit much
given my current Rust skill level though.
--
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]