Add length() to Datum.

Convenience method for sub-type supporting the length method.
This commit is contained in:
François Saint-Jacques committed 2019-06-05 07:46:25 -04:00
1 parent cdedd85f9c
commit 53703acdd1
1 file changed
+14
+14
View File
@@ -201,6 +201,20 @@ struct ARROW_EXPORT Datum {
return NULLPTR;
}
/// \brief The value length of the variant, if any
///
/// \return -1 if no type
int64_t length() const {
if (this->kind() == Datum::ARRAY) {
return util::get<std::shared_ptr<ArrayData>>(this->value)->length;
} else if (this->kind() == Datum::CHUNKED_ARRAY) {
return util::get<std::shared_ptr<ChunkedArray>>(this->value)->length();
} else if (this->kind() == Datum::SCALAR) {
return 1;
}
return -1;
}
bool Equals(const Datum& other) const {
if (this->kind() != other.kind()) return false;