Implementation of Scalar::Validate() and Scalar::ValidateFull()
| 240 | |
| 241 | // Implementation of Scalar::Validate() and Scalar::ValidateFull() |
| 242 | struct ScalarValidateImpl { |
| 243 | const bool full_validation_; |
| 244 | |
| 245 | explicit ScalarValidateImpl(bool full_validation) : full_validation_(full_validation) { |
| 246 | ::arrow::util::InitializeUTF8(); |
| 247 | } |
| 248 | |
| 249 | Status Validate(const Scalar& scalar) { |
| 250 | if (!scalar.type) { |
| 251 | return Status::Invalid("scalar lacks a type"); |
| 252 | } |
| 253 | return VisitScalarInline(scalar, this); |
| 254 | } |
| 255 | |
| 256 | Status Visit(const NullScalar& s) { |
| 257 | if (s.is_valid) { |
| 258 | return Status::Invalid("null scalar should have is_valid = false"); |
| 259 | } |
| 260 | return Status::OK(); |
| 261 | } |
| 262 | |
| 263 | template <typename T> |
| 264 | Status Visit(const internal::PrimitiveScalar<T>& s) { |
| 265 | return Status::OK(); |
| 266 | } |
| 267 | |
| 268 | Status Visit(const BaseBinaryScalar& s) { return ValidateBinaryScalar(s); } |
| 269 | |
| 270 | Status Visit(const StringScalar& s) { return ValidateStringScalar(s); } |
| 271 | |
| 272 | Status Visit(const BinaryViewScalar& s) { return ValidateBinaryScalar(s); } |
| 273 | |
| 274 | Status Visit(const StringViewScalar& s) { return ValidateStringScalar(s); } |
| 275 | |
| 276 | Status Visit(const LargeBinaryScalar& s) { return ValidateBinaryScalar(s); } |
| 277 | |
| 278 | Status Visit(const LargeStringScalar& s) { return ValidateStringScalar(s); } |
| 279 | |
| 280 | template <typename ScalarType> |
| 281 | Status CheckValueNotNull(const ScalarType& s) { |
| 282 | if (!s.value) { |
| 283 | return Status::Invalid(s.type->ToString(), " value is null"); |
| 284 | } |
| 285 | return Status::OK(); |
| 286 | } |
| 287 | |
| 288 | Status Visit(const FixedSizeBinaryScalar& s) { |
| 289 | const auto& byte_width = |
| 290 | checked_cast<const FixedSizeBinaryType&>(*s.type).byte_width(); |
| 291 | RETURN_NOT_OK(CheckValueNotNull(s)); |
| 292 | if (s.value->size() != byte_width) { |
| 293 | return Status::Invalid(s.type->ToString(), " scalar should have a value of size ", |
| 294 | byte_width, ", got ", s.value->size()); |
| 295 | } |
| 296 | return Status::OK(); |
| 297 | } |
| 298 | |
| 299 | Status Visit(const Decimal32Scalar& s) { |
no outgoing calls
no test coverage detected