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


##########
be/src/exprs/vectorized_fn_call.cpp:
##########
@@ -215,6 +217,33 @@ size_t raw_comparison_value_size(PrimitiveType 
primitive_type) {
     }
 }
 
+Status create_agg_state_finalize_function(const std::string& function_name,
+                                          const DataTypes& argument_types,
+                                          const DataTypePtr& return_type,
+                                          FunctionBasePtr& function) {
+    if (argument_types.size() != 1 ||
+        remove_nullable(argument_types[0])->get_primitive_type() != 
TYPE_AGG_STATE) {
+        return Status::InternalError("Finalize function requires one AGG_STATE 
argument");
+    }
+    const auto state_type = remove_nullable(argument_types[0]);
+    const auto* agg_state = assert_cast<const 
DataTypeAggState*>(state_type.get());
+    if (agg_state->get_function_name() + AGG_FINALIZE_SUFFIX != function_name) 
{
+        return Status::InternalError("{} does not match function {}", 
state_type->get_name(),
+                                     function_name);
+    }
+    const auto& nested = agg_state->get_nested_function();
+    auto expected_type = nested->get_return_type();
+    if (argument_types[0]->is_nullable()) {
+        expected_type = make_nullable(expected_type);
+    }
+    if (!expected_type->equals(*return_type)) {

Review Comment:
   [P1] Preserve the effective decimal aggregate result type
   
   This equality check rejects valid states because `DataTypeAggState` cannot 
always reconstruct the return type FE planned from argument subtypes alone. For 
example, with `enable_decimal256=true`, `sum_finalize(sum_state(cast(1 as 
decimal(12,2))))` and the AVG equivalent have Decimal256 FE return types, but 
BE rebuilds their narrow state subtype as Decimal128. The problem is not 
limited to that flag: FE gives decimal `sum_map`/`avg_map` a 
`MAP<K,DECIMAL(38,s)>` result, while the state stores `MAP<K,DECIMAL(12,s)>`; 
since `DataTypeAggState` only widens a top-level DecimalV3 subtype, BE rebuilds 
the map's nested aggregate with the narrow decimal family. In both cases 
`nested->get_return_type()` differs and prepare returns `InternalError`. Please 
preserve the effective nested result type in the state/reconstruction contract 
(or otherwise make FE and BE derive it identically), with end-to-end scalar and 
MAP decimal finalizer coverage.



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