@@ -21,12 +21,12 @@ use std::sync::Arc;
2121use arrow:: array:: { Array , ArrayRef , IntervalMonthDayNanoBuilder , PrimitiveArray } ;
2222use arrow:: datatypes:: DataType :: Interval ;
2323use arrow:: datatypes:: IntervalUnit :: MonthDayNano ;
24- use arrow:: datatypes:: { DataType , IntervalMonthDayNano } ;
24+ use arrow:: datatypes:: { DataType , Field , FieldRef , IntervalMonthDayNano } ;
2525use datafusion_common:: types:: { NativeType , logical_float64, logical_int32} ;
2626use datafusion_common:: { DataFusionError , Result , ScalarValue , plan_datafusion_err} ;
2727use datafusion_expr:: {
28- Coercion , ColumnarValue , ScalarFunctionArgs , ScalarUDFImpl , Signature , TypeSignature ,
29- TypeSignatureClass , Volatility ,
28+ Coercion , ColumnarValue , ReturnFieldArgs , ScalarFunctionArgs , ScalarUDFImpl , Signature ,
29+ TypeSignature , TypeSignatureClass , Volatility ,
3030} ;
3131use datafusion_functions:: utils:: make_scalar_function;
3232
@@ -122,6 +122,31 @@ impl ScalarUDFImpl for SparkMakeInterval {
122122 Ok ( Interval ( MonthDayNano ) )
123123 }
124124
125+ fn return_field_from_args ( & self , args : ReturnFieldArgs < ' _ > ) -> Result < FieldRef > {
126+ // Spark make_interval semantics:
127+ // - Returns NULL if ANY input argument is NULL
128+ // - Returns NULL on arithmetic overflow (e.g., year * 12 + month overflows)
129+ // - With no arguments, returns a non-null zero interval
130+ //
131+ // Therefore:
132+ // - If no arguments: not nullable (always returns 0 interval)
133+ // - If any arguments: nullable (inputs might be null OR overflow might occur)
134+ let nullable = if args. arg_fields . is_empty ( ) {
135+ false
136+ } else {
137+ // Always nullable when we have arguments because:
138+ // 1. Any nullable input → nullable output
139+ // 2. Overflow can occur even with non-null inputs → nullable output
140+ true
141+ } ;
142+
143+ Ok ( Arc :: new ( Field :: new (
144+ "make_interval" ,
145+ Interval ( MonthDayNano ) ,
146+ nullable,
147+ ) ) )
148+ }
149+
125150 fn invoke_with_args ( & self , args : ScalarFunctionArgs ) -> Result < ColumnarValue > {
126151 if args. args . is_empty ( ) {
127152 return Ok ( ColumnarValue :: Scalar ( ScalarValue :: IntervalMonthDayNano (
0 commit comments