Merge pull request #3301 from vavrusa/fix-capnp-array-struct-mismatch

Formats/CapnProtoRowInputStream: fix column mismatch in list of structs
This commit is contained in:
alexey-milovidov 2018-10-05 02:07:08 +03:00 committed by GitHub
commit 8c9f13e726
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -144,7 +144,12 @@ void CapnProtoRowInputStream::createActions(const NestedFieldList & sortedFields
{
// The field list here flattens Nested elements into multiple arrays
// In order to map Nested types in Cap'nProto back, they need to be collected
actions.back().columns.push_back(field.pos);
// Since the field names are sorted, the order of field positions must be preserved
// For example, if the fields are { b @0 :Text, a @1 :Text }, the `a` would come first
// even though it's position is second.
auto & columns = actions.back().columns;
auto it = std::upper_bound(columns.cbegin(), columns.cend(), field.pos);
columns.insert(it, field.pos);
}
else
{