Skip to content

Commit f0688d0

Browse files
rtpswpitrou
andauthored
ARROW-17289: [C++] Add type category membership checks (#13783)
See https://issues.apache.org/jira/browse/ARROW-17289 Lead-authored-by: Yaron Gvili <[email protected]> Co-authored-by: rtpsw <[email protected]> Co-authored-by: Antoine Pitrou <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent cef6894 commit f0688d0

3 files changed

Lines changed: 438 additions & 45 deletions

File tree

‎cpp/src/arrow/type.h‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,31 +2123,37 @@ std::string ToString(TimeUnit::type unit);
21232123

21242124
// Helpers to get instances of data types based on general categories
21252125

2126+
/// \brief Signed integer types
21262127
ARROW_EXPORT
21272128
const std::vector<std::shared_ptr<DataType>>& SignedIntTypes();
2129+
/// \brief Unsigned integer types
21282130
ARROW_EXPORT
21292131
const std::vector<std::shared_ptr<DataType>>& UnsignedIntTypes();
2132+
/// \brief Signed and unsigned integer types
21302133
ARROW_EXPORT
21312134
const std::vector<std::shared_ptr<DataType>>& IntTypes();
2135+
/// \brief Floating point types
21322136
ARROW_EXPORT
21332137
const std::vector<std::shared_ptr<DataType>>& FloatingPointTypes();
2134-
// Number types without boolean
2138+
/// \brief Number types without boolean - integer and floating point types
21352139
ARROW_EXPORT
21362140
const std::vector<std::shared_ptr<DataType>>& NumericTypes();
2137-
// Binary and string-like types (except fixed-size binary)
2141+
/// \brief Binary and string-like types (except fixed-size binary)
21382142
ARROW_EXPORT
21392143
const std::vector<std::shared_ptr<DataType>>& BaseBinaryTypes();
2144+
/// \brief Binary and large-binary types
21402145
ARROW_EXPORT
21412146
const std::vector<std::shared_ptr<DataType>>& BinaryTypes();
2147+
/// \brief String and large-string types
21422148
ARROW_EXPORT
21432149
const std::vector<std::shared_ptr<DataType>>& StringTypes();
2144-
// Temporal types including time and timestamps for each unit
2150+
/// \brief Temporal types including date, time and timestamps for each unit
21452151
ARROW_EXPORT
21462152
const std::vector<std::shared_ptr<DataType>>& TemporalTypes();
2147-
// Interval types
2153+
/// \brief Interval types
21482154
ARROW_EXPORT
21492155
const std::vector<std::shared_ptr<DataType>>& IntervalTypes();
2150-
// Integer, floating point, base binary, and temporal
2156+
/// \brief Numeric, base binary, date, boolean and null types
21512157
ARROW_EXPORT
21522158
const std::vector<std::shared_ptr<DataType>>& PrimitiveTypes();
21532159

‎cpp/src/arrow/type_test.cc‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,4 +1821,47 @@ TEST(TypesTest, TestDecimalEquals) {
18211821
AssertTypeNotEqual(t5, t10);
18221822
}
18231823

1824+
#define TEST_PREDICATE(all_types, type_predicate) \
1825+
for (auto type : all_types) { \
1826+
ASSERT_EQ(type_predicate(type->id()), type_predicate(*type)); \
1827+
}
1828+
1829+
TEST(TypesTest, TestMembership) {
1830+
std::vector<std::shared_ptr<DataType>> all_types;
1831+
for (auto type : NumericTypes()) {
1832+
all_types.push_back(type);
1833+
}
1834+
for (auto type : TemporalTypes()) {
1835+
all_types.push_back(type);
1836+
}
1837+
for (auto type : IntervalTypes()) {
1838+
all_types.push_back(type);
1839+
}
1840+
for (auto type : PrimitiveTypes()) {
1841+
all_types.push_back(type);
1842+
}
1843+
TEST_PREDICATE(all_types, is_integer);
1844+
TEST_PREDICATE(all_types, is_signed_integer);
1845+
TEST_PREDICATE(all_types, is_unsigned_integer);
1846+
TEST_PREDICATE(all_types, is_floating);
1847+
TEST_PREDICATE(all_types, is_numeric);
1848+
TEST_PREDICATE(all_types, is_decimal);
1849+
TEST_PREDICATE(all_types, is_primitive);
1850+
TEST_PREDICATE(all_types, is_base_binary_like);
1851+
TEST_PREDICATE(all_types, is_binary_like);
1852+
TEST_PREDICATE(all_types, is_large_binary_like);
1853+
TEST_PREDICATE(all_types, is_binary);
1854+
TEST_PREDICATE(all_types, is_string);
1855+
TEST_PREDICATE(all_types, is_temporal);
1856+
TEST_PREDICATE(all_types, is_interval);
1857+
TEST_PREDICATE(all_types, is_dictionary);
1858+
TEST_PREDICATE(all_types, is_fixed_size_binary);
1859+
TEST_PREDICATE(all_types, is_fixed_width);
1860+
TEST_PREDICATE(all_types, is_list_like);
1861+
TEST_PREDICATE(all_types, is_nested);
1862+
TEST_PREDICATE(all_types, is_union);
1863+
}
1864+
1865+
#undef TEST_PREDICATE
1866+
18241867
} // namespace arrow

0 commit comments

Comments
 (0)