This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new d908d6617 KUDU-1261: move Serialize into kudu::serdes namespace
d908d6617 is described below
commit d908d6617368c02b36fff4136eb56fd32e5b0e8f
Author: Alexey Serbin <[email protected]>
AuthorDate: Thu Oct 2 13:57:13 2025 -0700
KUDU-1261: move Serialize into kudu::serdes namespace
This patch moves all the serialization methods from array_type_serdes.h
into the 'kudu::serdes' namespace. They were in the 'kudu' namespace
before.
Also, there is an update in ArrayDataGenerator::Build() to reflect on
various representations of 'empty' Slice instances that might be used
as serialized form of an empty or null array cell. The code in
ArrayCellMetadataView::Init() has been updated accordingly.
Change-Id: Ic0fe86c2ff7a9ed0839ac3d9008295d3901b209f
Reviewed-on: http://gerrit.cloudera.org:8080/23486
Reviewed-by: Abhishek Chennaka <[email protected]>
Tested-by: Alexey Serbin <[email protected]>
---
src/kudu/cfile/cfile-test-base.h | 13 +++++++++++--
src/kudu/cfile/cfile_reader.cc | 2 +-
src/kudu/common/array_cell_view.h | 4 ++--
src/kudu/common/array_type_serdes-test.cc | 14 +++++++-------
src/kudu/common/array_type_serdes.h | 2 ++
src/kudu/common/partial_row.cc | 1 +
src/kudu/common/types-test.cc | 1 +
7 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/kudu/cfile/cfile-test-base.h b/src/kudu/cfile/cfile-test-base.h
index cc637a115..c4387bef5 100644
--- a/src/kudu/cfile/cfile-test-base.h
+++ b/src/kudu/cfile/cfile-test-base.h
@@ -432,7 +432,16 @@ class ArrayDataGenerator {
values_vector_[i].clear();
values_vector_str_[i].clear();
- array_cells_[i] = Slice(static_cast<uint8_t*>(nullptr), 0);
+#if DCHECK_IS_ON()
+ // As an extra provision to catch mistakes in debug builds, supply
+ // null pointers for empty (i.e. zero-sized) Slices instances.
+ // For an empty Slice, the code shouldn't try dereferencing its data
+ // pointer, and that would be a mistake doing otherwise.
+ array_cells_[i] = (i % 2 == 0) ? Slice(static_cast<uint8_t*>(nullptr),
0)
+ : Slice();
+#else
+ array_cells_[i] = Slice();
+#endif
} else {
// Helper container for flatbuffer's serialization.
std::vector<bool> validity_src(array_elem_num, false);
@@ -488,7 +497,7 @@ class ArrayDataGenerator {
}
size_t buf_size = 0;
- const auto s = Serialize<DATA_TYPE, FB_TYPE>(
+ const auto s = serdes::Serialize<DATA_TYPE, FB_TYPE>(
reinterpret_cast<uint8_t*>(values_vector_[i].data()),
array_elem_num,
validity_src,
diff --git a/src/kudu/cfile/cfile_reader.cc b/src/kudu/cfile/cfile_reader.cc
index 9fde2219f..2ca327cf5 100644
--- a/src/kudu/cfile/cfile_reader.cc
+++ b/src/kudu/cfile/cfile_reader.cc
@@ -1372,7 +1372,7 @@ Status CFileIterator::Scan(ColumnMaterializationContext*
ctx) {
// Serialize the read data into dst->arena().
Slice cell_out;
- RETURN_NOT_OK(SerializeIntoArena(
+ RETURN_NOT_OK(serdes::SerializeIntoArena(
elem_type_info,
cblock_data.get(),
cblock_not_null_bitmap.get(),
diff --git a/src/kudu/common/array_cell_view.h
b/src/kudu/common/array_cell_view.h
index 06c7ae369..96d1c7ccc 100644
--- a/src/kudu/common/array_cell_view.h
+++ b/src/kudu/common/array_cell_view.h
@@ -94,13 +94,13 @@ class ArrayCellMetadataView final {
Status Init() {
DCHECK(!is_initialized_);
if (size_ == 0) {
- DCHECK(!data_);
content_ = nullptr;
is_initialized_ = true;
return Status::OK();
}
DCHECK_GT(size_, 0);
+ DCHECK(data_);
{
flatbuffers::Verifier::Options opt;
// While verifying the input data, rely on the built-in constant of
@@ -257,7 +257,7 @@ class ArrayCellMetadataView final {
}
// Flatbuffer-encoded data; a non-owning raw pointer.
- const uint8_t* data_;
+ const uint8_t* const data_;
// Size of the encoded data, i.e. the number of bytes in the memory after
// the 'data_' pointer that represent the serialized array.
diff --git a/src/kudu/common/array_type_serdes-test.cc
b/src/kudu/common/array_type_serdes-test.cc
index be180b9a6..34de4c064 100644
--- a/src/kudu/common/array_type_serdes-test.cc
+++ b/src/kudu/common/array_type_serdes-test.cc
@@ -50,18 +50,18 @@ TEST(ArrayTypeSerdesTest, Basic) {
unique_ptr<uint8_t[]> buf_data;
size_t buf_data_size = 0;
- ASSERT_OK(Serialize(GetTypeInfo(INT32),
- reinterpret_cast<const uint8_t*>(val.data()),
- val.size(),
- validity_vector,
- &buf_data,
- &buf_data_size));
+ ASSERT_OK(serdes::Serialize(GetTypeInfo(INT32),
+ reinterpret_cast<const uint8_t*>(val.data()),
+ val.size(),
+ validity_vector,
+ &buf_data,
+ &buf_data_size));
ASSERT_TRUE(buf_data);
const Slice cell(buf_data.get(), buf_data_size);
Arena arena(128);
Slice arena_cell;
- ASSERT_OK(SerializeIntoArena(
+ ASSERT_OK(serdes::SerializeIntoArena(
GetTypeInfo(INT32),
reinterpret_cast<const uint8_t*>(val.data()),
validity_bitmap,
diff --git a/src/kudu/common/array_type_serdes.h
b/src/kudu/common/array_type_serdes.h
index a6b5a8b8f..7e8890925 100644
--- a/src/kudu/common/array_type_serdes.h
+++ b/src/kudu/common/array_type_serdes.h
@@ -34,6 +34,7 @@
#include "kudu/util/status.h"
namespace kudu {
+namespace serdes {
template<DataType KUDU_DATA_TYPE, typename FB_TYPE>
void BuildFlatbuffers(
@@ -281,4 +282,5 @@ inline Status SerializeIntoArena(
}
}
+} // namespace serdes
} // namespace kudu
diff --git a/src/kudu/common/partial_row.cc b/src/kudu/common/partial_row.cc
index 19ce63bbb..1d6ef0f8d 100644
--- a/src/kudu/common/partial_row.cc
+++ b/src/kudu/common/partial_row.cc
@@ -47,6 +47,7 @@
#endif
#include "kudu/util/status.h"
+using kudu::serdes::Serialize;
using std::string;
using std::vector;
using strings::Substitute;
diff --git a/src/kudu/common/types-test.cc b/src/kudu/common/types-test.cc
index 0edff6680..09847e3cf 100644
--- a/src/kudu/common/types-test.cc
+++ b/src/kudu/common/types-test.cc
@@ -41,6 +41,7 @@
#include "kudu/util/test_macros.h"
#include "kudu/util/test_util.h"
+using kudu::serdes::Serialize;
using std::get;
using std::make_tuple;
using std::nextafter;