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 
42 class ARROW_EXPORT JsonWriter {
43  public:
44  ~JsonWriter();
45 
51  static Status Open(const std::shared_ptr<Schema>& schema,
52  std::unique_ptr<JsonWriter>* out);
53 
55  Status WriteRecordBatch(const RecordBatch& batch);
56 
61  Status Finish(std::string* result);
62 
63  private:
64  explicit JsonWriter(const std::shared_ptr<Schema>& schema);
65 
66  // Hide RapidJSON details from public API
67  class JsonWriterImpl;
68  std::unique_ptr<JsonWriterImpl> impl_;
69 };
70 
75 class ARROW_EXPORT JsonReader {
76  public:
77  ~JsonReader();
78 
85  static Status Open(MemoryPool* pool, const std::shared_ptr<Buffer>& data,
86  std::unique_ptr<JsonReader>* reader);
87 
93  static Status Open(const std::shared_ptr<Buffer>& data,
94  std::unique_ptr<JsonReader>* reader);
95 
97  std::shared_ptr<Schema> schema() const;
98 
100  int num_record_batches() const;
101 
106  Status ReadRecordBatch(int i, std::shared_ptr<RecordBatch>* batch) const;
107 
108  private:
109  JsonReader(MemoryPool* pool, const std::shared_ptr<Buffer>& data);
110 
111  // Hide RapidJSON details from public API
112  class JsonReaderImpl;
113  std::unique_ptr<JsonReaderImpl> impl_;
114 };
115 
116 } // namespace ipc
117 } // namespace arrow
118 
119 #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.
Collection of equal-length arrays matching a particular Schema.
Definition: table.h:118
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.
Definition: status.h:106
Top-level namespace for Apache Arrow C++ API.
Definition: allocator.h:29
Read the JSON representation of an Arrow record batch file or stream.
Definition: json.h:75
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.
Base class for memory allocation.
Definition: memory_pool.h:34
Write the JSON representation of an Arrow record batch file or stream.
Definition: json.h:42