From 6b972fef08ed3840881b22d24a6ae93611038b0a Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Tue, 31 Oct 2023 13:23:07 -0500 Subject: [PATCH] Fix schema serialization with empty enumerations 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. --- test/src/unit-enumerations.cc | 20 ++++++++++++++++++++ tiledb/sm/serialization/enumeration.cc | 19 ++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/test/src/unit-enumerations.cc b/test/src/unit-enumerations.cc index 7840f81c3475..1170ca65b83b 100644 --- a/test/src/unit-enumerations.cc +++ b/test/src/unit-enumerations.cc @@ -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", diff --git a/tiledb/sm/serialization/enumeration.cc b/tiledb/sm/serialization/enumeration.cc index 6cdcaee2f3c0..4d2f587ead7a 100644 --- a/tiledb/sm/serialization/enumeration.cc +++ b/tiledb/sm/serialization/enumeration.cc @@ -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(); @@ -73,15 +75,14 @@ shared_ptr 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;