You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@arrow.apache.org by "Adam Szmigin (Jira)" <ji...@apache.org> on 2020/06/22 16:35:00 UTC

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

     [ https://issues.apache.org/jira/browse/ARROW-8344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Adam Szmigin updated ARROW-8344:
--------------------------------
    Description: 
h1. 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:
{code:java}
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("]");
        }
    }
{code}
h2. Expected Output
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['Foo', 'Bar']
{noformat}
h2. Actual Output (Windows 10 x64)
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['   ', '   ']{noformat}
h2. Actual Output (Ubuntu 18.04 LTS x64)
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['', '']{noformat}
h1. Workaround

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

  was:
h1. 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:
{code:java}
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("]");
        }
    }
{code}
h2. Expected Output
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['Foo', 'Bar']
{noformat}
h2. Actual Output (Windows 10 x64)
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['   ', '   ']{noformat}
h2. Actual Output (Ubuntu 18.04 LTS x64)
{noformat}
Array contents: ['Hello', 'World']
Array contents: ['', '']{noformat}
h1. Workaround

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

The issue ARROW-7040 mentions other issues with string arrays in C#, but I'm not sure if this is related or not.


> [C#] StringArray.Builder.Clear() corrupts subsequently-built array contents
> ---------------------------------------------------------------------------
>
>                 Key: ARROW-8344
>                 URL: https://issues.apache.org/jira/browse/ARROW-8344
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: C#
>    Affects Versions: 0.16.0
>         Environment: Windows 10 x64
> Ubuntu Linux 18.04 LTS x64
>            Reporter: Adam Szmigin
>            Priority: Major
>
> h1. 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:
> {code:java}
> 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("]");
>         }
>     }
> {code}
> h2. Expected Output
> {noformat}
> Array contents: ['Hello', 'World']
> Array contents: ['Foo', 'Bar']
> {noformat}
> h2. Actual Output (Windows 10 x64)
> {noformat}
> Array contents: ['Hello', 'World']
> Array contents: ['   ', '   ']{noformat}
> h2. Actual Output (Ubuntu 18.04 LTS x64)
> {noformat}
> Array contents: ['Hello', 'World']
> Array contents: ['', '']{noformat}
> h1. Workaround
> The bug can be trivially worked around by constructing a new {{StringArray.Builder}} instead of calling {{Clear()}}.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)