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


##########
be/src/vec/columns/column_object.cpp:
##########
@@ -415,11 +456,77 @@ void ColumnObject::Subcolumn::insert(Field field, 
FieldInfo info) {
     data.back()->insert(field);
 }
 
-void ColumnObject::Subcolumn::insertRangeFrom(const Subcolumn& src, size_t 
start, size_t length) {
+static DataTypePtr create_array(TypeIndex type, size_t num_dimensions) {
+    DataTypePtr result_type = 
make_nullable(DataTypeFactory::instance().create_data_type(type));
+    for (size_t i = 0; i < num_dimensions; ++i) {
+        result_type = 
make_nullable(std::make_shared<DataTypeArray>(result_type));
+    }
+    return result_type;
+}
+
+Array create_empty_array_field(size_t num_dimensions) {
+    if (num_dimensions == 0) {
+        throw doris::Exception(ErrorCode::INVALID_ARGUMENT,
+                               "Cannot create array field with 0 dimensions");
+    }
+
+    Array array;
+    Array* current_array = &array;
+    for (size_t i = 1; i < num_dimensions; ++i) {
+        current_array->push_back(Array());
+        current_array = &current_array->back().get<Array&>();
+    }
+
+    return array;
+}
+
+// Recreates column with default scalar values and keeps sizes of arrays.
+static ColumnPtr recreate_column_with_default_values(const ColumnPtr& column, 
TypeIndex scalar_type,
+                                                     size_t num_dimensions) {
+    const auto* column_array = 
check_and_get_column<ColumnArray>(remove_nullable(column).get());
+    if (column_array && num_dimensions) {
+        return make_nullable(ColumnArray::create(
+                
recreate_column_with_default_values(column_array->get_data_ptr(), scalar_type,
+                                                    num_dimensions - 1),
+                IColumn::mutate(column_array->get_offsets_ptr())));
+    }
+
+    return create_array(scalar_type, num_dimensions)
+            ->create_column()
+            ->clone_resized(column->size());
+}
+
+ColumnObject::Subcolumn ColumnObject::Subcolumn::recreate_with_default_values(
+        const FieldInfo& field_info) const {
+    Subcolumn new_subcolumn(*this);
+    new_subcolumn.least_common_type =
+            LeastCommonType {create_array(field_info.scalar_type_id, 
field_info.num_dimensions)};
+
+    for (int i = 0; i < new_subcolumn.data.size(); ++i) {
+        new_subcolumn.data[i] = recreate_column_with_default_values(
+                new_subcolumn.data[i], field_info.scalar_type_id, 
field_info.num_dimensions);
+        new_subcolumn.data_types[i] = 
create_array_of_type(field_info.scalar_type_id,
+                                                           
field_info.num_dimensions, is_nullable);
+    }
+
+    return new_subcolumn;
+}
+
+Field ColumnObject::Subcolumn::get_last_field() const {
+    if (data.empty()) {
+        return Field();
+    }
+
+    const auto& last_part = data.back();
+    assert(!last_part->empty());
+    return (*last_part)[last_part->size() - 1];
+}
+
+void ColumnObject::Subcolumn::insert_range_from(const Subcolumn& src, size_t 
start, size_t length) {

Review Comment:
   warning: function 'insert_range_from' exceeds recommended size/complexity 
thresholds [readability-function-size]
   ```cpp
   void ColumnObject::Subcolumn::insert_range_from(const Subcolumn& src, size_t 
start, size_t length) {
                                 ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/columns/column_object.cpp:524:** 85 lines including whitespace 
and comments (threshold 80)
   ```cpp
   void ColumnObject::Subcolumn::insert_range_from(const Subcolumn& src, size_t 
start, size_t length) {
                                 ^
   ```
   
   </details>
   



##########
be/src/vec/columns/column_object.cpp:
##########
@@ -1381,34 +1585,71 @@
     return Status::OK();
 }
 
-void ColumnObject::finalize_if_not() {
-    if (!is_finalized()) {
-        finalize();
-    }
-}
-
-void ColumnObject::finalize(bool ignore_sparse) {
+void ColumnObject::unnest(Subcolumns::NodePtr& entry, Subcolumns& subcolumns) 
const {
+    entry->data.finalize();
+    auto nested_column = 
entry->data.get_finalized_column_ptr()->assume_mutable();
+    auto* nested_column_nullable = 
assert_cast<ColumnNullable*>(nested_column.get());
+    auto* nested_column_array =
+            
assert_cast<ColumnArray*>(nested_column_nullable->get_nested_column_ptr().get());
+    auto& offset = nested_column_array->get_offsets_ptr();
+
+    auto* nested_object_nullable = assert_cast<ColumnNullable*>(
+            nested_column_array->get_data_ptr()->assume_mutable().get());
+    auto& nested_object_column =
+            
assert_cast<ColumnObject&>(nested_object_nullable->get_nested_column());
+    PathInData nested_path = entry->path;
+    for (auto& nested_entry : nested_object_column.subcolumns) {
+        if (nested_entry->data.least_common_type.get_base_type_id() == 
TypeIndex::Nothing) {
+            continue;
+        }
+        nested_entry->data.finalize();
+        PathInDataBuilder path_builder;
+        // format nested path
+        path_builder.append(nested_path.get_parts(), false);
+        path_builder.append(nested_entry->path.get_parts(), true);
+        auto subnested_column = ColumnArray::create(
+                
ColumnNullable::create(nested_entry->data.get_finalized_column_ptr(),
+                                       
nested_object_nullable->get_null_map_column_ptr()),
+                offset);
+        auto nullable_subnested_column = ColumnNullable::create(
+                subnested_column, 
nested_column_nullable->get_null_map_column_ptr());
+        auto type = make_nullable(
+                
std::make_shared<DataTypeArray>(nested_entry->data.least_common_type.get()));
+        Subcolumn subcolumn(nullable_subnested_column->assume_mutable(), type, 
is_nullable);
+        subcolumns.add(path_builder.build(), subcolumn);
+    }
+}
+
+void ColumnObject::finalize(FinalizeMode mode) {

Review Comment:
   warning: method 'finalize' can be made const 
[readability-make-member-function-const]
   
   be/src/vec/columns/column_object.h:345:
   ```diff
   -     void finalize(FinalizeMode mode);
   +     void finalize(FinalizeMode mode) const;
   ```
   
   ```suggestion
   void ColumnObject::finalize(FinalizeMode mode) const {
   ```
   



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