| 465 | } |
| 466 | |
| 467 | Status ValidateSparseUnion(const SparseUnionScalar& s) { |
| 468 | const auto& union_type = checked_cast<const SparseUnionType&>(*s.type); |
| 469 | if (union_type.num_fields() != static_cast<int>(s.value.size())) { |
| 470 | return Status::Invalid("Sparse union scalar value had ", union_type.num_fields(), |
| 471 | " fields but type has ", s.value.size(), " fields."); |
| 472 | } |
| 473 | for (int j = 0; j < union_type.num_fields(); ++j) { |
| 474 | const auto& field_type = *union_type.field(j)->type(); |
| 475 | const Scalar& field_value = *s.value[j]; |
| 476 | if (!field_type.Equals(*field_value.type)) { |
| 477 | return Status::Invalid(s.type->ToString(), " value for field ", |
| 478 | union_type.field(j)->ToString(), " had incorrect type of ", |
| 479 | field_value.type->ToString()); |
| 480 | } |
| 481 | RETURN_NOT_OK(ValidateValue(s, field_value)); |
| 482 | } |
| 483 | return Status::OK(); |
| 484 | } |
| 485 | |
| 486 | Status Visit(const UnionScalar& s) { |
| 487 | const int type_code = s.type_code; // avoid 8-bit int types for printing |