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

[C#] StringArray.Builder.Clear() corrupts subsequently-built array contents

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.16.0
    • 1.0.0
    • C#
    • Windows 10 x64
      Ubuntu Linux 18.04 LTS x64

    Description

      Summary

      Using the Clear() method on a StringArray.Builder class causes all subsequently-built arrays to contain corrupted strings, either consisting solely of whitespace or the empty string: the outcome appears OS-specific.  The below minimal example illustrates:

      namespace ArrowStringArrayBuilderBug
      {
          using Apache.Arrow;
          using Apache.Arrow.Memory;
      
          public class Program
          {
              private static readonly NativeMemoryAllocator Allocator
                  = new NativeMemoryAllocator();
      
              public static void Main()
              {
                  var builder = new StringArray.Builder();
                  AppendBuildPrint(builder, "Hello", "World");
                  builder.Clear();
                  AppendBuildPrint(builder, "Foo", "Bar");
              }
      
              private static void AppendBuildPrint(
                  StringArray.Builder builder, params string[] strings)
              {
                  foreach (var elem in strings)
                      builder.Append(elem);
      
                  var arr = builder.Build(Allocator);
                  System.Console.Write("Array contents: [");
                  for (var i = 0; i < arr.Length; i++)
                  {
                      if (i > 0) System.Console.Write(", ");
                      System.Console.Write($"'{arr.GetString(i)}'");
                  }
                  System.Console.WriteLine("]");
              }
          }
      

      Expected Output

      Array contents: ['Hello', 'World']
      Array contents: ['Foo', 'Bar']
      

      Actual Output (Windows 10 x64)

      Array contents: ['Hello', 'World']
      Array contents: ['   ', '   ']

      Actual Output (Ubuntu 18.04 LTS x64)

      Array contents: ['Hello', 'World']
      Array contents: ['', '']

      Workaround

      The bug can be trivially worked around by constructing a new StringArray.Builder instead of calling Clear().

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mr_smidge Adam Szmigin
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2.5h
                  2.5h