Skip to content

Commit 310dd6c

Browse files
authored
Add datatypes GEOM_WKB and GEOM_WKT (#4640)
Add datatypes GEOM_WKB and GEOM_WKT, which represent `std::byte` --- TYPE: FEATURE DESC: Add datatypes GEOM_WKB and GEOM_WKT
1 parent 598e84e commit 310dd6c

34 files changed

+399
-190
lines changed

test/src/test-cppapi-aggregates.cc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2023 TileDB, Inc.
8+
* @copyright Copyright (c) 2023-2024 TileDB, Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -516,7 +516,7 @@ std::vector<uint8_t> CppAggregatesFx<T>::make_data_buff(
516516
}
517517
} else {
518518
for (auto& v : values) {
519-
data.emplace_back(v);
519+
data.emplace_back(static_cast<T>(v));
520520
}
521521
}
522522

@@ -1624,6 +1624,31 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
16241624
array.close();
16251625
}
16261626

1627+
typedef tuple<std::byte> BlobTypeUnderTest;
1628+
TEMPLATE_LIST_TEST_CASE_METHOD(
1629+
CppAggregatesFx,
1630+
"C++ API: Aggregates basic sum, std::byte",
1631+
"[cppapi][aggregates][basic][sum][byte]",
1632+
BlobTypeUnderTest) {
1633+
typedef TestType T;
1634+
CppAggregatesFx<T>::generate_test_params();
1635+
CppAggregatesFx<T>::create_array_and_write_fragments();
1636+
Array array{
1637+
CppAggregatesFx<T>::ctx_, CppAggregatesFx<T>::ARRAY_NAME, TILEDB_READ};
1638+
Query query(CppAggregatesFx<T>::ctx_, array, TILEDB_READ);
1639+
1640+
// Add a sum aggregator to the query.
1641+
QueryChannel default_channel = QueryExperimental::get_default_channel(query);
1642+
1643+
REQUIRE_THROWS_WITH(
1644+
QueryExperimental::create_unary_aggregate<SumOperator>(query, "a1"),
1645+
Catch::Matchers::ContainsSubstring(
1646+
"Datatype::BLOB is not a valid Datatype"));
1647+
1648+
// Close array.
1649+
array.close();
1650+
}
1651+
16271652
typedef tuple<
16281653
uint8_t,
16291654
uint16_t,
@@ -2607,7 +2632,7 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
26072632
TEST_CASE_METHOD(
26082633
CppAggregatesFx<int32_t>,
26092634
"CPP: Aggregates - Basic",
2610-
"[aggregates][cpp_api][args]") {
2635+
"[cppapi][aggregates][args]") {
26112636
dense_ = false;
26122637
nullable_ = false;
26132638
allow_dups_ = false;

test/src/unit-backwards_compat.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2021 TileDB Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB Inc.
99
* @copyright Copyright (c) 2016 MIT and Intel Corporation
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -275,7 +275,9 @@ TEST_CASE(
275275
uint8_t* validity = static_cast<uint8_t*>(malloc(sizeof(uint8_t)));
276276

277277
switch (attr.second.type()) {
278-
case TILEDB_BLOB: {
278+
case TILEDB_BLOB:
279+
case TILEDB_GEOM_WKB:
280+
case TILEDB_GEOM_WKT: {
279281
set_buffer_wrapper<std::byte>(
280282
query,
281283
attribute_name,
@@ -577,7 +579,9 @@ TEST_CASE(
577579

578580
Attribute attribute = array->schema().attribute(buff.first);
579581
switch (attribute.type()) {
580-
case TILEDB_BLOB: {
582+
case TILEDB_BLOB:
583+
case TILEDB_GEOM_WKB:
584+
case TILEDB_GEOM_WKT: {
581585
REQUIRE(
582586
static_cast<std::byte*>(std::get<1>(buffer))[0] ==
583587
static_cast<std::byte>(1));
@@ -780,7 +784,9 @@ TEST_CASE(
780784
uint8_t* validity = static_cast<uint8_t*>(malloc(sizeof(uint8_t)));
781785

782786
switch (attr.second.type()) {
783-
case TILEDB_BLOB: {
787+
case TILEDB_BLOB:
788+
case TILEDB_GEOM_WKB:
789+
case TILEDB_GEOM_WKT: {
784790
set_buffer_wrapper<std::byte>(
785791
query,
786792
attribute_name,
@@ -1118,7 +1124,9 @@ TEST_CASE(
11181124

11191125
Attribute attribute = array->schema().attribute(buff.first);
11201126
switch (attribute.type()) {
1121-
case TILEDB_BLOB: {
1127+
case TILEDB_BLOB:
1128+
case TILEDB_GEOM_WKB:
1129+
case TILEDB_GEOM_WKT: {
11221130
REQUIRE(
11231131
static_cast<std::byte*>(std::get<1>(buffer))[0] ==
11241132
static_cast<std::byte>(1));

test/src/unit-capi-attributes.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2021-2023 TileDB Inc.
8+
* @copyright Copyright (c) 2021-2024 TileDB Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -286,8 +286,10 @@ TEST_CASE_METHOD(
286286

287287
TEST_CASE_METHOD(
288288
Attributesfx,
289-
"C API: Test attributes with tiledb_blob datatype",
290-
"[capi][attributes][tiledb_blob]") {
289+
"C API: Test attributes with std::byte",
290+
"[capi][attributes][byte]") {
291+
auto datatype = GENERATE(TILEDB_BLOB, TILEDB_GEOM_WKB, TILEDB_GEOM_WKT);
292+
291293
SECTION("no serialization") {
292294
serialize_ = false;
293295
}
@@ -306,7 +308,7 @@ TEST_CASE_METHOD(
306308
continue;
307309
}
308310

309-
std::string attr_name = "attr";
311+
std::string attr_name = "a";
310312

311313
// Create new TileDB context with file lock config disabled, rest the
312314
// same.
@@ -324,7 +326,7 @@ TEST_CASE_METHOD(
324326

325327
create_temp_dir(temp_dir);
326328

327-
create_dense_vector(array_name, attr_name, TILEDB_BLOB);
329+
create_dense_vector(array_name, attr_name, datatype);
328330

329331
// Prepare cell buffers
330332
uint8_t buffer_write[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@@ -383,6 +385,7 @@ TEST_CASE_METHOD(
383385
rc = tiledb_query_set_data_buffer(
384386
ctx_, query, attr_name.c_str(), buffer_read, &buffer_read_size);
385387
CHECK(rc == TILEDB_OK);
388+
386389
rc = submit_query_wrapper(
387390
ctx_,
388391
array_name,

test/src/unit-cppapi-array.cc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,73 @@ TEST_CASE(
11981198
vfs.remove_dir(array_name);
11991199
}
12001200

1201+
TEST_CASE(
1202+
"C++ API: Writing single byte cell with global order",
1203+
"[cppapi][std::byte]") {
1204+
bool serialize = false, refactored_query_v2 = false;
1205+
const std::string array_name = "cpp_unit_array";
1206+
1207+
Context ctx;
1208+
VFS vfs(ctx);
1209+
if (vfs.is_dir(array_name)) {
1210+
vfs.remove_dir(array_name);
1211+
}
1212+
1213+
// Create
1214+
Domain domain(ctx);
1215+
domain.add_dimension(Dimension::create<int>(ctx, "rows", {{0, 0}}, 1));
1216+
ArraySchema schema(ctx, TILEDB_DENSE);
1217+
schema.set_domain(domain).set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}});
1218+
schema.add_attribute(
1219+
Attribute::create(ctx, "a", tiledb_datatype_t::TILEDB_BLOB));
1220+
Array::create(array_name, schema);
1221+
1222+
// Write
1223+
std::byte data_w{1};
1224+
Array array_w(ctx, array_name, TILEDB_WRITE);
1225+
Query query_w(ctx, array_w);
1226+
query_w.set_layout(TILEDB_GLOBAL_ORDER).set_data_buffer("a", &data_w, 1);
1227+
1228+
SECTION("no serialization") {
1229+
serialize = false;
1230+
}
1231+
#ifdef TILEDB_SERIALIZATION
1232+
SECTION("serialization enabled global order write") {
1233+
serialize = true;
1234+
refactored_query_v2 = GENERATE(true, false);
1235+
}
1236+
#endif
1237+
1238+
// Submit query
1239+
test::ServerQueryBuffers server_buffers_;
1240+
auto rc = test::submit_query_wrapper(
1241+
ctx,
1242+
array_name,
1243+
&query_w,
1244+
server_buffers_,
1245+
serialize,
1246+
refactored_query_v2);
1247+
REQUIRE(rc == TILEDB_OK);
1248+
array_w.close();
1249+
1250+
// Read
1251+
Array array(ctx, array_name, TILEDB_READ);
1252+
Query query(ctx, array);
1253+
Subarray subarray(ctx, array);
1254+
subarray.add_range(0, 0, 0);
1255+
std::byte data;
1256+
query.set_layout(TILEDB_ROW_MAJOR)
1257+
.set_subarray(subarray)
1258+
.set_data_buffer("a", &data, 1);
1259+
query.submit();
1260+
array.close();
1261+
1262+
REQUIRE(data == data_w);
1263+
1264+
if (vfs.is_dir(array_name))
1265+
vfs.remove_dir(array_name);
1266+
}
1267+
12011268
TEST_CASE("C++ API: Write cell with large cell val num", "[cppapi][sparse]") {
12021269
const std::string array_name = "cpp_unit_array";
12031270
Context ctx;

test/src/unit-enum-helpers.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2023 TileDB Inc.
8+
* @copyright Copyright (c) 2023-2024 TileDB Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -58,6 +58,8 @@ TEST_CASE(
5858
}
5959

6060
REQUIRE_THROWS(datatype_max_integral_value(Datatype::BLOB));
61+
REQUIRE_THROWS(datatype_max_integral_value(Datatype::GEOM_WKB));
62+
REQUIRE_THROWS(datatype_max_integral_value(Datatype::GEOM_WKT));
6163
REQUIRE_THROWS(datatype_max_integral_value(Datatype::FLOAT64));
6264
REQUIRE_THROWS(datatype_max_integral_value(Datatype::STRING_ASCII));
6365
}

tiledb/api/c_api/datatype/datatype_api_enum.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License
33
*
4-
* @copyright Copyright (c) 2022 TileDB, Inc.
4+
* @copyright Copyright (c) 2022-2024 TileDB, Inc.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -114,4 +114,8 @@
114114
TILEDB_DATATYPE_ENUM(BLOB) = 40,
115115
/** Boolean */
116116
TILEDB_DATATYPE_ENUM(BOOL) = 41,
117+
/** Geometry data in well-known binary (WKB) format, stored as std::byte */
118+
TILEDB_DATATYPE_ENUM(GEOM_WKB) = 42,
119+
/** Geometry data in well-known text (WKT) format, stored as std::byte */
120+
TILEDB_DATATYPE_ENUM(GEOM_WKT) = 43,
117121
#endif

tiledb/api/c_api/datatype/test/unit_capi_datatype.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2022 TileDB Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB Inc.
99
* @copyright Copyright (c) 2016 MIT and Intel Corporation
1010
*
1111
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -106,7 +106,9 @@ TEST_CASE(
106106
TestCase(TILEDB_TIME_FS, "TIME_FS", 38),
107107
TestCase(TILEDB_TIME_AS, "TIME_AS", 39),
108108
TestCase(TILEDB_BLOB, "BLOB", 40),
109-
TestCase(TILEDB_BOOL, "BOOL", 41));
109+
TestCase(TILEDB_BOOL, "BOOL", 41),
110+
TestCase(TILEDB_GEOM_WKB, "GEOM_WKB", 42),
111+
TestCase(TILEDB_GEOM_WKT, "GEOM_WKT", 43));
110112

111113
DYNAMIC_SECTION("[" << test.name_ << "]") {
112114
test.run();

tiledb/api/c_api/dimension/dimension_api_external.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2023 TileDB, Inc.
8+
* @copyright Copyright (c) 2023-2024 TileDB, Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -62,9 +62,9 @@ typedef struct tiledb_dimension_handle_t tiledb_dimension_t;
6262
*
6363
* Note: as laid out in the Storage Format,
6464
* the following Datatypes are not valid for Dimension:
65-
* TILEDB_CHAR, TILEDB_BLOB, TILEDB_BOOL, TILEDB_STRING_UTF8,
66-
* TILEDB_STRING_UTF16, TILEDB_STRING_UTF32, TILEDB_STRING_UCS2,
67-
* TILEDB_STRING_UCS4, TILEDB_ANY
65+
* TILEDB_CHAR, TILEDB_BLOB, TILEDB_GEOM_WKB, TILEDB_GEOM_WKT, TILEDB_BOOL,
66+
* TILEDB_STRING_UTF8, TILEDB_STRING_UTF16, TILEDB_STRING_UTF32,
67+
* TILEDB_STRING_UCS2, TILEDB_STRING_UCS4, TILEDB_ANY
6868
*
6969
* @param ctx The TileDB context.
7070
* @param name The dimension name.

tiledb/sm/array_schema/dimension.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2023 TileDB, Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB, Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -50,8 +50,7 @@ tiledb::common::blank<tiledb::sm::Dimension>::blank()
5050
: tiledb::sm::Dimension{"", tiledb::sm::Datatype::INT32} {
5151
}
5252

53-
namespace tiledb {
54-
namespace sm {
53+
namespace tiledb::sm {
5554

5655
class DimensionException : public StatusException {
5756
public:
@@ -1555,6 +1554,8 @@ void Dimension::ensure_datatype_is_supported(Datatype type) const {
15551554
switch (type) {
15561555
case Datatype::CHAR:
15571556
case Datatype::BLOB:
1557+
case Datatype::GEOM_WKB:
1558+
case Datatype::GEOM_WKT:
15581559
case Datatype::BOOL:
15591560
case Datatype::STRING_UTF8:
15601561
case Datatype::STRING_UTF16:
@@ -1795,5 +1796,4 @@ void Dimension::set_smaller_than_func() {
17951796
apply_with_type(g, type_);
17961797
}
17971798

1798-
} // namespace sm
1799-
} // namespace tiledb
1799+
} // namespace tiledb::sm

tiledb/sm/array_schema/dimension.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* The MIT License
77
*
8-
* @copyright Copyright (c) 2017-2021 TileDB, Inc.
8+
* @copyright Copyright (c) 2017-2024 TileDB, Inc.
99
*
1010
* Permission is hereby granted, free of charge, to any person obtaining a copy
1111
* of this software and associated documentation files (the "Software"), to deal
@@ -56,8 +56,7 @@ namespace tiledb::type {
5656
class Range;
5757
}
5858

59-
namespace tiledb {
60-
namespace sm {
59+
namespace tiledb::sm {
6160

6261
class Buffer;
6362
class ConstBuffer;
@@ -70,9 +69,9 @@ enum class Datatype : uint8_t;
7069
*
7170
* Note: as laid out in the Storage Format,
7271
* the following Datatypes are not valid for Dimension:
73-
* TILEDB_CHAR, TILEDB_BLOB, TILEDB_BOOL, TILEDB_STRING_UTF8,
74-
* TILEDB_STRING_UTF16, TILEDB_STRING_UTF32, TILEDB_STRING_UCS2,
75-
* TILEDB_STRING_UCS4, TILEDB_ANY
72+
* TILEDB_CHAR, TILEDB_BLOB, TILEDB_GEOM_WKB, TILEDB_GEOM_WKT, TILEDB_BOOL,
73+
* TILEDB_STRING_UTF8, TILEDB_STRING_UTF16, TILEDB_STRING_UTF32,
74+
* TILEDB_STRING_UCS2, TILEDB_STRING_UCS4, TILEDB_ANY
7675
*/
7776
class Dimension {
7877
public:
@@ -1085,8 +1084,7 @@ class Dimension {
10851084
void set_smaller_than_func();
10861085
};
10871086

1088-
} // namespace sm
1089-
} // namespace tiledb
1087+
} // namespace tiledb::sm
10901088

10911089
namespace tiledb::common {
10921090
template <>

0 commit comments

Comments
 (0)