HappenLee commented on code in PR #33126:
URL: https://github.com/apache/doris/pull/33126#discussion_r1554946123


##########
be/src/vec/core/block.cpp:
##########
@@ -728,6 +730,87 @@ void Block::shuffle_columns(const std::vector<int>& 
result_column_ids) {
     swap(Block {tmp_data});
 }
 
+void Block::build_output_block_after_projects(Block& input_block, Block& 
origin_block,
+                                              const std::vector<int>& 
result_column_ids) {
+    auto insert_column_datas = [](vectorized::ColumnPtr& to, 
vectorized::ColumnPtr& origin_column,
+                                  size_t rows, bool use_swap) {
+        auto insert_column = [](vectorized::ColumnPtr& to, 
vectorized::ColumnPtr& from, size_t rows,
+                                bool use_swap) {
+            if (!to->is_nullable() && from->is_nullable()) {
+                throw Exception(ErrorCode::INTERNAL_ERROR,
+                                "cannot convert a nullable column to a 
non-nullable");
+            }
+            // Due to historical reasons, there are some cases where 
non-nullable columns are converted to nullable ones.
+            // We plan to remove such code in the future.
+            if (to->is_nullable() && !from->is_nullable()) {
+                if (use_swap) {
+                    make_nullable(from, false).swap(to);
+                } else {
+                    MutableColumnPtr mut_to = (*std::move(to)).mutate();
+                    reinterpret_cast<vectorized::ColumnNullable&>(*mut_to)
+                            .insert_range_from_not_nullable(*from, 0, rows);
+                    to = std::move(mut_to);
+                }
+            } else {
+                if (use_swap) {
+                    to.swap(from);
+                } else {
+                    MutableColumnPtr mut_to = (*std::move(to)).mutate();
+                    mut_to->insert_range_from(*from, 0, rows);
+                    to = std::move(mut_to);
+                }
+            }
+        };
+        if (is_column_const(*origin_column)) {
+            auto column_ptr = origin_column->convert_to_full_column_if_const();
+            insert_column(to, column_ptr, rows, false);

Review Comment:
   the column_ptr is temporary mem,so here better `use_swap` = 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: commits-unsubscr...@doris.apache.org

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


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

Reply via email to