benibus commented on code in PR #34537:
URL: https://github.com/apache/arrow/pull/34537#discussion_r1142809697
##########
cpp/src/arrow/type_test.cc:
##########
@@ -379,6 +382,72 @@ TEST(TestFieldPath, Basics) {
FieldPath({s.num_fields() * 2}).Get(s));
}
+TEST(TestFieldPath, GetForTable) {
Review Comment:
The current tests only cover `FieldPath`s with one index - i.e. top-level
fields. However, paths that reference nested fields have multiple indices
and/or names in sequence.
For example, let's say you set up a schema like this (note that `"c"` is a
struct with two nested fields):
```
auto f0 = field("a", int32());
auto f1 = field("b", int32());
auto f2 = field("c", struct_({f0, f1}));
auto s = schema({f0, f1, f2});
```
These are the paths for every field in the schema:
```
"a" -> [0]
"b" -> [1]
"c" -> [2]
"c.a" -> [2,0]
"c.b" -> [2,1]
```
Now, let's say you create a table with that schema:
```
auto v0 = ChunkedArrayFromJSON(s->field(0)->type(), {"[0,1,2]","[3,4,5]"});
auto v1 = ChunkedArrayFromJSON(s->field(1)->type(),
{"[5,4]","[3,2]","[1,0]"});
auto v2 = ChunkedArrayFromJSON(s->field(2)->type(),
{R"([{"a":0,"b":5},{"a":1,"b":4}])",
R"([{"a":2,"b":3},{"a":3,"b":2}])",
R"([{"a":4,"b":1},{"a":5,"b":0}])"});
auto t = Table::Make(s, {v0, v1, v2}, 6);
ASSERT_OK(t->ValidateFull());
```
In this case, the results of `FieldPath(1).Get(*t)` and
`FieldPath(2,1).Get(*t)` should both be equal to `v1`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]