Пример #1
0
        public ByteString ToGprcArrowFrame()
        {
            MemoryStream stream = new MemoryStream();

            var recordBatchBuilder = new RecordBatch.Builder();

            foreach (Field field in fields)
            {
                recordBatchBuilder.Append(field.Name, true, field.ToArrowArray());
            }

            var recordBatch = recordBatchBuilder.Build();
            var writer      = new ArrowFileWriter(stream, recordBatch.Schema);

            writer.WriteRecordBatch(recordBatch);
            writer.WriteEnd();

            stream.Position = 0;

            return(ByteString.FromStream(stream));
        }
Пример #2
0
        public async Task WritesEmptyFile()
        {
            RecordBatch originalBatch = TestData.CreateSampleRecordBatch(length: 1);

            var stream = new MemoryStream();
            var writer = new ArrowFileWriter(stream, originalBatch.Schema);

            writer.WriteStart();
            writer.WriteEnd();

            stream.Position = 0;

            var reader = new ArrowFileReader(stream);
            int count  = await reader.RecordBatchCountAsync();

            Assert.Equal(0, count);
            RecordBatch readBatch = reader.ReadNextRecordBatch();

            Assert.Null(readBatch);
            SchemaComparer.Compare(originalBatch.Schema, reader.Schema);
        }
Пример #3
0
        public async Task WritesFooterAlignedMulitpleOf8()
        {
            RecordBatch originalBatch = TestData.CreateSampleRecordBatch(length: 100);

            var stream = new MemoryStream();
            var writer = new ArrowFileWriter(
                stream,
                originalBatch.Schema,
                leaveOpen: true,
                // use WriteLegacyIpcFormat, which only uses a 4-byte length prefix
                // which causes the length prefix to not be 8-byte aligned by default
                new IpcOptions()
            {
                WriteLegacyIpcFormat = true
            });

            writer.WriteRecordBatch(originalBatch);
            writer.WriteEnd();

            stream.Position = 0;

            await ValidateRecordBatchFile(stream, originalBatch);
        }