public void Visit(ListType type)
            {
                ListArray.Builder resultBuilder = new ListArray.Builder(type.ValueDataType).Reserve(_baseDataTotalElementCount);
                //Todo : Support various types
                Int64Array.Builder resultValueBuilder = (Int64Array.Builder)resultBuilder.ValueBuilder.Reserve(_baseDataTotalElementCount);

                for (int i = 0; i < _baseDataListCount; i++)
                {
                    List <int?> dataList = _baseData[i];

                    ListArray.Builder  builder      = new ListArray.Builder(type.ValueField).Reserve(dataList.Count);
                    Int64Array.Builder valueBuilder = (Int64Array.Builder)builder.ValueBuilder.Reserve(dataList.Count);

                    foreach (long?value in dataList)
                    {
                        if (value.HasValue)
                        {
                            builder.Append();
                            resultBuilder.Append();

                            valueBuilder.Append(value.Value);
                            resultValueBuilder.Append(value.Value);
                        }
                        else
                        {
                            builder.AppendNull();
                            resultBuilder.AppendNull();
                        }
                    }

                    TestTargetArrayList.Add(builder.Build());
                }

                ExpectedArray = resultBuilder.Build();
            }
Пример #2
0
        public void ListArrayBuilder()
        {
            var listBuilder  = new ListArray.Builder(StringType.Default);
            var valueBuilder = listBuilder.ValueBuilder as StringArray.Builder;

            Assert.NotNull(valueBuilder);
            listBuilder.Append();
            valueBuilder.Append("1");
            listBuilder.AppendNull();
            listBuilder.Append();
            valueBuilder.Append("22").Append("33");
            listBuilder.Append();
            valueBuilder.Append("444").AppendNull().Append("555").Append("666");

            var list = listBuilder.Build();

            Assert.Equal(
                new List <string> {
                "1"
            },
                ConvertStringArrayToList(list.GetSlicedValues(0) as StringArray));
            Assert.Null(list.GetSlicedValues(1));
            Assert.Equal(
                new List <string> {
                "22", "33"
            },
                ConvertStringArrayToList(list.GetSlicedValues(2) as StringArray));
            Assert.Equal(
                new List <string> {
                "444", null, "555", "666"
            },
                ConvertStringArrayToList(list.GetSlicedValues(3) as StringArray));

            List <string> ConvertStringArrayToList(StringArray array)
            {
                var length     = array.Length;
                var resultList = new List <string>(length);

                for (var index = 0; index < length; index++)
                {
                    resultList.Add(array.GetString(index));
                }
                return(resultList);
            }
        }
Пример #3
0
        public void ListArrayBuilder()
        {
            var listBuilder  = new ListArray.Builder(StringType.Default);
            var valueBuilder = listBuilder.ValueBuilder as StringArray.Builder;

            Assert.NotNull(valueBuilder);
            listBuilder.Append();
            valueBuilder.Append("1");
            listBuilder.AppendNull();
            listBuilder.Append();
            valueBuilder.Append("22").Append("33");
            listBuilder.Append();
            valueBuilder.Append("444").AppendNull().Append("555").Append("666");

            var list = listBuilder.Build();

            Assert.Equal(
                new List <string> {
                "1"
            },
                ConvertStringArrayToList(list.GetSlicedValues(0) as StringArray));
            Assert.Null(list.GetSlicedValues(1));
            Assert.Equal(
                new List <string> {
                "22", "33"
            },
                ConvertStringArrayToList(list.GetSlicedValues(2) as StringArray));
            Assert.Equal(
                new List <string> {
                "444", null, "555", "666"
            },
                ConvertStringArrayToList(list.GetSlicedValues(3) as StringArray));

            Assert.Throws <ArgumentOutOfRangeException>(() => list.GetValueLength(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => list.GetValueLength(4));

            listBuilder.Resize(2);
            var truncatedList = listBuilder.Build();

            Assert.Equal(
                new List <string> {
                "22", "33", "444", null, "555", "666"
            },
                ConvertStringArrayToList(truncatedList.GetSlicedValues(2) as StringArray));

            Assert.Throws <ArgumentOutOfRangeException>(() => truncatedList.GetSlicedValues(-1));
            Assert.Throws <ArgumentOutOfRangeException>(() => truncatedList.GetSlicedValues(3));

            listBuilder.Clear();
            var emptyList = listBuilder.Build();

            Assert.Equal(0, emptyList.Length);

            List <string> ConvertStringArrayToList(StringArray array)
            {
                var length     = array.Length;
                var resultList = new List <string>(length);

                for (var index = 0; index < length; index++)
                {
                    resultList.Add(array.GetString(index));
                }
                return(resultList);
            }
        }