github-actions[bot] commented on code in PR #61081:
URL: https://github.com/apache/doris/pull/61081#discussion_r2894162494


##########
be/src/vec/functions/array/function_array_apply.cpp:
##########
@@ -171,79 +172,47 @@ class FunctionArrayApply : public IFunction {
         return ColumnArray::create(filtered, std::move(column_offsets));
     }
 
-// need exception safety
-#define APPLY_ALL_TYPES(src_column, src_offsets, OP, cmp, dst)                 
               \
-    do {                                                                       
               \
-        switch (nested_type->get_primitive_type()) {                           
               \
-        case PrimitiveType::TYPE_BOOLEAN:                                      
               \
-            *dst = _apply_internal<UInt8, OP>(src_column, src_offsets, cmp);   
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_TINYINT:                                      
               \
-            *dst = _apply_internal<Int8, OP>(src_column, src_offsets, cmp);    
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_SMALLINT:                                     
               \
-            *dst = _apply_internal<Int16, OP>(src_column, src_offsets, cmp);   
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_INT:                                          
               \
-            *dst = _apply_internal<Int32, OP>(src_column, src_offsets, cmp);   
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_BIGINT:                                       
               \
-            *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp);   
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_FLOAT:                                        
               \
-            *dst = _apply_internal<Float32, OP>(src_column, src_offsets, cmp); 
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DOUBLE:                                       
               \
-            *dst = _apply_internal<Float64, OP>(src_column, src_offsets, cmp); 
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DATEV2:                                       
               \
-            *dst = _apply_internal<UInt32, OP>(src_column, src_offsets, cmp);  
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DATETIMEV2:                                   
               \
-            *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp);  
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_TIMESTAMPTZ:                                  
               \
-            *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp);  
               \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DECIMAL32:                                    
               \
-            *dst = _apply_internal<Decimal32, OP>(src_column, src_offsets, 
cmp);              \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DECIMAL64:                                    
               \
-            *dst = _apply_internal<Decimal64, OP>(src_column, src_offsets, 
cmp);              \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DECIMALV2:                                    
               \
-            *dst = _apply_internal<Decimal128V2, OP>(src_column, src_offsets, 
cmp);           \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DECIMAL128I:                                  
               \
-            *dst = _apply_internal<Decimal128V3, OP>(src_column, src_offsets, 
cmp);           \
-            break;                                                             
               \
-        case PrimitiveType::TYPE_DECIMAL256:                                   
               \
-            *dst = _apply_internal<Decimal256, OP>(src_column, src_offsets, 
cmp);             \
-            break;                                                             
               \
-        default:                                                               
               \
-            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,                
               \
-                                   "array_apply only accept array with nested 
type which is " \
-                                   "uint/int/decimal/float/date but got : " +  
               \
-                                           nested_type->get_name());           
               \
-        }                                                                      
               \
-    } while (0)
-
+    template <ApplyOp OP>
+    void dispatch_array_scalar(DataTypePtr nested_type, const IColumn& 
src_column,
+                               const ColumnArray::Offsets64& src_offsets, 
const ColumnConst& cmp,
+                               ColumnPtr* dst) const {
+        auto call = [&](const auto& type) -> bool {
+            using DispatchType = std::decay_t<decltype(type)>;
+            constexpr PrimitiveType PType = DispatchType::PType;
+            *dst = _apply_internal<typename 
PrimitiveTypeTraits<PType>::CppType, OP>(
+                    src_column, src_offsets, cmp);
+            return true;
+        };
+
+        if (!dispatch_switch_scalar(nested_type->get_primitive_type(), call)) {
+            throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
+                                   "array_apply only accept array with nested 
type which is "
+                                   "uint/int/decimal/float/date but got : " +

Review Comment:
   Nit: This error message says `uint/int/decimal/float/date` but 
`dispatch_switch_scalar` (SCALAR mask = INT | FLOAT | DECIMAL | DATETIME | IP) 
also accepts IP types (IPV4, IPV6) and LARGEINT. Consider updating to something 
like `"array_apply only accepts array with scalar nested type 
(int/largeint/decimal/float/date/ip) but got: "` to accurately reflect the 
supported types.



-- 
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]

Reply via email to