static List GenerateBatches()

in http/get_simple/csharp/server/ArrowHttpServer.cs [40:75]


        static List<RecordBatch> GenerateBatches(int totalRecords = 100000000, int batchSize = 4096)
        {
            Random random = new Random();
            IArrowArray[] columns = new IArrowArray[schema.FieldsList.Count];
            for (int i = 0; i < columns.Length; i++)
            {
                byte[] dataBytes = new byte[batchSize * sizeof(long)];
                random.NextBytes(dataBytes);
                ArrowBuffer data = new ArrowBuffer(dataBytes);
                byte[] validityBytes = new byte[batchSize / 8];
                System.Array.Fill(validityBytes, (byte)0xff);
                ArrowBuffer validity = new ArrowBuffer(validityBytes);

                columns[i] = ArrowArrayFactory.BuildArray(new ArrayData(schema.FieldsList[i].DataType, batchSize, 0, 0, new [] { validity, data }, null));
            }
            
            List<RecordBatch> batches = new List<RecordBatch>(totalRecords);
            using (RecordBatch batch = new RecordBatch(schema, columns, batchSize))
            {
                int records = 0;
                while (records < totalRecords)
                {
                    RecordBatch newBatch = batch.Clone();
                    if (records + batchSize > totalRecords)
                    {
                        int newLength = totalRecords - records;
                        newBatch = new RecordBatch(schema, newBatch.Arrays.Select(a => ArrowArrayFactory.Slice(a, 0, newLength)), newLength);
                    }

                    batches.Add(batch);
                    records += batchSize;
                }
            }

            return batches;
        }