3333#include " arrow/memory_pool.h"
3434#include " arrow/table.h"
3535#include " arrow/testing/gtest_util.h"
36+ #include " arrow/testing/matchers.h"
3637#include " arrow/testing/random.h"
3738#include " arrow/testing/util.h"
3839#include " arrow/type.h"
3940#include " arrow/type_traits.h"
41+ #include " arrow/util/logging.h"
4042#include " arrow/util/checked_cast.h"
4143#include " arrow/util/key_value_metadata.h"
4244
@@ -50,6 +52,66 @@ TEST(TestTypeId, AllTypeIds) {
5052 ASSERT_EQ (static_cast <int >(all_ids.size ()), Type::MAX_ID );
5153}
5254
55+ TEST (TestTypeSingleton, ParameterFreeTypes) {
56+ // Test successful cases - parameter-free types
57+ std::vector<std::pair<Type::type, std::shared_ptr<DataType>>> cases = {
58+ {Type::NA , null ()},
59+ {Type::BOOL , boolean ()},
60+ {Type::INT8 , int8 ()},
61+ {Type::INT16 , int16 ()},
62+ {Type::INT32 , int32 ()},
63+ {Type::INT64 , int64 ()},
64+ {Type::UINT8 , uint8 ()},
65+ {Type::UINT16 , uint16 ()},
66+ {Type::UINT32 , uint32 ()},
67+ {Type::UINT64 , uint64 ()},
68+ {Type::HALF_FLOAT , float16 ()},
69+ {Type::FLOAT , float32 ()},
70+ {Type::DOUBLE , float64 ()},
71+ {Type::STRING , utf8 ()},
72+ {Type::BINARY , binary ()},
73+ {Type::LARGE_STRING , large_utf8 ()},
74+ {Type::LARGE_BINARY , large_binary ()},
75+ {Type::DATE32 , date32 ()},
76+ };
77+
78+ for (const auto & test_case : cases) {
79+ SCOPED_TRACE (" Testing type: " + std::to_string (static_cast <int >(test_case.first )));
80+ auto result = type_singleton (test_case.first );
81+ ASSERT_OK_AND_ASSIGN (auto type, result);
82+ ASSERT_TRUE (type->Equals (*test_case.second ))
83+ << " Failed on type " << test_case.first << " . Expected "
84+ << test_case.second ->ToString () << " but got " << type->ToString ();
85+ }
86+ }
87+
88+ TEST (TestTypeSingleton, ParameterizedTypes) {
89+ // Test error cases - parameterized types
90+ std::vector<Type::type> parameterized_types = {
91+ Type::TIMESTAMP , Type::TIME32 , Type::TIME64 ,
92+ Type::DURATION , Type::FIXED_SIZE_BINARY , Type::DECIMAL128 ,
93+ Type::LIST , Type::LARGE_LIST , Type::FIXED_SIZE_LIST ,
94+ Type::STRUCT , Type::DICTIONARY , Type::MAP ,
95+ Type::EXTENSION
96+ };
97+
98+ for (const auto type_id : parameterized_types) {
99+ SCOPED_TRACE (" Testing type: " + std::to_string (static_cast <int >(type_id)));
100+ auto result = type_singleton (type_id);
101+ ASSERT_FALSE (result.ok ());
102+ const auto & status = result.status ();
103+ EXPECT_THAT (status.message (), testing::HasSubstr (" is not a parameter-free singleton type" ));
104+ }
105+ }
106+
107+ TEST (TestTypeSingleton, InvalidType) {
108+ // Test with an invalid type ID
109+ auto result = type_singleton (static_cast <Type::type>(9999 ));
110+ ASSERT_FALSE (result.ok ());
111+ const auto & status = result.status ();
112+ EXPECT_THAT (status.message (), testing::HasSubstr (" requires parameters or is not supported" ));
113+ }
114+
53115template <typename ReprFunc>
54116void CheckTypeIdReprs (ReprFunc&& repr_func, bool expect_uppercase) {
55117 std::unordered_set<std::string> unique_reprs;
0 commit comments