Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions cpp/src/arrow/ipc/ipc-json-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,25 @@

namespace arrow {
namespace ipc {
namespace json {

void TestSchemaRoundTrip(const Schema& schema) {
rj::StringBuffer sb;
rj::Writer<rj::StringBuffer> writer(sb);

ASSERT_OK(WriteJsonSchema(schema, &writer));
writer.StartObject();
ASSERT_OK(internal::WriteSchema(schema, &writer));
writer.EndObject();

std::string json_schema = sb.GetString();

rj::Document d;
d.Parse(sb.GetString());
d.Parse(json_schema);

std::shared_ptr<Schema> out;
ASSERT_OK(ReadJsonSchema(d, &out));
if (!internal::ReadSchema(d, default_memory_pool(), &out).ok()) {
FAIL() << "Unable to read JSON schema: " << json_schema;
}

if (!schema.Equals(*out)) {
FAIL() << "In schema: " << schema.ToString() << "\nOut schema: " << out->ToString();
Expand All @@ -63,7 +70,7 @@ void TestArrayRoundTrip(const Array& array) {
rj::StringBuffer sb;
rj::Writer<rj::StringBuffer> writer(sb);

ASSERT_OK(WriteJsonArray(name, array, &writer));
ASSERT_OK(internal::WriteArray(name, array, &writer));

std::string array_as_json = sb.GetString();

Expand All @@ -73,7 +80,7 @@ void TestArrayRoundTrip(const Array& array) {
if (d.HasParseError()) { FAIL() << "JSON parsing failed"; }

std::shared_ptr<Array> out;
ASSERT_OK(ReadJsonArray(default_memory_pool(), d, array.type(), &out));
ASSERT_OK(internal::ReadArray(default_memory_pool(), d, array.type(), &out));

// std::cout << array_as_json << std::endl;
CompareArraysDetailed(0, *out, array);
Expand Down Expand Up @@ -355,7 +362,8 @@ TEST(TestJsonFileReadWrite, MinimalFormatExample) {
#define BATCH_CASES() \
::testing::Values(&MakeIntRecordBatch, &MakeListRecordBatch, &MakeNonNullRecordBatch, \
&MakeZeroLengthRecordBatch, &MakeDeeplyNestedList, &MakeStringTypesRecordBatch, \
&MakeStruct, &MakeUnion, &MakeDates, &MakeTimestamps, &MakeTimes, &MakeFWBinary);
&MakeStruct, &MakeUnion, &MakeDates, &MakeTimestamps, &MakeTimes, &MakeFWBinary, \
&MakeDictionary);

class TestJsonRoundTrip : public ::testing::TestWithParam<MakeRecordBatch*> {
public:
Expand All @@ -364,6 +372,8 @@ class TestJsonRoundTrip : public ::testing::TestWithParam<MakeRecordBatch*> {
};

void CheckRoundtrip(const RecordBatch& batch) {
TestSchemaRoundTrip(*batch.schema());

std::unique_ptr<JsonWriter> writer;
ASSERT_OK(JsonWriter::Open(batch.schema(), &writer));
ASSERT_OK(writer->WriteRecordBatch(batch));
Expand Down Expand Up @@ -392,5 +402,6 @@ TEST_P(TestJsonRoundTrip, RoundTrip) {

INSTANTIATE_TEST_CASE_P(TestJsonRoundTrip, TestJsonRoundTrip, BATCH_CASES());

} // namespace json
} // namespace ipc
} // namespace arrow
Loading