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


##########
be/src/exprs/function/cast/cast_to_map.h:
##########
@@ -21,15 +21,53 @@
 #include "exprs/function/cast/cast_base.h"
 
 namespace doris::CastWrapper {
+
+inline Status deduplicate_map_keys_in_result(Block& block, uint32_t result) {
+    auto result_column_name = block.get_by_position(result).column->get_name();
+    auto mutable_result_column = 
IColumn::mutate(std::move(block.get_by_position(result).column));
+
+    if (auto* nullable_column = 
check_and_get_column<ColumnNullable>(*mutable_result_column)) {
+        auto nested_column = 
IColumn::mutate(nullable_column->get_nested_column_ptr());
+        auto* map_column = check_and_get_column<ColumnMap>(*nested_column);
+        if (!map_column) {
+            return Status::RuntimeError("Illegal column {} for function CAST 
AS MAP",
+                                        result_column_name);
+        }
+
+        RETURN_IF_ERROR(map_column->deduplicate_keys());

Review Comment:
   This only deduplicates the outer `ColumnMap`. 
`DataTypeMapSerDe::_from_string()` recursively deserializes MAP values but does 
not deduplicate them, so a cast like `CAST('{"outer":{"a":1,"a":2}}' AS 
MAP<STRING, MAP<STRING, INT>>)` will still leave duplicate keys in the nested 
map and `element_at(..., 'a')` can keep returning the first value there. That 
means the PR fixes the top-level repro but not the same inconsistency for 
nested MAP types. Please call `deduplicate_keys(true)` here (and in the 
non-nullable branch) and add a nested MAP regression case.
   
   ```suggestion
           RETURN_IF_ERROR(map_column->deduplicate_keys(true));
   ```



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