If the index is out of bounds, this returns an invalid selector rather than an error.
| 1650 | // If the index is out of bounds, this returns an invalid selector rather than an |
| 1651 | // error. |
| 1652 | Result<NestedSelector> GetChild(int i) const { |
| 1653 | std::shared_ptr<T> child; |
| 1654 | if (auto parent = get_parent()) { |
| 1655 | const DataType* type = Util::GetType(*parent); |
| 1656 | // We avoid this check for schema fields since it's inconsequential (plus there are |
| 1657 | // tests elsewhere that rely on it not happening) |
| 1658 | if constexpr (!std::is_same_v<T, Field>) { |
| 1659 | if (ARROW_PREDICT_FALSE(type->id() != Type::STRUCT)) { |
| 1660 | return Util::NonStructError(); |
| 1661 | } |
| 1662 | } |
| 1663 | // Bounds-check the index *once* using the parent's type |
| 1664 | if (ARROW_PREDICT_TRUE(i >= 0 && i < type->num_fields())) { |
| 1665 | ARROW_ASSIGN_OR_RAISE(child, GetChild(*parent, i, pool_)); |
| 1666 | } |
| 1667 | } else if (auto children = get_children()) { |
| 1668 | if (ARROW_PREDICT_TRUE(i >= 0 && static_cast<size_t>(i) < children->size())) { |
| 1669 | child = (*children)[i]; |
| 1670 | } |
| 1671 | } |
| 1672 | return NestedSelector(std::move(child), pool_); |
| 1673 | } |
| 1674 | |
| 1675 | Result<std::shared_ptr<T>> Finish() const { |
| 1676 | DCHECK(get_parent() && owned_parent_); |
nothing calls this directly
no test coverage detected