Skip to content

Commit

Permalink
Fix schema serialization with empty enumerations
Browse files Browse the repository at this point in the history
This is an obvious oversight from me when adding tests in the original
PR. I managed to test array schema evolution for extending enumerations
but never thought to add basic schema serialization tests with empty
enmerations.
  • Loading branch information
davisp committed Oct 31, 2023
1 parent 8a07df2 commit 6b972fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
20 changes: 20 additions & 0 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,26 @@ TEST_CASE_METHOD(
REQUIRE(loaded_names2.empty());
}

TEST_CASE_METHOD(
EnumerationFx,
"Cap'N Proto - ArraySchema Serialization with Empty Enumerations",
"[enumeration][capnp][array-schema][empty-enumerations]") {
create_array();

auto client_side = GENERATE(true, false);
auto ser_type = GENERATE(SerializationType::CAPNP, SerializationType::JSON);

auto schema1 = create_schema();
auto empty_enmr = Enumeration::create("empty", Datatype::INT32, 1, false, nullptr, 0, nullptr, 0);
schema1->add_enumeration(empty_enmr);

auto schema2 = ser_des_array_schema(schema1, client_side, ser_type);

auto all_names1 = schema1->get_enumeration_names();
auto all_names2 = schema2.get_enumeration_names();
REQUIRE(vec_cmp(all_names1, all_names2));
}

TEST_CASE_METHOD(
EnumerationFx,
"Cap'N Proto - Basic ArraySchemaEvolution Serialization",
Expand Down
19 changes: 10 additions & 9 deletions tiledb/sm/serialization/enumeration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ void enumeration_to_capnp(
enmr_builder.setOrdered(enumeration->ordered());

auto dspan = enumeration->data();
enmr_builder.setData(::kj::arrayPtr(dspan.data(), dspan.size()));
if (dspan.size() > 0) {
enmr_builder.setData(::kj::arrayPtr(dspan.data(), dspan.size()));
}

if (enumeration->var_size()) {
auto ospan = enumeration->offsets();
Expand All @@ -73,15 +75,14 @@ shared_ptr<const Enumeration> enumeration_from_capnp(
Datatype datatype = Datatype::ANY;
throw_if_not_ok(datatype_enum(reader.getType(), &datatype));

if (!reader.hasData()) {
throw SerializationStatusException(
"[Deserialization::enumeration_from_capnp] Deserialization of "
"Enumeration is missing its data buffer.");
}
const void* data = nullptr;
uint64_t data_size = 0;

auto data_reader = reader.getData().asBytes();
auto data = data_reader.begin();
auto data_size = data_reader.size();
if (reader.hasData()) {
auto data_reader = reader.getData().asBytes();
data = data_reader.begin();
data_size = data_reader.size();
}

const void* offsets = nullptr;
uint64_t offsets_size = 0;
Expand Down

0 comments on commit 6b972fe

Please sign in to comment.