MCPcopy Create free account
hub / github.com/apache/arrow / GetChild

Method GetChild

cpp/src/arrow/type.cc:1652–1673  ·  view source on GitHub ↗

If the index is out of bounds, this returns an invalid selector rather than an error.

Source from the content-addressed store, hash-verified

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_);

Callers

nothing calls this directly

Calls 15

NestedSelectorClass · 0.85
GetFlattenedFieldMethod · 0.80
push_backMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.50
MakeArrayFunction · 0.50
idMethod · 0.45
num_fieldsMethod · 0.45
sizeMethod · 0.45
fieldMethod · 0.45
typeMethod · 0.45
CopyMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected