Uploaded image for project: 'Apache Arrow'
  1. Apache Arrow
  2. ARROW-5035

[C#] ArrowBuffer.Builder<bool> is broken

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: C#
    • Labels:
      None

      Description

      If someone creates and uses `ArrowBuffer.Builder<bool>` in their code to create an ArrowBuffer filled with Boolean values, it is currently producing the wrong results.

      The reason it is producing the wrong results is because it is taking the `sizeof(bool)` (which is 1) and using that for how many bytes to write into the backing buffer for each element being added to the builder. However, in Arrow, Boolean values are stored in a bit-wise fashion allowing for 8 Boolean values in a single byte. Thus, when I add 4 `true` values to the buffer, I expect to get a buffer with 1 byte in it with the value 0x0F. However, I am getting a buffer with 4 bytes in it, each with value 0x01.

      One way to fix this would be to throw in `ArrowBuffer.Builder<T>`'s constructor if `T` == `bool` and instead create a new class `ArrowBuffer.BooleanBuilder`, which will create Boolean buffers correctly. Looking at the current implementation, I think it would be rather hard to special case `typeof(bool)` all over in the `Builder` class, but if someone wanted to take that approach and made it work, that would be great too.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              eerhardt Eric Erhardt
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: