Skip to content

Commit

Permalink
[pick](Serde-2.1) fix variant serde may lost num_rows when subcolumns…
Browse files Browse the repository at this point in the history
… empty (apache#38413)

serialization object with empty subcolumns may lost num_rows, so need
to record num_rows and set back num_rows in serdes

backport apache#38413
  • Loading branch information
eldenmoon committed Sep 28, 2024
1 parent 9a9226e commit dc3b728
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
3 changes: 2 additions & 1 deletion be/src/agent/be_exec_version_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ class BeExecVersionManager {
* g. do local merge of remote runtime filter
* h. "now": ALWAYS_NOT_NULLABLE -> DEPEND_ON_ARGUMENTS
*/
constexpr inline int BeExecVersionManager::max_be_exec_version = 5;
constexpr inline int BeExecVersionManager::max_be_exec_version = 6;
constexpr inline int BeExecVersionManager::min_be_exec_version = 0;

/// functional
constexpr inline int BITMAP_SERDE = 3;
constexpr inline int USE_NEW_SERDE = 4; // release on DORIS version 2.1
constexpr inline int OLD_WAL_SERDE = 3; // use to solve compatibility issues, see pr #32299
constexpr inline int VARIANT_SERDE = 6; // change variant serde to fix PR #38413

} // namespace doris
18 changes: 17 additions & 1 deletion be/src/vec/data_types/data_type_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <utility>
#include <vector>

#include "agent/be_exec_version_manager.h"
#include "vec/columns/column_object.h"
#include "vec/common/assert_cast.h"
#include "vec/common/typeid_cast.h"
Expand Down Expand Up @@ -66,7 +67,6 @@ int64_t DataTypeObject::get_uncompressed_serialized_bytes(const IColumn& column,
if (is_nothing(type)) {
continue;
}

PColumnMeta column_meta_pb;
column_meta_pb.set_name(entry->path.get_path());
type->to_pb_column_meta(&column_meta_pb);
Expand All @@ -78,6 +78,10 @@ int64_t DataTypeObject::get_uncompressed_serialized_bytes(const IColumn& column,
size += type->get_uncompressed_serialized_bytes(entry->data.get_finalized_column(),
be_exec_version);
}
// serialize num of rows, only take effect when subcolumns empty
if (be_exec_version >= VARIANT_SERDE) {
size += sizeof(uint32_t);
}

return size;
}
Expand Down Expand Up @@ -121,6 +125,11 @@ char* DataTypeObject::serialize(const IColumn& column, char* buf, int be_exec_ve
}
// serialize num of subcolumns
*reinterpret_cast<uint32_t*>(size_pos) = num_of_columns;
// serialize num of rows, only take effect when subcolumns empty
if (be_exec_version >= VARIANT_SERDE) {
*reinterpret_cast<uint32_t*>(buf) = column_object.rows();
buf += sizeof(uint32_t);
}

return buf;
}
Expand Down Expand Up @@ -155,6 +164,13 @@ const char* DataTypeObject::deserialize(const char* buf, IColumn* column,
}
column_object->add_sub_column(key, std::move(sub_column), type);
}
size_t num_rows = 0;
// serialize num of rows, only take effect when subcolumns empty
if (be_exec_version >= VARIANT_SERDE) {
num_rows = *reinterpret_cast<const uint32_t*>(buf);
column_object->set_num_rows(num_rows);
buf += sizeof(uint32_t);
}

column_object->finalize();
#ifndef NDEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,7 @@ public class Config extends ConfigBase {
* Max data version of backends serialize block.
*/
@ConfField(mutable = false)
public static int max_be_exec_version = 5;
public static int max_be_exec_version = 6;

/**
* Min data version of backends serialize block.
Expand Down
67 changes: 67 additions & 0 deletions regression-test/data/variant_p0/rqg/rqg5.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !rqg5 --
0

-- !rqg5_2 --
50

-- !rqg5_3 --
50

-- !rqg5_4 --
50

-- !rqg5_5 --
50

-- !rqg5_6 --
50

-- !rqg5_7 --
0

-- !rqg5_8 --
0

-- !rqg5_9 --
50

-- !rqg5_10 --
50

-- !rqg5_11 --
50

-- !rqg5_12 --
50

-- !rqg5_13 --
50

-- !rqg5_14 --
50

-- !rqg5_15 --
0

-- !rqg5_16 --
100

-- !rqg5_17 --
100

-- !rqg5_18 --
100

-- !rqg5_19 --
100

-- !rqg5_20 --
100

-- !rqg5_21 --
100

-- !rqg5_22 --
0

22 changes: 22 additions & 0 deletions regression-test/suites/variant_p0/rqg/rqg5.sql

Large diffs are not rendered by default.

0 comments on commit dc3b728

Please sign in to comment.