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

[Backport release-2.18] Fix serialization of empty enumerations #4476

Merged
merged 1 commit into from
Nov 1, 2023
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
33 changes: 33 additions & 0 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,39 @@ 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 enmr1 = Enumeration::create(
"empty_fixed", Datatype::INT32, 1, false, nullptr, 0, nullptr, 0);
auto enmr2 = Enumeration::create(
"empty_var",
Datatype::STRING_ASCII,
constants::var_num,
false,
nullptr,
0,
nullptr,
0);

schema1->add_enumeration(enmr1);
schema1->add_enumeration(enmr2);

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
2 changes: 1 addition & 1 deletion tiledb/sm/c_api/tiledb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3595,7 +3595,7 @@ int32_t tiledb_deserialize_array_schema(
} catch (...) {
delete *array_schema;
*array_schema = nullptr;
return TILEDB_ERR;
throw;
}

return TILEDB_OK;
Expand Down
23 changes: 12 additions & 11 deletions tiledb/sm/serialization/enumeration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ 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();
auto ospan = enumeration->offsets();
if (ospan.size() > 0) {
enmr_builder.setOffsets(::kj::arrayPtr(ospan.data(), ospan.size()));
}
}
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
Loading