You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/06 06:23:04 UTC

[GitHub] [arrow] edponce commented on issue #12049: How to read arrow files data in C#

edponce commented on issue #12049:
URL: https://github.com/apache/arrow/issues/12049#issuecomment-1006315899


   @neroarth94 There are several abstractions underlying the `Column` data structure. `var col` is a [`Column` which is represented by a `Field` and a `ChunkedArray`](https://github.com/apache/arrow/blob/master/csharp/src/Apache.Arrow/Column.cs#L27-L28). The `Data` getter gives you access to the [`ChunkedArray` which is a collection of `Arrays`](https://github.com/apache/arrow/blob/master/csharp/src/Apache.Arrow/ChunkedArray.cs#L28) that logically represent a single array of values. The `Array`s are the data structures that generally give you access to particular values. In your case, you have an [`Int32Array` which derives from `PrimitiveArray`](https://github.com/apache/arrow/blob/master/csharp/src/Apache.Arrow/Arrays/Int32Array.cs#L20) that contains the [`GetValue(index)`](https://github.com/apache/arrow/blob/master/csharp/src/Apache.Arrow/Arrays/PrimitiveArray.cs#L36) method for accessing a particular value.
   
   IIUC, unfortunately, the C# `ChunkedArray` API does not has an indexing method similar to [the one in the C++ API](https://github.com/apache/arrow/blob/master/cpp/src/arrow/chunked_array.cc#L149), so you would need to convert global `ChunkedArray` indices to and pair of `Array` index and relative value index. 
   
   For example, assuming the column consists of a single `ChunkedArray` you should be able to access the values as follows:
   ```c#
   var col = readBatch.Column(0);
   var value = col.Data.Array(0).GetValue(10);  // Value at index 10 is 15
   ```
   Note: Most of the data structures contain `Slice(offset, length)` methods that allow you to get a copy of a subset of the values.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org