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

Method GetChild

cpp/src/arrow/type.cc:1655–1676  ·  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

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