Skip to content

Commit 3d6bbbd

Browse files
committed
Start high level writer scaffold
Change-Id: I325f3c3a33c1ded53b083d19d72234794338b28b
1 parent 6bbd669 commit 3d6bbbd

File tree

4 files changed

+71
-26
lines changed

4 files changed

+71
-26
lines changed

cpp/src/arrow/ipc/ipc-json-test.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "arrow/ipc/json-internal.h"
1918

2019
#include <cstdint>
2120
#include <cstdio>
@@ -25,12 +24,11 @@
2524
#include <string>
2625
#include <vector>
2726

28-
#include "rapidjson/document.h"
29-
#include "rapidjson/filewritestream.h"
30-
#include "rapidjson/prettywriter.h"
3127
#include "gtest/gtest.h"
3228

3329
#include "arrow/array.h"
30+
#include "arrow/ipc/json.h"
31+
#include "arrow/ipc/json-internal.h"
3432
#include "arrow/test-util.h"
3533
#include "arrow/type.h"
3634
#include "arrow/type_traits.h"

cpp/src/arrow/ipc/json-internal.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
// Implement Arrow JSON serialization format
19-
20-
#ifndef ARROW_IPC_JSON_H
21-
#define ARROW_IPC_JSON_H
18+
#ifndef ARROW_IPC_JSON_INTERNAL_H
19+
#define ARROW_IPC_JSON_INTERNAL_H
2220

2321
#define RAPIDJSON_HAS_STDSTRING 1
2422
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 1
@@ -57,4 +55,4 @@ Status ARROW_EXPORT ReadJsonArray(MemoryPool* pool, const rj::Value& json_obj,
5755
} // namespace ipc
5856
} // namespace arrow
5957

60-
#endif // ARROW_IPC_FILE_H
58+
#endif // ARROW_IPC_JSON_INTERNAL_H

cpp/src/arrow/ipc/json.cc

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,62 @@
2222
#include "arrow/util/status.h"
2323

2424
namespace arrow {
25-
namespace ipc {} // namespace ipc
25+
namespace ipc {
26+
27+
class JsonWriter::JsonWriterImpl {
28+
public:
29+
JsonWriterImpl(const std::shared_ptr<Schema>& schema)
30+
: schema_(schema) {
31+
writer_.reset(new RjWriter(string_buffer_));
32+
}
33+
34+
Status Start() {
35+
writer_->StartObject();
36+
37+
writer_->Key("schema");
38+
RETURN_NOT_OK(WriteJsonSchema(schema_, writer_.get()));
39+
40+
// Record batches
41+
writer_->Key("batches");
42+
writer_->StartArray();
43+
return Status::OK();
44+
}
45+
46+
Status Finish() {
47+
writer_->EndArray(); // Record batches
48+
writer_->EndObject();
49+
return Status::OK();
50+
}
51+
52+
Status WriteRecordBatch(const std::vector<std::shared_ptr<Array>>& columns, int32_t num_rows) {
53+
return Status::OK();
54+
}
55+
56+
private:
57+
std::shared_ptr<Schema> schema_;
58+
59+
rj::StringBuffer string_buffer_;
60+
std::unique_ptr<RjWriter> writer_;
61+
};
62+
63+
JsonWriter::JsonWriter(const std::shared_ptr<Schema>& schema) {
64+
impl_.reset(new JsonWriteImpl(schema));
65+
}
66+
67+
Status JsonWriter::Open(
68+
const std::shared_ptr<Schema>& schema, std::unique_ptr<JsonWriter>* writer) {
69+
*writer = std::unique_ptr<JsonWriter>(new JsonWriter(schema));
70+
return (*writer)->impl_->Start();
71+
}
72+
73+
Status JsonWriter::Close() {
74+
return impl_->Close();
75+
}
76+
77+
Status JsonWriter::WriteRecordBatch(
78+
const std::vector<std::shared_ptr<Array>>& columns, int32_t num_rows) {
79+
80+
}
81+
82+
} // namespace ipc
2683
} // namespace arrow

cpp/src/arrow/ipc/json.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ namespace ipc {
4343

4444
class ARROW_EXPORT JsonWriter {
4545
public:
46-
static Status Open(io::OutputStream* sink, const std::shared_ptr<Schema>& schema,
47-
std::shared_ptr<JsonWriter>* out);
46+
static Status Open(const std::shared_ptr<Schema>& schema, std::unique_ptr<JsonWriter>* out);
4847

4948
// TODO(wesm): Write dictionaries
5049

@@ -54,25 +53,21 @@ class ARROW_EXPORT JsonWriter {
5453
Status Close();
5554

5655
private:
57-
JsonWriter(io::OutputStream* sink, const std::shared_ptr<Schema>& schema);
58-
59-
io::OutputStream* sink_;
60-
std::shared_ptr<Schema> schema_;
56+
explicit JsonWriter(const std::shared_ptr<Schema>& schema);
6157

6258
// Hide RapidJSON details from public API
6359
class JsonWriterImpl;
6460
std::unique_ptr<JsonWriterImpl> impl_;
6561
};
6662

63+
// TODO(wesm): Read from a file stream rather than an in-memory buffer
6764
class ARROW_EXPORT JsonReader {
6865
public:
69-
static Status Open(MemoryPool* pool,
70-
const std::shared_ptr<io::ReadableFileInterface>& file,
71-
std::shared_ptr<JsonReader>* reader);
66+
static Status Open(MemoryPool* pool, const std::shared_ptr<Buffer>& data,
67+
std::unique_ptr<JsonReader>* reader);
7268

7369
// Use the default memory pool
74-
static Status Open(const std::shared_ptr<io::ReadableFileInterface>& file,
75-
std::shared_ptr<JsonReader>* reader);
70+
static Status Open(const std::shared_ptr<Buffer>& data, std::unique_ptr<JsonReader>* reader);
7671

7772
std::shared_ptr<Schema> schema() const;
7873

@@ -82,10 +77,7 @@ class ARROW_EXPORT JsonReader {
8277
Status GetRecordBatch(int i, std::shared_ptr<RecordBatch>* batch);
8378

8479
private:
85-
explicit JsonReader(const std::shared_ptr<io::ReadableFileInterface>& file);
86-
87-
std::shared_ptr<io::ReadableFileInterface> file_;
88-
std::shared_ptr<Schema> schema_;
80+
explicit JsonReader(const std::shared_ptr<Buffer>& data);
8981

9082
// Hide RapidJSON details from public API
9183
class JsonReaderImpl;
@@ -95,4 +87,4 @@ class ARROW_EXPORT JsonReader {
9587
} // namespace ipc
9688
} // namespace arrow
9789

98-
#endif // ARROW_IPC_FILE_H
90+
#endif // ARROW_IPC_JSON_H

0 commit comments

Comments
 (0)