This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new 2c393e55f13 branch-4.1: [fix](function) Preserve NUL bytes in
count-by-enum keys #67984 (#68419)
2c393e55f13 is described below
commit 2c393e55f131fda4800e13503034b2f48eb12c39
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 24 09:23:35 2026 +0800
branch-4.1: [fix](function) Preserve NUL bytes in count-by-enum keys #67984
(#68419)
Cherry-picked from #67984
Co-authored-by: Mryange <[email protected]>
---
.../aggregate/aggregate_function_count_by_enum.h | 3 +-
be/test/exprs/aggregate/vec_count_by_enum_test.cpp | 48 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/be/src/exprs/aggregate/aggregate_function_count_by_enum.h
b/be/src/exprs/aggregate/aggregate_function_count_by_enum.h
index 40bccd7e5fc..77e220473d9 100644
--- a/be/src/exprs/aggregate/aggregate_function_count_by_enum.h
+++ b/be/src/exprs/aggregate/aggregate_function_count_by_enum.h
@@ -49,7 +49,8 @@ void build_json_from_vec(rapidjson::StringBuffer& buffer,
rapidjson::Value obj_cbe(rapidjson::kObjectType);
std::unordered_map<std::string, uint64_t> unordered_map =
data_vec[idx].cbe;
for (auto it : unordered_map) {
- rapidjson::Value key_cbe(it.first.c_str(), allocator);
+ rapidjson::Value key_cbe(it.first.data(),
+
static_cast<rapidjson::SizeType>(it.first.size()), allocator);
rapidjson::Value value_cbe(it.second);
obj_cbe.AddMember(key_cbe, value_cbe, allocator);
}
diff --git a/be/test/exprs/aggregate/vec_count_by_enum_test.cpp
b/be/test/exprs/aggregate/vec_count_by_enum_test.cpp
index cbb9a5888d6..f57d2203e61 100644
--- a/be/test/exprs/aggregate/vec_count_by_enum_test.cpp
+++ b/be/test/exprs/aggregate/vec_count_by_enum_test.cpp
@@ -142,6 +142,54 @@ TEST_F(VCountByEnumTest, testNotNullableSample) {
agg_function->destroy(place2);
}
+TEST_F(VCountByEnumTest, testNulInStringKey) {
+ Arena arena;
+ auto column = ColumnString::create();
+ column->insert_data("A\0B", 3);
+ column->insert_data("A", 1);
+
+ std::unique_ptr<char[]> memory(new char[agg_function->size_of_data()]);
+ AggregateDataPtr place = memory.get();
+ agg_function->create(place);
+ const IColumn* columns[1] = {column.get()};
+ agg_function->add(place, columns, 0, arena);
+ agg_function->add(place, columns, 1, arena);
+
+ auto result_column = std::make_shared<DataTypeString>()->create_column();
+ agg_function->insert_result_into(place, *result_column);
+ auto& result = assert_cast<ColumnString&>(*result_column);
+
+ rapidjson::Document document;
+ document.Parse(result.get_data_at(0).to_string().c_str());
+ ASSERT_TRUE(document.IsArray());
+ ASSERT_EQ(document.Size(), 1);
+ const rapidjson::Value& cbe = document[0]["cbe"];
+ ASSERT_TRUE(cbe.IsObject());
+ ASSERT_EQ(cbe.MemberCount(), 2);
+
+ bool found_nul_key = false;
+ bool found_plain_key = false;
+ for (auto member = cbe.MemberBegin(); member != cbe.MemberEnd(); ++member)
{
+ if (member->name.GetStringLength() == 3 && member->name.GetString()[1]
== '\0') {
+ found_nul_key = true;
+ EXPECT_EQ(std::string(member->name.GetString(),
member->name.GetStringLength()),
+ std::string("A\0B", 3));
+ EXPECT_EQ(member->value.GetInt(), 1);
+ } else if (member->name.GetStringLength() == 1) {
+ found_plain_key = true;
+ EXPECT_EQ(member->name.GetString()[0], 'A');
+ EXPECT_EQ(member->value.GetInt(), 1);
+ }
+ }
+ EXPECT_TRUE(found_nul_key);
+ EXPECT_TRUE(found_plain_key);
+ EXPECT_EQ(document[0]["notnull"].GetInt(), 2);
+ EXPECT_EQ(document[0]["null"].GetInt(), 0);
+ EXPECT_EQ(document[0]["all"].GetInt(), 2);
+
+ agg_function->destroy(place);
+}
+
TEST_F(VCountByEnumTest, testNullableSample) {
Arena arena;
const int batch_size = 5;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]