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