From 6e122dd5cefc0153ad15d702353197cedb61ae8e Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Tue, 23 Apr 2024 11:32:55 -0300 Subject: [PATCH 1/2] Add bit/byte_width checks to extension_type_test.cc --- cpp/src/arrow/extension_type_test.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpp/src/arrow/extension_type_test.cc b/cpp/src/arrow/extension_type_test.cc index 31222d74806..f104c984a64 100644 --- a/cpp/src/arrow/extension_type_test.cc +++ b/cpp/src/arrow/extension_type_test.cc @@ -196,6 +196,8 @@ TEST_F(TestExtensionType, ExtensionTypeTest) { auto type = uuid(); ASSERT_EQ(type->id(), Type::EXTENSION); + ASSERT_EQ(type->bit_width(), 128); + ASSERT_EQ(type->byte_width(), 16); const auto& ext_type = static_cast(*type); std::string serialized = ext_type.Serialize(); @@ -204,6 +206,9 @@ TEST_F(TestExtensionType, ExtensionTypeTest) { ext_type.Deserialize(fixed_size_binary(16), serialized)); ASSERT_TRUE(deserialized->Equals(*type)); ASSERT_FALSE(deserialized->Equals(*fixed_size_binary(16))); + ASSERT_EQ(deserialized->id(), Type::EXTENSION); + ASSERT_EQ(deserialized->bit_width(), 128); + ASSERT_EQ(deserialized->byte_width(), 16); } auto RoundtripBatch = [](const std::shared_ptr& batch, From 044fc968f25266c1637df2ae6cc8e5a11b72b0ec Mon Sep 17 00:00:00 2001 From: Felipe Oliveira Carvalho Date: Tue, 23 Apr 2024 10:56:09 -0300 Subject: [PATCH 2/2] Define ExtensionType::bit_width() as the storage type's bit-width by default --- cpp/src/arrow/extension_type.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cpp/src/arrow/extension_type.h b/cpp/src/arrow/extension_type.h index 0fd7216f182..b3f085198be 100644 --- a/cpp/src/arrow/extension_type.h +++ b/cpp/src/arrow/extension_type.h @@ -54,6 +54,9 @@ class ARROW_EXPORT ExtensionType : public DataType { std::string name() const override { return "extension"; } + int32_t byte_width() const override { return storage_type_->byte_width(); } + int bit_width() const override { return storage_type_->bit_width(); } + /// \brief Unique name of extension type used to identify type for /// serialization /// \return the string name of the extension