Skip to content

Commit

Permalink
fix serialize with root
Browse files Browse the repository at this point in the history
  • Loading branch information
eldenmoon committed Dec 20, 2024
1 parent c15122c commit 3015d5c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 22 additions & 1 deletion be/src/vec/columns/column_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1836,8 +1836,25 @@ struct Prefix {
bool root_is_first_flag = true;
};

bool ColumnObject::is_visible_root_value(size_t nrow) const {
if (is_null_root()) {
return false;
}
const auto& nullable = assert_cast<const ColumnNullable&>(*get_root());
if (nullable.is_null_at(nrow)) {
return false;
}
const auto& value_column = assert_cast<const ColumnString&>(nullable.get_nested_column());
return !value_column.get_data_at(nrow).empty();
}

Status ColumnObject::serialize_one_row_to_json_format(int64_t row_num, BufferWritable& output,
bool* is_null) const {
// root is not eighther null or empty, we should only process root value
if (is_visible_root_value(row_num)) {
subcolumns.get_root()->data.serialize_text_json(row_num, output);
return Status::OK();
}
const auto& column_map = assert_cast<const ColumnMap&>(*serialized_sparse_column);
const auto& sparse_data_offsets = column_map.get_offsets();
const auto [sparse_data_paths, sparse_data_values] = get_sparse_data_paths_and_values();
Expand All @@ -1850,9 +1867,13 @@ Status ColumnObject::serialize_one_row_to_json_format(int64_t row_num, BufferWri
// For example:
// b.c, a.b, a.a, b.e, g, h.u.t -> a.a, a.b, b.c, b.e, g, h.u.t -> {"a" : {"a" : ..., "b" : ...}, "b" : {"c" : ..., "e" : ...}, "g" : ..., "h" : {"u" : {"t" : ...}}}.
std::vector<String> sorted_paths;
std::map<std::string, Subcolumn> subcolumn_path_map;
std::unordered_map<std::string, Subcolumn> subcolumn_path_map;
sorted_paths.reserve(get_subcolumns().size() + (sparse_data_end - sparse_data_offset));
for (const auto& subcolumn : get_subcolumns()) {
// Skip root value, we have already processed it
if (subcolumn->data.is_root) {
continue;
}
/// We consider null value and absence of the path in a row as equivalent cases, because we cannot actually distinguish them.
/// So, we don't output null values at all.
if (!subcolumn->data.is_null_at(row_num)) {
Expand Down
2 changes: 2 additions & 0 deletions be/src/vec/columns/column_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,8 @@ class ColumnObject final : public COWHelper<IColumn, ColumnObject> {
size_t start, size_t length);

bool try_add_new_subcolumn(const PathInData& path);

bool is_visible_root_value(size_t nrow) const;
};

} // namespace doris::vectorized

0 comments on commit 3015d5c

Please sign in to comment.