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 152a95e4d KUDU-1261 Fix bug in wire_protocol.cc
152a95e4d is described below

commit 152a95e4d192da7e6b4d03483df11d6ff7c785b8
Author: Abhishek Chennaka <[email protected]>
AuthorDate: Thu Sep 18 16:01:32 2025 -0700

    KUDU-1261 Fix bug in wire_protocol.cc
    
    This patch sets the type attributes for Nested 1D Array Columns
    of types - DECIMAL and VARCHAR.
    
    Change-Id: I4ef6d8490c3452cb87c22eb48c70263853892d11
    Reviewed-on: http://gerrit.cloudera.org:8080/23441
    Tested-by: Alexey Serbin <[email protected]>
    Reviewed-by: Alexey Serbin <[email protected]>
---
 src/kudu/common/wire_protocol-test.cc | 52 +++++++++++++++++++++++++++++++++++
 src/kudu/common/wire_protocol.cc      | 13 +++++----
 2 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/src/kudu/common/wire_protocol-test.cc 
b/src/kudu/common/wire_protocol-test.cc
index a904f9c35..8b30b27c0 100644
--- a/src/kudu/common/wire_protocol-test.cc
+++ b/src/kudu/common/wire_protocol-test.cc
@@ -886,6 +886,58 @@ TEST_F(WireProtocolTest, ScalarArray1DToPB) {
   }
 }
 
+TEST_F(WireProtocolTest, ScalarArrayWithTypeAttributes1DToPB) {
+  // Column 1: DECIMAL(10,5) array
+  ColumnSchema dec_col(ColumnSchemaBuilder()
+                           .name("dec_col")
+                           .type(DECIMAL32)
+                           .type_attributes(ColumnTypeAttributes(10, 5))
+                           .array(true));
+
+  // Column 2: STRING(10) array
+  ColumnSchema str_col(ColumnSchemaBuilder()
+                           .name("str_col")
+                           .type(VARCHAR)
+                           .type_attributes(ColumnTypeAttributes(10))
+                           .array(true));
+
+  // Serialize both
+  ColumnSchemaPB dec_pb;
+  ColumnSchemaToPB(dec_col, &dec_pb);
+  ColumnSchemaPB str_pb;
+  ColumnSchemaToPB(str_col, &str_pb);
+
+  // Deserialize both
+  ColumnSchemaBuilder dec_bld;
+  ASSERT_OK(ColumnSchemaBuilderFromPB(dec_pb, &dec_bld));
+  ColumnSchema dec_col_fpb(dec_bld);
+
+  ColumnSchemaBuilder str_bld;
+  ASSERT_OK(ColumnSchemaBuilderFromPB(str_pb, &str_bld));
+  ColumnSchema str_col_fpb(str_bld);
+
+  // DECIMAL array column checks
+  ASSERT_TRUE(dec_col_fpb.is_array());
+  const auto* dec_type_info = dec_col_fpb.type_info();
+  ASSERT_EQ(DataType::NESTED, dec_col_fpb.type_info()->type());
+
+  const auto* dec_nested = dec_type_info->nested_type_info();
+  ASSERT_TRUE(dec_nested->is_array());
+  ASSERT_EQ(DataType::DECIMAL32, dec_nested->array().elem_type_info()->type());
+  ASSERT_EQ(10, dec_col_fpb.type_attributes().precision);
+  ASSERT_EQ(5, dec_col_fpb.type_attributes().scale);
+
+  // VARCHAR array column checks
+  ASSERT_TRUE(str_col_fpb.is_array());
+  const auto* str_type_info = str_col_fpb.type_info();
+  ASSERT_EQ(DataType::NESTED, str_type_info->type());
+
+  const auto* str_nested = str_type_info->nested_type_info();
+  ASSERT_TRUE(str_nested->is_array());
+  ASSERT_EQ(DataType::VARCHAR, str_nested->array().elem_type_info()->type());
+  ASSERT_EQ(10, str_col_fpb.type_attributes().length);
+}
+
 TEST_F(WireProtocolTest, NestedTypeValidityChecks) {
   {
     ColumnSchemaPB pb;
diff --git a/src/kudu/common/wire_protocol.cc b/src/kudu/common/wire_protocol.cc
index 1c8871f49..d84028120 100644
--- a/src/kudu/common/wire_protocol.cc
+++ b/src/kudu/common/wire_protocol.cc
@@ -235,6 +235,7 @@ void ColumnSchemaToPB(const ColumnSchema& col_schema, 
ColumnSchemaPB *pb, int fl
   const auto* type_info = col_schema.type_info();
   const DataType type = type_info->type();
   pb->set_type(type);
+  DataType elem_type = type;
   // Set information on the nested type, if necessary.
   if (type == DataType::NESTED) {
     const auto* nested_type_info = type_info->nested_type_info();
@@ -242,16 +243,16 @@ void ColumnSchemaToPB(const ColumnSchema& col_schema, 
ColumnSchemaPB *pb, int fl
     // Only arrays are supported yet.
     DCHECK(nested_type_info->is_array());
     const auto& array_info = nested_type_info->array();
-    pb->mutable_nested_type()->mutable_array()->set_type(
-        array_info.elem_type_info()->type());
+    elem_type = array_info.elem_type_info()->type();
+    pb->mutable_nested_type()->mutable_array()->set_type(elem_type);
   }
   // Only serialize precision and scale for decimal types.
-  if (type == DataType::DECIMAL32 ||
-      type == DataType::DECIMAL64 ||
-      type == DataType::DECIMAL128) {
+  if (elem_type == DataType::DECIMAL32 ||
+      elem_type == DataType::DECIMAL64 ||
+      elem_type == DataType::DECIMAL128) {
     
pb->mutable_type_attributes()->set_precision(col_schema.type_attributes().precision);
     
pb->mutable_type_attributes()->set_scale(col_schema.type_attributes().scale);
-  } else if (type == DataType::VARCHAR) {
+  } else if (elem_type == DataType::VARCHAR) {
     
pb->mutable_type_attributes()->set_length(col_schema.type_attributes().length);
   }
   if (!(flags & SCHEMA_PB_WITHOUT_STORAGE_ATTRIBUTES)) {

Reply via email to