forked from apache/arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_integration.h
More file actions
129 lines (105 loc) · 4.11 KB
/
Copy pathjson_integration.h
File metadata and controls
129 lines (105 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
// Implement Arrow JSON serialization format for integration tests
#pragma once
#include <memory>
#include <string>
#include "arrow/status.h"
#include "arrow/testing/visibility.h"
namespace arrow {
class Buffer;
class MemoryPool;
class RecordBatch;
class Schema;
namespace io {
class ReadableFile;
} // namespace io
namespace testing {
/// \class IntegrationJsonWriter
/// \brief Write the JSON representation of an Arrow record batch file or stream
///
/// This is used for integration testing
class ARROW_TESTING_EXPORT IntegrationJsonWriter {
public:
~IntegrationJsonWriter();
/// \brief Create a new JSON writer that writes to memory
///
/// \param[in] schema the schema of record batches
/// \param[out] out the returned writer object
/// \return Status
static Status Open(const std::shared_ptr<Schema>& schema,
std::unique_ptr<IntegrationJsonWriter>* out);
/// \brief Append a record batch
Status WriteRecordBatch(const RecordBatch& batch);
/// \brief Finish the JSON payload and return as a std::string
///
/// \param[out] result the JSON as as a std::string
/// \return Status
Status Finish(std::string* result);
private:
explicit IntegrationJsonWriter(const std::shared_ptr<Schema>& schema);
// Hide RapidJSON details from public API
class Impl;
std::unique_ptr<Impl> impl_;
};
/// \class IntegrationJsonReader
/// \brief Read the JSON representation of an Arrow record batch file or stream
///
/// This is used for integration testing
class ARROW_TESTING_EXPORT IntegrationJsonReader {
public:
~IntegrationJsonReader();
/// \brief Create a new JSON reader
///
/// \param[in] pool a MemoryPool to use for buffer allocations
/// \param[in] data a Buffer containing the JSON data
/// \param[out] reader the returned reader object
/// \return Status
static Status Open(MemoryPool* pool, const std::shared_ptr<Buffer>& data,
std::unique_ptr<IntegrationJsonReader>* reader);
/// \brief Create a new JSON reader that uses the default memory pool
///
/// \param[in] data a Buffer containing the JSON data
/// \param[out] reader the returned reader object
/// \return Status
static Status Open(const std::shared_ptr<Buffer>& data,
std::unique_ptr<IntegrationJsonReader>* reader);
/// \brief Create a new JSON reader from a file
///
/// \param[in] pool a MemoryPool to use for buffer allocations
/// \param[in] in_file a ReadableFile containing JSON data
/// \param[out] reader the returned reader object
/// \return Status
static Status Open(MemoryPool* pool, const std::shared_ptr<io::ReadableFile>& in_file,
std::unique_ptr<IntegrationJsonReader>* reader);
/// \brief Return the schema read from the JSON
std::shared_ptr<Schema> schema() const;
/// \brief Return the number of record batches
int num_record_batches() const;
/// \brief Read a particular record batch from the file
///
/// \param[in] i the record batch index, does not boundscheck
/// \param[out] batch the read record batch
Status ReadRecordBatch(int i, std::shared_ptr<RecordBatch>* batch) const;
private:
IntegrationJsonReader(MemoryPool* pool, const std::shared_ptr<Buffer>& data);
// Hide RapidJSON details from public API
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace testing
} // namespace arrow