Skip to content

Commit 4f99444

Browse files
shaunrd0davisp
authored andcommitted
Remove Status from datatype_enum. (TileDB-Inc#4780)
Removes Status from datatype_enum, returning `Datatype` instead. This also relocates `Subarray::LabelRangeSubset` to be public for use in TileDB-Inc#4685. --- TYPE: NO_HISTORY DESC: Remove Status from datatype_enum.
1 parent ae27122 commit 4f99444

File tree

7 files changed

+108
-111
lines changed

7 files changed

+108
-111
lines changed

tiledb/api/c_api/datatype/datatype_api.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ capi_return_t tiledb_datatype_to_str(
4545

4646
capi_return_t tiledb_datatype_from_str(
4747
const char* str, tiledb_datatype_t* datatype) {
48-
tiledb::sm::Datatype val = tiledb::sm::Datatype::UINT8;
49-
if (!tiledb::sm::datatype_enum(str, &val).ok()) {
50-
return TILEDB_ERR;
51-
}
52-
*datatype = (tiledb_datatype_t)val;
48+
*datatype = (tiledb_datatype_t)tiledb::sm::datatype_enum(str);
5349
return TILEDB_OK;
5450
}
5551

tiledb/sm/enums/datatype.h

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -235,100 +235,99 @@ inline const std::string& datatype_str(Datatype type) {
235235
}
236236

237237
/** Returns the datatype given a string representation. */
238-
inline Status datatype_enum(
239-
const std::string& datatype_str, Datatype* datatype) {
238+
inline Datatype datatype_enum(const std::string& datatype_str) {
240239
if (datatype_str == constants::int32_str)
241-
*datatype = Datatype::INT32;
240+
return Datatype::INT32;
242241
else if (datatype_str == constants::int64_str)
243-
*datatype = Datatype::INT64;
242+
return Datatype::INT64;
244243
else if (datatype_str == constants::float32_str)
245-
*datatype = Datatype::FLOAT32;
244+
return Datatype::FLOAT32;
246245
else if (datatype_str == constants::float64_str)
247-
*datatype = Datatype::FLOAT64;
246+
return Datatype::FLOAT64;
248247
else if (datatype_str == constants::char_str)
249-
*datatype = Datatype::CHAR;
248+
return Datatype::CHAR;
250249
else if (datatype_str == constants::blob_str)
251-
*datatype = Datatype::BLOB;
250+
return Datatype::BLOB;
252251
else if (datatype_str == constants::geom_wkb_str)
253-
*datatype = Datatype::GEOM_WKB;
252+
return Datatype::GEOM_WKB;
254253
else if (datatype_str == constants::geom_wkt_str)
255-
*datatype = Datatype::GEOM_WKT;
254+
return Datatype::GEOM_WKT;
256255
else if (datatype_str == constants::bool_str)
257-
*datatype = Datatype::BOOL;
256+
return Datatype::BOOL;
258257
else if (datatype_str == constants::int8_str)
259-
*datatype = Datatype::INT8;
258+
return Datatype::INT8;
260259
else if (datatype_str == constants::uint8_str)
261-
*datatype = Datatype::UINT8;
260+
return Datatype::UINT8;
262261
else if (datatype_str == constants::int16_str)
263-
*datatype = Datatype::INT16;
262+
return Datatype::INT16;
264263
else if (datatype_str == constants::uint16_str)
265-
*datatype = Datatype::UINT16;
264+
return Datatype::UINT16;
266265
else if (datatype_str == constants::uint32_str)
267-
*datatype = Datatype::UINT32;
266+
return Datatype::UINT32;
268267
else if (datatype_str == constants::uint64_str)
269-
*datatype = Datatype::UINT64;
268+
return Datatype::UINT64;
270269
else if (datatype_str == constants::string_ascii_str)
271-
*datatype = Datatype::STRING_ASCII;
270+
return Datatype::STRING_ASCII;
272271
else if (datatype_str == constants::string_utf8_str)
273-
*datatype = Datatype::STRING_UTF8;
272+
return Datatype::STRING_UTF8;
274273
else if (datatype_str == constants::string_utf16_str)
275-
*datatype = Datatype::STRING_UTF16;
274+
return Datatype::STRING_UTF16;
276275
else if (datatype_str == constants::string_utf32_str)
277-
*datatype = Datatype::STRING_UTF32;
276+
return Datatype::STRING_UTF32;
278277
else if (datatype_str == constants::string_ucs2_str)
279-
*datatype = Datatype::STRING_UCS2;
278+
return Datatype::STRING_UCS2;
280279
else if (datatype_str == constants::string_ucs4_str)
281-
*datatype = Datatype::STRING_UCS4;
280+
return Datatype::STRING_UCS4;
282281
else if (datatype_str == constants::any_str)
283-
*datatype = Datatype::ANY;
282+
return Datatype::ANY;
284283
else if (datatype_str == constants::datetime_year_str)
285-
*datatype = Datatype::DATETIME_YEAR;
284+
return Datatype::DATETIME_YEAR;
286285
else if (datatype_str == constants::datetime_month_str)
287-
*datatype = Datatype::DATETIME_MONTH;
286+
return Datatype::DATETIME_MONTH;
288287
else if (datatype_str == constants::datetime_week_str)
289-
*datatype = Datatype::DATETIME_WEEK;
288+
return Datatype::DATETIME_WEEK;
290289
else if (datatype_str == constants::datetime_day_str)
291-
*datatype = Datatype::DATETIME_DAY;
290+
return Datatype::DATETIME_DAY;
292291
else if (datatype_str == constants::datetime_hr_str)
293-
*datatype = Datatype::DATETIME_HR;
292+
return Datatype::DATETIME_HR;
294293
else if (datatype_str == constants::datetime_min_str)
295-
*datatype = Datatype::DATETIME_MIN;
294+
return Datatype::DATETIME_MIN;
296295
else if (datatype_str == constants::datetime_sec_str)
297-
*datatype = Datatype::DATETIME_SEC;
296+
return Datatype::DATETIME_SEC;
298297
else if (datatype_str == constants::datetime_ms_str)
299-
*datatype = Datatype::DATETIME_MS;
298+
return Datatype::DATETIME_MS;
300299
else if (datatype_str == constants::datetime_us_str)
301-
*datatype = Datatype::DATETIME_US;
300+
return Datatype::DATETIME_US;
302301
else if (datatype_str == constants::datetime_ns_str)
303-
*datatype = Datatype::DATETIME_NS;
302+
return Datatype::DATETIME_NS;
304303
else if (datatype_str == constants::datetime_ps_str)
305-
*datatype = Datatype::DATETIME_PS;
304+
return Datatype::DATETIME_PS;
306305
else if (datatype_str == constants::datetime_fs_str)
307-
*datatype = Datatype::DATETIME_FS;
306+
return Datatype::DATETIME_FS;
308307
else if (datatype_str == constants::datetime_as_str)
309-
*datatype = Datatype::DATETIME_AS;
308+
return Datatype::DATETIME_AS;
310309
else if (datatype_str == constants::time_hr_str)
311-
*datatype = Datatype::TIME_HR;
310+
return Datatype::TIME_HR;
312311
else if (datatype_str == constants::time_min_str)
313-
*datatype = Datatype::TIME_MIN;
312+
return Datatype::TIME_MIN;
314313
else if (datatype_str == constants::time_sec_str)
315-
*datatype = Datatype::TIME_SEC;
314+
return Datatype::TIME_SEC;
316315
else if (datatype_str == constants::time_ms_str)
317-
*datatype = Datatype::TIME_MS;
316+
return Datatype::TIME_MS;
318317
else if (datatype_str == constants::time_us_str)
319-
*datatype = Datatype::TIME_US;
318+
return Datatype::TIME_US;
320319
else if (datatype_str == constants::time_ns_str)
321-
*datatype = Datatype::TIME_NS;
320+
return Datatype::TIME_NS;
322321
else if (datatype_str == constants::time_ps_str)
323-
*datatype = Datatype::TIME_PS;
322+
return Datatype::TIME_PS;
324323
else if (datatype_str == constants::time_fs_str)
325-
*datatype = Datatype::TIME_FS;
324+
return Datatype::TIME_FS;
326325
else if (datatype_str == constants::time_as_str)
327-
*datatype = Datatype::TIME_AS;
326+
return Datatype::TIME_AS;
328327
else {
329-
return Status_Error("Invalid Datatype " + datatype_str);
328+
throw std::runtime_error(
329+
"Invalid Datatype string (\"" + datatype_str + "\")");
330330
}
331-
return Status::Ok();
332331
}
333332

334333
/** Returns true if the input datatype is a string type. */
@@ -440,12 +439,7 @@ inline void ensure_datatype_is_valid(Datatype type) {
440439
* the datatype string's enum is not between 0 and 43.
441440
**/
442441
inline void ensure_datatype_is_valid(const std::string& datatype_str) {
443-
Datatype datatype_type;
444-
Status st{datatype_enum(datatype_str, &datatype_type)};
445-
if (!st.ok()) {
446-
throw std::runtime_error(
447-
"Invalid Datatype string (\"" + datatype_str + "\")");
448-
}
442+
Datatype datatype_type = datatype_enum(datatype_str);
449443
ensure_datatype_is_valid(datatype_type);
450444
}
451445

tiledb/sm/serialization/array.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ Status metadata_from_capnp(
102102
auto entry_reader = entries_reader[i];
103103
auto key = std::string{std::string_view{
104104
entry_reader.getKey().cStr(), entry_reader.getKey().size()}};
105-
Datatype type = Datatype::UINT8;
106-
RETURN_NOT_OK(datatype_enum(entry_reader.getType(), &type));
105+
Datatype type = datatype_enum(entry_reader.getType());
107106
uint32_t value_num = entry_reader.getValueNum();
108107

109108
auto value_ptr = entry_reader.getValue();

tiledb/sm/serialization/array_schema.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ void attribute_to_capnp(
400400
shared_ptr<Attribute> attribute_from_capnp(
401401
const capnp::Attribute::Reader& attribute_reader) {
402402
// Get datatype
403-
Datatype datatype = Datatype::ANY;
404-
throw_if_not_ok(datatype_enum(attribute_reader.getType(), &datatype));
403+
Datatype datatype = datatype_enum(attribute_reader.getType());
405404

406405
// Set nullable
407406
const bool nullable = attribute_reader.getNullable();
@@ -614,8 +613,7 @@ shared_ptr<Dimension> dimension_from_capnp(
614613
Status st;
615614

616615
// Deserialize datatype
617-
Datatype dim_type;
618-
st = datatype_enum(dimension_reader.getType().cStr(), &dim_type);
616+
Datatype dim_type = datatype_enum(dimension_reader.getType().cStr());
619617
if (!st.ok()) {
620618
throw std::runtime_error(
621619
"[Deserialization::dimension_from_capnp] " +
@@ -783,8 +781,7 @@ shared_ptr<DimensionLabel> dimension_label_from_capnp(
783781
const capnp::DimensionLabel::Reader& dim_label_reader,
784782
shared_ptr<MemoryTracker> memory_tracker) {
785783
// Get datatype
786-
Datatype datatype = Datatype::ANY;
787-
throw_if_not_ok(datatype_enum(dim_label_reader.getType(), &datatype));
784+
Datatype datatype = datatype_enum(dim_label_reader.getType());
788785

789786
shared_ptr<ArraySchema> schema{nullptr};
790787
if (dim_label_reader.hasSchema()) {

tiledb/sm/serialization/enumeration.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ shared_ptr<const Enumeration> enumeration_from_capnp(
7575
shared_ptr<MemoryTracker> memory_tracker) {
7676
auto name = reader.getName();
7777
auto path_name = reader.getPathName();
78-
Datatype datatype = Datatype::ANY;
79-
throw_if_not_ok(datatype_enum(reader.getType(), &datatype));
78+
Datatype datatype = datatype_enum(reader.getType());
8079

8180
const void* data = nullptr;
8281
uint64_t data_size = 0;

tiledb/sm/serialization/query.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ Status subarray_from_capnp(
268268
uint32_t dim_num = ranges_reader.size();
269269
for (uint32_t i = 0; i < dim_num; i++) {
270270
auto range_reader = ranges_reader[i];
271-
Datatype type = Datatype::UINT8;
272-
RETURN_NOT_OK(datatype_enum(range_reader.getType(), &type));
273271

274272
auto data = range_reader.getBuffer();
275273
auto data_ptr = data.asBytes();

tiledb/sm/subarray/subarray.h

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,60 @@ class Subarray {
205205
uint64_t size_validity_;
206206
};
207207

208+
/**
209+
* Wrapper for optional<tuple<std::string, RangeSetAndSuperset>> for
210+
* cleaner data access.
211+
*/
212+
struct LabelRangeSubset {
213+
public:
214+
/**
215+
* Default constructor is not C.41.
216+
**/
217+
LabelRangeSubset() = delete;
218+
219+
/**
220+
* Constructor
221+
*
222+
* @param ref Dimension label the ranges will be set on.
223+
* @param coalesce_ranges Set if ranges should be combined when adjacent.
224+
*/
225+
LabelRangeSubset(const DimensionLabel& ref, bool coalesce_ranges = true);
226+
227+
/**
228+
* Constructor
229+
*
230+
* @param name The name of the dimension label the ranges will be set on.
231+
* @param type The type of the label the ranges will be set on.
232+
* @param coalesce_ranges Set if ranges should be combined when adjacent.
233+
*/
234+
LabelRangeSubset(
235+
const std::string& name, Datatype type, bool coalesce_ranges = true);
236+
237+
/**
238+
* Constructor
239+
*
240+
* @param name The name of the dimension label the ranges will be set on.
241+
* @param type The type of the label the ranges will be set on.
242+
* @param ranges The range subset for the dimension label.
243+
* @param coalesce_ranges Set if ranges should be combined when adjacent.
244+
*/
245+
LabelRangeSubset(
246+
const std::string& name,
247+
Datatype type,
248+
std::vector<Range> ranges,
249+
bool coalesce_ranges = true);
250+
251+
inline const std::vector<Range>& get_ranges() const {
252+
return ranges_.ranges();
253+
}
254+
255+
/** Name of the dimension label. */
256+
std::string name_;
257+
258+
/** The ranges set on the dimension label. */
259+
RangeSetAndSuperset ranges_;
260+
};
261+
208262
/* ********************************* */
209263
/* CONSTRUCTORS & DESTRUCTORS */
210264
/* ********************************* */
@@ -1351,46 +1405,6 @@ class Subarray {
13511405
uint64_t range_len_;
13521406
};
13531407

1354-
/**
1355-
* Wrapper for optional<tuple<std::string, RangeSetAndSuperset>> for
1356-
* cleaner data access.
1357-
*/
1358-
struct LabelRangeSubset {
1359-
public:
1360-
/**
1361-
* Default constructor is not C.41.
1362-
**/
1363-
LabelRangeSubset() = delete;
1364-
1365-
/**
1366-
* Constructor
1367-
*
1368-
* @param ref Dimension label the ranges will be set on.
1369-
* @param coalesce_ranges Set if ranges should be combined when adjacent.
1370-
*/
1371-
LabelRangeSubset(const DimensionLabel& ref, bool coalesce_ranges = true);
1372-
1373-
/**
1374-
* Constructor
1375-
*
1376-
* @param name The name of the dimension label the ranges will be set on.
1377-
* @param type The type of the label the ranges will be set on.
1378-
* @param coalesce_ranges Set if ranges should be combined when adjacent.
1379-
*/
1380-
LabelRangeSubset(
1381-
const std::string& name, Datatype type, bool coalesce_ranges = true);
1382-
1383-
inline const std::vector<Range>& get_ranges() const {
1384-
return ranges_.ranges();
1385-
}
1386-
1387-
/** Name of the dimension label. */
1388-
std::string name_;
1389-
1390-
/** The ranges set on the dimension label. */
1391-
RangeSetAndSuperset ranges_;
1392-
};
1393-
13941408
/**
13951409
* A hash function capable of hashing std::vector<uint8_t> for use by
13961410
* the tile_coords_map_ unordered_map for caching coords indices.

0 commit comments

Comments
 (0)