@@ -46,9 +46,9 @@ make_udf_expr_and_func!(
4646 doc_section( label = "Array Functions" ) ,
4747 description = "Returns the product of the elements in the input numeric array. \
4848 NULL elements inside the array are skipped (matching SQL aggregate \
49- convention). Returns NULL if the whole input is NULL or if every \
50- element is NULL. Returns 1.0 for an empty array (multiplicative \
51- identity). The result is always returned as `Float64`.",
49+ convention). Returns NULL if the input is NULL, every element is \
50+ NULL, or the array is empty. The result is always returned as \
51+ `Float64`.",
5252 syntax_example = "array_product(array)" ,
5353 sql_example = r#"```sql
5454> select array_product([1.0, 2.0, 3.0]);
@@ -153,23 +153,12 @@ fn general_array_product<O: OffsetSizeTrait>(arrays: &[ArrayRef]) -> Result<Arra
153153
154154 let start = offsets[ row] . as_usize ( ) ;
155155 let end = offsets[ row + 1 ] . as_usize ( ) ;
156- let len = end - start;
157-
158- // Empty list -> multiplicative identity. Distinguished here from
159- // all-NULL elements (which yield NULL): we have no data either way,
160- // but `[]` is structurally a known-empty product, while `[NULL,NULL]`
161- // means every value was unknown.
162- if len == 0 {
163- builder. append_value ( 1.0 ) ;
164- continue ;
165- }
166156
167- let slice = values. slice ( start, len) ;
168157 let mut prod = 1.0_f64 ;
169158 let mut any_valid = false ;
170- for i in 0 ..len {
171- if slice . is_valid ( i) {
172- prod *= slice . value ( i) ;
159+ for i in start..end {
160+ if values . is_valid ( i) {
161+ prod *= values . value ( i) ;
173162 any_valid = true ;
174163 }
175164 }
0 commit comments