]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/cpp/src/arrow/ipc/stream_to_file.cc
import quincy 17.2.0
[ceph.git] / 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
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
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
16 // under the License.
17
18 #include <iostream>
19 #include <memory>
20 #include <string>
21
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"
27
28 namespace arrow {
29 namespace ipc {
30
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;
37
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;
42 while (true) {
43 ARROW_ASSIGN_OR_RAISE(batch, reader->Next());
44 if (batch == nullptr) break;
45 RETURN_NOT_OK(writer->WriteRecordBatch(*batch));
46 }
47 return writer->Close();
48 }
49
50 } // namespace ipc
51 } // namespace arrow
52
53 int main(int argc, char** argv) {
54 arrow::Status status = arrow::ipc::ConvertToFile();
55 if (!status.ok()) {
56 std::cerr << "Could not convert to file: " << status.ToString() << std::endl;
57 return 1;
58 }
59 return 0;
60 }