Sort fields and properties by MetadataToken. #157
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found an issue that when writing parquet files using a writer like:
the resulting parquet file would have column C1 typed as
int
and C2 aslong
- i.e. the first two column types were swapped.Upon debugging it transpired that this was when
Type.GetFields()
was being used to build the write delegate.Type.GetFields()
was not returning fields in declaration order so the mapping of column name to type failed. The .NET docs for this method (andType.GetProperties()
) explicitly state that order is not guaranteed. So, I have changed the code to sort byMemberInfo.MetadataToken
as advised in this SO article.Note that no unit tests have been added to cover this as it proved impossible to find a circumstance which reliably failed with the old code. It seems the order
GetFields
uses is usually declaration order but might change under certain runtime conditions. I have verified though that my change here fixed the issue I was seeing in my code.