Apache Arrow (C++)
A columnar in-memory analytics layer designed to accelerate big data.
json.h
Go to the documentation of this file.
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 // Implement Arrow JSON serialization format
19 
20 #ifndef ARROW_IPC_JSON_H
21 #define ARROW_IPC_JSON_H
22 
23 #include <memory>
24 #include <string>
25 
26 #include "arrow/status.h"
27 #include "arrow/util/visibility.h"
28 
29 namespace arrow {
30 
31 class Buffer;
32 class MemoryPool;
33 class RecordBatch;
34 class Schema;
35 
36 namespace ipc {
37 namespace internal {
38 namespace json {
39 
44 class JsonWriter {
45  public:
46  ~JsonWriter();
47 
53  static Status Open(const std::shared_ptr<Schema>& schema,
54  std::unique_ptr<JsonWriter>* out);
55 
57  Status WriteRecordBatch(const RecordBatch& batch);
58 
63  Status Finish(std::string* result);
64 
65  private:
66  explicit JsonWriter(const std::shared_ptr<Schema>& schema);
67 
68  // Hide RapidJSON details from public API
69  class JsonWriterImpl;
70  std::unique_ptr<JsonWriterImpl> impl_;
71 };
72 
77 class JsonReader {
78  public:
79  ~JsonReader();
80 
87  static Status Open(MemoryPool* pool, const std::shared_ptr<Buffer>& data,
88  std::unique_ptr<JsonReader>* reader);
89 
95  static Status Open(const std::shared_ptr<Buffer>& data,
96  std::unique_ptr<JsonReader>* reader);
97 
99  std::shared_ptr<Schema> schema() const;
100 
102  int num_record_batches() const;
103 
108  Status ReadRecordBatch(int i, std::shared_ptr<RecordBatch>* batch) const;
109 
110  private:
111  JsonReader(MemoryPool* pool, const std::shared_ptr<Buffer>& data);
112 
113  // Hide RapidJSON details from public API
114  class JsonReaderImpl;
115  std::unique_ptr<JsonReaderImpl> impl_;
116 };
117 
118 } // namespace json
119 } // namespace internal
120 } // namespace ipc
121 } // namespace arrow
122 
123 #endif // ARROW_IPC_JSON_H
Status WriteRecordBatch(const RecordBatch &batch, int64_t buffer_start_offset, io::OutputStream *dst, int32_t *metadata_length, int64_t *body_length, MemoryPool *pool, int max_recursion_depth=kMaxNestingDepth, bool allow_64bit=false)
Low-level API for writing a record batch (without schema) to an OutputStream.
Status ReadRecordBatch(const std::shared_ptr< Schema > &schema, io::InputStream *stream, std::shared_ptr< RecordBatch > *out)
Read record batch as encapsulated IPC message with metadata size prefix and header.
Top-level namespace for Apache Arrow C++ API.
Definition: adapter.h:32
std::shared_ptr< Schema > schema(const std::vector< std::shared_ptr< Field >> &fields, const std::shared_ptr< const KeyValueMetadata > &metadata=NULLPTR)
Create a Schema instance.