Skip to content
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
11 changes: 6 additions & 5 deletions core/src/array/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ int ArraySchema::serialize(
memcpy(buffer + offset, &compression, sizeof(char));
offset += sizeof(char);
}
// Copy compression_level_
char compression_level;
// Copy compression_level_. Levels can be negative, and char is unsigned on some platforms
int8_t compression_level;
for(int i=0; i<=attribute_num_; ++i) {
compression_level = compression_level_[i];
assert(offset + sizeof(char) <= buffer_size);
Expand All @@ -790,7 +790,7 @@ int ArraySchema::serialize(
offset += sizeof(char);
}
// Copy offsets compression_level_
char offsets_compression_level;
int8_t offsets_compression_level;
for(int i=0; i<attribute_num_; ++i) {
offsets_compression_level = offsets_compression_level_[i];
assert(offset + sizeof(char) <= buffer_size);
Expand Down Expand Up @@ -1198,7 +1198,8 @@ int ArraySchema::deserialize(
}
// Load compression_level_. Support added in array schema version 1L
if (get_version() >= 1L) {
char compression_level;
// Levels can be negative, and char is unsigned on some platforms
int8_t compression_level;
for(int i=0; i<=attribute_num_; ++i) {
assert(offset + sizeof(char) <= buffer_size);
memcpy(&compression_level, buffer + offset, sizeof(char));
Expand All @@ -1218,7 +1219,7 @@ int ArraySchema::deserialize(
}
// Load offsets_compression_level_. Support added in array schema version 2L
if (get_version() >= 2L) {
char offsets_compression_level;
int8_t offsets_compression_level;
for(int i=0; i<attribute_num_; ++i) {
assert(offset + sizeof(char) <= buffer_size);
memcpy(&offsets_compression_level, buffer + offset, sizeof(char));
Expand Down
14 changes: 14 additions & 0 deletions test/src/c_api/test_array_schema_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ TEST_CASE_METHOD(ArraySchemaTestFixture, "Test Array Schema char", "[array_schem
check_dense_array(array_name);
}

TEST_CASE_METHOD(ArraySchemaTestFixture, "A negative compression level is read back as negative",
"[array_schema_compression_level]") {
std::string array_name = array_name_ + "gzip_default_level";

// With no compression levels given, GZIP gets its default, which is negative
REQUIRE(TILEDB_COMPRESSION_LEVEL_GZIP < 0);
REQUIRE(create_dense_array(array_name, TILEDB_INT32, TILEDB_GZIP) == TILEDB_OK);

TileDB_ArraySchema array_schema_disk;
REQUIRE(tiledb_array_load_schema(tiledb_ctx_, array_name.c_str(), &array_schema_disk) == TILEDB_OK);
CHECK(array_schema_disk.compression_level_[0] == TILEDB_COMPRESSION_LEVEL_GZIP);
REQUIRE(tiledb_array_free_schema(&array_schema_disk) == TILEDB_OK);
}

TEST_CASE_METHOD(ArraySchemaTestFixture, "Test Array Schema int8", "[array_schema_int8]") {
std::string array_name = array_name_ + "int8";

Expand Down
Loading