You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/10/14 03:33:37 UTC

[GitHub] [doris] BiteTheDDDDt commented on a diff in pull request #13273: [improvement](schema change) avoid using column ptr swap

BiteTheDDDDt commented on code in PR #13273:
URL: https://github.com/apache/doris/pull/13273#discussion_r995308928


##########
be/src/olap/schema_change.cpp:
##########
@@ -834,8 +834,34 @@ Status RowBlockChanger::change_block(vectorized::Block* ref_block,
     }
 
     for (auto it : swap_idx_map) {
-        new_block->get_by_position(it.second).column.swap(
-                ref_block->get_by_position(it.first).column);
+        auto& ref_col = ref_block->get_by_position(it.first);
+        auto& new_col = new_block->get_by_position(it.second);
+
+        bool ref_col_nullable = ref_col.column->is_nullable();
+        bool new_col_nullable = new_col.column->is_nullable();
+
+        if (ref_col_nullable != new_col_nullable) {
+            // not nullable to nullable
+            if (new_col_nullable) {
+                auto* new_nullable_col = assert_cast<vectorized::ColumnNullable*>(
+                        std::move(*new_col.column).mutate().get());
+
+                new_nullable_col->swap_nested_column(ref_col.column);
+                new_nullable_col->get_null_map_data().resize_fill(new_nullable_col->size());
+            } else {
+                // nullable to not nullable:

Review Comment:
   It is best to add a logic to check that the nullmap does not contain null. If there is null data, the schema change will fail to prevent accidental data loss.



-- 
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: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org