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();
            }
Ejemplo n.º 2
0
        public void NestedListArrayBuilder()
        {
            var childListType     = new ListType(Int64Type.Default);
            var parentListBuilder = new ListArray.Builder(childListType);
            var childListBuilder  = parentListBuilder.ValueBuilder as ListArray.Builder;

            Assert.NotNull(childListBuilder);
            var valueBuilder = childListBuilder.ValueBuilder as Int64Array.Builder;

            Assert.NotNull(valueBuilder);

            parentListBuilder.Append();
            childListBuilder.Append();
            valueBuilder.Append(1);
            childListBuilder.Append();
            valueBuilder.Append(2).Append(3);
            parentListBuilder.Append();
            childListBuilder.Append();
            valueBuilder.Append(4).Append(5).Append(6).Append(7);
            parentListBuilder.Append();
            childListBuilder.Append();
            valueBuilder.Append(8).Append(9).Append(10).Append(11).Append(12);

            var parentList = parentListBuilder.Build();

            var childList1 = (ListArray)parentList.GetSlicedValues(0);
            var childList2 = (ListArray)parentList.GetSlicedValues(1);
            var childList3 = (ListArray)parentList.GetSlicedValues(2);

            Assert.Equal(2, childList1.Length);
            Assert.Equal(1, childList2.Length);
            Assert.Equal(1, childList3.Length);
            Assert.Equal(
                new List <long?> {
                1
            },
                ((Int64Array)childList1.GetSlicedValues(0)).ToList());
            Assert.Equal(
                new List <long?> {
                2, 3
            },
                ((Int64Array)childList1.GetSlicedValues(1)).ToList());
            Assert.Equal(
                new List <long?> {
                4, 5, 6, 7
            },
                ((Int64Array)childList2.GetSlicedValues(0)).ToList());
            Assert.Equal(
                new List <long?> {
                8, 9, 10, 11, 12
            },
                ((Int64Array)childList3.GetSlicedValues(0)).ToList());
        }
Ejemplo n.º 3
0
            public void Visit(ListType type)
            {
                var builder = new ListArray.Builder(type.ValueField).Reserve(Length);

                //Todo : Support various types
                var valueBuilder = (Int64Array.Builder)builder.ValueBuilder.Reserve(Length);

                for (var i = 0; i < Length; i++)
                {
                    builder.Append();
                    valueBuilder.Append(i);
                }

                Array = builder.Build();
            }
Ejemplo n.º 4
0
            public void Visit(ListType type)
            {
                var builder = new ListArray.Builder(type.ValueField).Reserve(Length);

                //Todo : Support various types
                var valueBuilder = (Int64Array.Builder)builder.ValueBuilder.Reserve(Length + 1);

                for (var i = 0; i < Length; i++)
                {
                    builder.Append();
                    valueBuilder.Append(i);
                }
                //Add a value to check if Values.Length can exceed ListArray.Length
                valueBuilder.Append(0);

                Array = builder.Build();
            }
Ejemplo n.º 5
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);
            }
        }
        private Tuple <Field, DictionaryArray> CreateListTypeDictionaryArrayTestData(List <string> dictionaryDataBase)
        {
            var listBuilder  = new ListArray.Builder(StringType.Default);
            var valueBuilder = listBuilder.ValueBuilder as StringArray.Builder;

            foreach (string data in dictionaryDataBase)
            {
                listBuilder.Append();
                valueBuilder.Append(data);
            }

            ListArray  dictionary          = listBuilder.Build();
            Int32Array indiceArray         = new Int32Array.Builder().AppendRange(Enumerable.Range(0, dictionary.Length)).Build();
            var        dictionaryArrayType = new DictionaryType(Int32Type.Default, dictionary.Data.DataType, false);
            var        dictionaryArray     = new DictionaryArray(dictionaryArrayType, indiceArray, dictionary);

            return(Tuple.Create(new Field($"dictionaryField_{dictionaryArray.Data.DataType.Name}", dictionaryArrayType, false), dictionaryArray));
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        public void ListArrayBuilderValidityBuffer()
        {
            ListArray listArray = new ListArray.Builder(Int64Type.Default).Append().AppendNull().Build();

            Assert.False(listArray.IsValid(2));
        }