]>
git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/ipc/stream_to_file.cc
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
22 #include "arrow/io/stdio.h"
23 #include "arrow/ipc/reader.h"
24 #include "arrow/ipc/writer.h"
25 #include "arrow/record_batch.h"
26 #include "arrow/status.h"
31 // Converts a stream from stdin to a file written to standard out.
32 // A typical usage would be:
33 // $ <program that produces streaming output> | stream-to-file > file.arrow
34 Status
ConvertToFile() {
35 io::StdinStream input
;
36 io::StdoutStream sink
;
38 ARROW_ASSIGN_OR_RAISE(auto reader
, RecordBatchStreamReader::Open(&input
));
39 ARROW_ASSIGN_OR_RAISE(
40 auto writer
, MakeFileWriter(&sink
, reader
->schema(), IpcWriteOptions::Defaults()));
41 std::shared_ptr
<RecordBatch
> batch
;
43 ARROW_ASSIGN_OR_RAISE(batch
, reader
->Next());
44 if (batch
== nullptr) break;
45 RETURN_NOT_OK(writer
->WriteRecordBatch(*batch
));
47 return writer
->Close();
53 int main(int argc
, char** argv
) {
54 arrow::Status status
= arrow::ipc::ConvertToFile();
56 std::cerr
<< "Could not convert to file: " << status
.ToString() << std::endl
;