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

Function ToUniversalRef

cpp/src/arrow/dataset/file_json.cc:166–184  ·  view source on GitHub ↗

Converts a FieldPath to a FieldRef consisting exclusively of field names. The resulting FieldRef can be used to lookup the corresponding field in any schema regardless of missing/unordered fields. The input path is assumed to be valid for the given schema.

Source from the content-addressed store, hash-verified

164// regardless of missing/unordered fields. The input path is assumed to be valid for the
165// given schema.
166FieldRef ToUniversalRef(const FieldPath& path, const Schema& schema) {
167 std::vector<FieldRef> refs;
168 refs.reserve(path.indices().size());
169
170 const FieldVector* fields = &schema.fields();
171 for (auto it = path.begin(); it != path.end(); ++it) {
172 DCHECK_LT(*it, static_cast<int>(fields->size()));
173 const auto& child_field = *(*fields)[*it];
174 refs.emplace_back(child_field.name());
175 if (it + 1 != path.end()) {
176 auto&& child_type = checked_cast<const StructType&>(*child_field.type());
177 fields = &child_type.fields();
178 }
179 }
180
181 return refs.empty() ? FieldRef()
182 : refs.size() == 1 ? refs[0]
183 : FieldRef(std::move(refs));
184}
185
186int TopLevelIndex(const FieldRef& ref, const Schema& schema) {
187 if (const auto* name = ref.name()) {

Callers 1

GetPartialSchemaFunction · 0.85

Calls 11

indicesMethod · 0.80
emplace_backMethod · 0.80
FieldRefFunction · 0.50
reserveMethod · 0.45
sizeMethod · 0.45
fieldsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
nameMethod · 0.45
typeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected