Extra tip: avoid calling ValueOrDie() as that will kill your program in
case of errors.

Replace auto x = F().ValueOrDie(); with ARROW_ASSIGN_OR_RAISE(auto x, F())
and declare the function to either return an arrow::Status or an
arrow::Result<T>.

--
Felipe

On Mon, Aug 19, 2024 at 10:41 AM Hung Dang <[email protected]> wrote:

> Hi Kou,
>
> Yes, it works.
>
> Thanks,
> Hung
>
> On Sun, Aug 18, 2024 at 9:29 PM Sutou Kouhei <[email protected]> wrote:
>
>> Hi,
>>
>> Does this work?
>>
>> std::shared_ptr<arrow::Table>
>> from_wire_format(std::shared_ptr<arrow::Buffer> buffer) {
>>   arrow::io::BufferReader input(std::move(buffer));
>>   auto reader =
>> arrow::ipc::RecordBatchStreamReader::Open(&input).ValueOrDie();
>>   return reader-.ToTable().ValueOrDie();
>> }
>>
>>
>> Thanks,
>> --
>> kou
>>
>> In <cajkfh3qu7++yrxev3sxpsdmulqpnjlya8pdtd8epzdcj8mq...@mail.gmail.com>
>>   "How to reconstruct an arrow::Table from an arrow::Buffer object in
>> C++?" on Sun, 18 Aug 2024 20:06:46 -0400,
>>   Hung Dang <[email protected]> wrote:
>>
>> > Hello,
>> >
>> > I use this code to serialize an arrow::Table to an arrow::Buffer.
>> >
>> > std::shared_ptr<arrow::Buffer> to_wire_format(const arrow::Table
>> &table) {
>> >   auto buffer = arrow::io::BufferOutputStream::Create().ValueOrDie();
>> >   auto writer = arrow::ipc::MakeStreamWriter(buffer,
>> > table.schema()).ValueOrDie();
>> >   validate_status(writer->WriteTable(table));
>> >   validate_status(writer->Close());
>> >   return buffer->Finish().ValueOrDie();
>> > }
>> >
>> > How do I reconstruct an arrow::Table from an arrow::Buffer?
>> >
>> > Thanks,
>> > Hung
>>
>

Reply via email to