Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: add elementId to programmatic API #267

Merged
Merged
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
4 changes: 4 additions & 0 deletions lang/c++/impl/Schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ ArraySchema::ArraySchema(const ArraySchema &itemsSchema) : Schema(std::make_shar
node_->addLeaf(itemsSchema.root());
}

ArraySchema::ArraySchema(const Schema &itemsSchema, int64_t elementId) : Schema(std::make_shared<NodeArray>(elementId)) {
node_->addLeaf(itemsSchema.root());
}

MapSchema::MapSchema(const Schema &valuesSchema) : Schema(std::make_shared<NodeMap>()) {
node_->addLeaf(valuesSchema.root());
}
Expand Down
1 change: 1 addition & 0 deletions lang/c++/include/avro/NodeImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public:
class AVRO_DECL NodeArray : public NodeImplArray {
public:
NodeArray() : NodeImplArray(AVRO_ARRAY) {}
explicit NodeArray(int64_t elementId) : NodeImplArray(AVRO_ARRAY), elementId_(elementId) {}

explicit NodeArray(const SingleLeaf &items) : NodeImplArray(AVRO_ARRAY, NoName(), items, NoLeafNames(), NoAttributes(), NoSize()) {}

Expand Down
1 change: 1 addition & 0 deletions lang/c++/include/avro/Schema.hh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public:
class AVRO_DECL ArraySchema : public Schema {
public:
explicit ArraySchema(const Schema &itemsSchema);
ArraySchema(const Schema &itemsSchema, int64_t elementId);
ArraySchema(const ArraySchema &itemsSchema);
};

Expand Down
21 changes: 21 additions & 0 deletions lang/c++/test/unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,26 @@ void testNestedMapSchema() {
BOOST_CHECK_EQUAL(expected, actual.str());
}

void testArraySchemaElementId() {
ArraySchema b0 = ArraySchema(NullSchema(), 2);
ArraySchema a0 = ArraySchema(b0, 1);

avro::ValidSchema vs(a0);
std::ostringstream actual;
vs.toJson(actual);

std::string expected = "{\n\
\"type\": \"array\",\n\
\"element-id\": 1,\n\
\"items\": {\n\
\"type\": \"array\",\n\
\"element-id\": 2,\n\
\"items\": \"null\"\n\
}\n\
}\n";
BOOST_CHECK_EQUAL(expected, actual.str());
}

boost::unit_test::test_suite *
init_unit_test_suite(int /*argc*/, char * /*argv*/[]) {
using namespace boost::unit_test;
Expand All @@ -1104,6 +1124,7 @@ init_unit_test_suite(int /*argc*/, char * /*argv*/[]) {
boost::make_shared<TestResolution>()));
test->add(BOOST_TEST_CASE(&testNestedArraySchema));
test->add(BOOST_TEST_CASE(&testNestedMapSchema));
test->add(BOOST_TEST_CASE(&testArraySchemaElementId));

return test;
}
Loading