Copilot commented on code in PR #62067:
URL: https://github.com/apache/doris/pull/62067#discussion_r3028497286


##########
regression-test/suites/variant_p0/delete_update.groovy:
##########
@@ -73,6 +73,46 @@ suite("regression_test_variant_delete_and_update", 
"variant_type"){
     sql """delete from ${table_name} where vs = 'xxx' or vs = 'yyy'"""
     qt_sql "select * from ${table_name} order by k"
 
+    def partialUpdateVariantTable = "var_partial_update_keep_subcolumn"
+    sql "DROP TABLE IF EXISTS ${partialUpdateVariantTable}"
+    sql """
+        CREATE TABLE IF NOT EXISTS ${partialUpdateVariantTable} (
+            event_id bigint,
+            oneid string,
+            event_property_variant variant
+        )
+        UNIQUE KEY(`event_id`)
+        DISTRIBUTED BY HASH(event_id) BUCKETS 1
+        properties(
+            "replication_num" = "1",
+            "enable_unique_key_merge_on_write" = "true",
+            "store_row_column" = "true"
+        );
+    """
+    sql """insert into ${partialUpdateVariantTable} values
+            (1, 'old-oneid', 
'{"base_id":"100000000009523363","other_key":"abc"}')"""
+    sql "sync"
+
+    def beforeUpdate = sql """select cast(event_property_variant['base_id'] as 
string)
+                              from ${partialUpdateVariantTable}
+                              where event_id = 1"""
+    assertEquals("100000000009523363", beforeUpdate[0][0])
+
+    sql """update ${partialUpdateVariantTable}
+           set oneid = 'new-oneid'
+           where event_id = 1"""
+    sql "sync"
+
+    def afterUpdate = sql """select cast(event_property_variant['base_id'] as 
string)
+                             from ${partialUpdateVariantTable}
+                             where event_id = 1"""
+    assertEquals("100000000009523363", afterUpdate[0][0])
+
+    def wholeVariant = sql """select cast(event_property_variant as string)
+                              from ${partialUpdateVariantTable}
+                              where event_id = 1"""
+    assertEquals('{"base_id":"100000000009523363","other_key":"abc"}', 
wholeVariant[0][0])

Review Comment:
   This assertion is potentially flaky because the string serialization of a 
VARIANT/JSON object may not guarantee key order or exact formatting. To make 
the test stable, assert on individual fields (e.g., base_id and other_key) or 
compare a canonicalized representation rather than strict string equality of 
the whole object.
   ```suggestion
       def wholeVariant = sql """select cast(event_property_variant['base_id'] 
as string),
                                        
cast(event_property_variant['other_key'] as string)
                                 from ${partialUpdateVariantTable}
                                 where event_id = 1"""
       assertEquals("100000000009523363", wholeVariant[0][0])
       assertEquals("abc", wholeVariant[0][1])
   ```



##########
regression-test/suites/variant_p0/delete_update.groovy:
##########
@@ -73,6 +73,46 @@ suite("regression_test_variant_delete_and_update", 
"variant_type"){
     sql """delete from ${table_name} where vs = 'xxx' or vs = 'yyy'"""
     qt_sql "select * from ${table_name} order by k"
 
+    def partialUpdateVariantTable = "var_partial_update_keep_subcolumn"
+    sql "DROP TABLE IF EXISTS ${partialUpdateVariantTable}"
+    sql """
+        CREATE TABLE IF NOT EXISTS ${partialUpdateVariantTable} (
+            event_id bigint,
+            oneid string,
+            event_property_variant variant
+        )
+        UNIQUE KEY(`event_id`)
+        DISTRIBUTED BY HASH(event_id) BUCKETS 1
+        properties(
+            "replication_num" = "1",
+            "enable_unique_key_merge_on_write" = "true",
+            "store_row_column" = "true"
+        );
+    """
+    sql """insert into ${partialUpdateVariantTable} values
+            (1, 'old-oneid', 
'{"base_id":"100000000009523363","other_key":"abc"}')"""
+    sql "sync"
+
+    def beforeUpdate = sql """select cast(event_property_variant['base_id'] as 
string)
+                              from ${partialUpdateVariantTable}
+                              where event_id = 1"""
+    assertEquals("100000000009523363", beforeUpdate[0][0])
+

Review Comment:
   This test intends to validate behavior after a *partial update*, but it 
doesn't explicitly enable partial updates before running the UPDATE (the suite 
enables `enable_unique_key_partial_update` later for a different section). 
Consider setting `enable_unique_key_partial_update=true` (and syncing) before 
this UPDATE, so the regression reliably exercises the specific code path this 
PR changes.
   ```suggestion
   
       sql "set enable_unique_key_partial_update=true;"
       sql "sync"
   ```



##########
be/src/storage/segment/vertical_segment_writer.cpp:
##########
@@ -636,6 +636,12 @@ Status 
VerticalSegmentWriter::_append_block_with_partial_content(RowsInBlock& da
             _opts.rowset_ctx, _rsid_to_rowset, *_tablet_schema, full_block,
             use_default_or_null_flag, has_default_or_nullable, 
segment_start_pos, data.block));
 
+    if (_tablet_schema->num_variant_columns() > 0) {
+        RETURN_IF_ERROR(variant_util::parse_and_materialize_variant_columns(
+                full_block, *_tablet_schema,
+                _opts.rowset_ctx->partial_update_info->missing_cids));
+    }

Review Comment:
   This VARIANT materialization block is duplicated in both 
`VerticalSegmentWriter` and `SegmentWriter`. To reduce the risk of the two 
paths diverging in future changes, consider extracting this into a shared 
helper (e.g., a small function that takes `full_block`, schema, and 
missing_cids) used by both writers.



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