Skip to content

Commit

Permalink
Fix the bug that cloneFullColumn does not clone the subcolumns at t…
Browse files Browse the repository at this point in the history
…he second and higher levels (#9606) (#9607)

close #9605

Fix the bug that `cloneFullColumn` does not clone the subcolumns at the second and higher levels

Signed-off-by: gengliqi <gengliqiii@gmail.com>

Co-authored-by: gengliqi <gengliqiii@gmail.com>
  • Loading branch information
ti-chi-bot and gengliqi authored Nov 13, 2024
1 parent 0849d94 commit d346b92
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbms/src/Columns/IColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class IColumn : public COWPtr<IColumn>
MutablePtr cloneFullColumn() const
{
MutablePtr res = clone();
res->forEachSubcolumn([](Ptr & subcolumn) { subcolumn = subcolumn->clone(); });
res->forEachSubcolumn([](Ptr & subcolumn) { subcolumn = subcolumn->cloneFullColumn(); });
return res;
}

Expand Down
74 changes: 74 additions & 0 deletions dbms/src/Columns/tests/gtest_column_misc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2024 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <TestUtils/FunctionTestUtils.h>
#include <TestUtils/TiFlashTestBasic.h>

#include "Functions/FunctionHelpers.h"

namespace DB
{
namespace tests
{
class TestColumnMisc : public ::testing::Test
{
public:
static void testCloneFullColumn(const ColumnPtr & column_ptr)
{
auto col_ptr_str = column_ptr->dumpStructure();
ColumnPtr col_ptr_clone = column_ptr->cloneFullColumn();
ASSERT_COLUMN_EQ(column_ptr, col_ptr_clone);
Field x;
col_ptr_clone->get(0, x);
col_ptr_clone->assumeMutable()->insert(x);
// Test whether the clone is the deep copy, i.e the original column does not changed
ASSERT_EQ(col_ptr_str, column_ptr->dumpStructure());

auto col_nullmap = ColumnUInt8::create();
for (size_t i = 0; i < col_ptr_clone->size(); ++i)
col_nullmap->insert(FIELD_INT8_1);
ColumnPtr col_nullable = ColumnNullable::create(col_ptr_clone, std::move(col_nullmap));
auto col_nullable_str = col_nullable->dumpStructure();
ColumnPtr col_nullable_clone = col_nullable->cloneFullColumn();
ASSERT_COLUMN_EQ(col_nullable, col_nullable_clone);
col_nullable_clone->get(0, x);
col_nullable_clone->assumeMutable()->insert(x);
// Test whether the clone is the deep copy, i.e the original column does not changed
ASSERT_EQ(col_nullable_str, col_nullable->dumpStructure());
}
};

TEST_F(TestColumnMisc, TestCloneFullColumn)
try
{
auto col_vector = createColumn<UInt32>({1, 2, 3}).column;
testCloneFullColumn(col_vector);
auto col_decimal = createColumn<Decimal128>(std::make_tuple(10, 3), {"1234567.333"}).column;
testCloneFullColumn(col_decimal);
auto col_string = createColumn<String>({"sdafyuwer123"}).column;
testCloneFullColumn(col_string);
auto col_array = createColumn<Array>(
std::make_tuple(std::make_shared<DataTypeFloat32>()), //
{Array{}, Array{1.0, 2.0}, Array{1.0, 2.0, 3.0}})
.column;
testCloneFullColumn(col_array);
ColumnPtr col_fixed_string = ColumnFixedString::create(2);
col_fixed_string->assumeMutable()->insertData("12", 2);
testCloneFullColumn(col_fixed_string);
}
CATCH


} // namespace tests
} // namespace DB

0 comments on commit d346b92

Please sign in to comment.