diff --git a/test/src/unit-cppapi-type.cc b/test/src/unit-cppapi-type.cc index cd2d388ba4b..880a8c9cd71 100644 --- a/test/src/unit-cppapi-type.cc +++ b/test/src/unit-cppapi-type.cc @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 TileDB Inc. + * @copyright Copyright (c) 2017-2024 TileDB Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,8 @@ #include #include "tiledb/sm/cpp_api/tiledb" +using namespace tiledb; + struct MyData { int a; float b; @@ -40,7 +42,6 @@ struct MyData { }; TEST_CASE("C++ API: Types", "[cppapi][types]") { - using namespace tiledb; Context ctx; CHECK( @@ -123,6 +124,12 @@ TEST_CASE("C++ API: Types", "[cppapi][types]") { CHECK_NOTHROW(impl::type_check>( TILEDB_STRING_ASCII, TILEDB_VAR_NUM)); + // Validate byte datatypes + CHECK_NOTHROW(impl::type_check(TILEDB_BLOB)); + CHECK_NOTHROW(impl::type_check(TILEDB_GEOM_WKB)); + CHECK_NOTHROW(impl::type_check(TILEDB_GEOM_WKT)); + CHECK_THROWS(impl::type_check(TILEDB_BOOL)); + auto a1 = Attribute::create(ctx, "a1"); auto a2 = Attribute::create(ctx, "a2"); auto a3 = Attribute::create(ctx, "a3"); diff --git a/test/src/unit-enum-helpers.cc b/test/src/unit-enum-helpers.cc index 1ff811d35ab..31402c46b7e 100644 --- a/test/src/unit-enum-helpers.cc +++ b/test/src/unit-enum-helpers.cc @@ -63,3 +63,11 @@ TEST_CASE( REQUIRE_THROWS(datatype_max_integral_value(Datatype::FLOAT64)); REQUIRE_THROWS(datatype_max_integral_value(Datatype::STRING_ASCII)); } + +TEST_CASE("Test datatype_is_byte", "[enums][datatype][datatype_is_byte]") { + auto datatype = + GENERATE(Datatype::BLOB, Datatype::GEOM_WKB, Datatype::GEOM_WKT); + + CHECK(datatype_is_byte(datatype)); + CHECK(!datatype_is_byte(Datatype::BOOL)); +} diff --git a/tiledb/sm/cpp_api/exception.h b/tiledb/sm/cpp_api/exception.h index 7edd776cecc..7d10125365f 100644 --- a/tiledb/sm/cpp_api/exception.h +++ b/tiledb/sm/cpp_api/exception.h @@ -7,7 +7,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2021 TileDB, Inc. + * @copyright Copyright (c) 2017-2024 TileDB, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -90,6 +90,12 @@ inline void type_check(tiledb_datatype_t type, unsigned num = 0) { "type (" + impl::type_to_str(type) + ")"); } + } else if (tiledb_byte_type(type)) { + if (!std::is_same::value) { + throw TypeError( + "Static type does not match expected container type std::byte for " + "tiledb byte type"); + } } else if (tiledb_datetime_type(type)) { if (!std::is_same::value) { throw TypeError( diff --git a/tiledb/sm/cpp_api/type.h b/tiledb/sm/cpp_api/type.h index db7331bf5c3..f8efb63cef7 100644 --- a/tiledb/sm/cpp_api/type.h +++ b/tiledb/sm/cpp_api/type.h @@ -7,7 +7,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017-2023 TileDB, Inc. + * @copyright Copyright (c) 2017-2024 TileDB, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -294,6 +294,17 @@ inline bool tiledb_string_type(tiledb_datatype_t type) { } } +inline bool tiledb_byte_type(tiledb_datatype_t type) { + switch (type) { + case TILEDB_BLOB: + case TILEDB_GEOM_WKB: + case TILEDB_GEOM_WKT: + return true; + default: + return false; + } +} + inline bool tiledb_datetime_type(tiledb_datatype_t type) { switch (type) { case TILEDB_DATETIME_YEAR: diff --git a/tiledb/sm/enums/datatype.h b/tiledb/sm/enums/datatype.h index 7b84f00f18e..897766241da 100644 --- a/tiledb/sm/enums/datatype.h +++ b/tiledb/sm/enums/datatype.h @@ -410,7 +410,7 @@ inline bool datatype_is_time(Datatype type) { /** Returns true if the input datatype is a std::byte type. */ inline bool datatype_is_byte(Datatype type) { return ( - type == Datatype::BOOL || type == Datatype::GEOM_WKB || + type == Datatype::BLOB || type == Datatype::GEOM_WKB || type == Datatype::GEOM_WKT); }