Commits

Benjamin Kietzman authored 6d3c08586b7
ARROW-7412: [C++][Dataset] Provide FieldRef to disambiguate field references `FieldRef` is a new utility class which represents a reference to a field. It is intended to replace parameters like `int field_index` and `const std::string& name`; it can be implicitly constructed from either a field index or a name. Nested fields can be referenced as well: ```C++ // the following all indicate schema->GetFieldByName("alpha")->type()->child(0) FieldRef ref1({FieldRef("alpha"), FieldRef(0)}); FieldRef ref2("alpha", 0); ARROW_ASSIGN_OR_RAISE(FieldRef ref3, FieldRef::FromDotPath(".alpha[0]")); ``` FieldRefs provide a number of accessors for drilling down to potentially nested children. They are overloaded for convenience to support Schema (returns a field), DataType (returns a child field), Field (returns a child field of this field's type) Array (returns a child array), RecordBatch (returns a column), ChunkedArray (returns a ChunkedArray where each chunk is a child array of the corresponding original chunk) and Table (returns a column). ```C++ // Field names can match multiple fields in a Schema Schema a_is_ambiguous({field("a", null()), field("a", null())}); auto matches = FieldRef("a").FindAll(a_is_ambiguous); assert(matches.size() == 2); assert_ok_and_eq(FieldRef::Get(match, a_is_ambiguous), a_is_ambiguous.field(0)); // Convenience accessor raises a helpful error if the field is not found or ambiguous ARROW_ASSIGN_OR_RAISE(auto column, FieldRef("struct", "field_i32").GetOne(some_table)); ``` Closes #6545 from bkietz/7412-Dataset-Ensure-that-datas Authored-by: Benjamin Kietzman <bengilgit@gmail.com> Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>