-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: [sc-58279] [core] add tiledb_array_schema_get_enumeration
API
#5359
Changes from all commits
b484eb6
c1efcf0
0a77551
dc2b5ae
5d5c3ba
d18cb94
0bf188d
754f239
2c2de31
adfcfea
efc7cea
2eeda89
9454c21
1f09625
d42551e
b9a5b46
4008d80
f13411d
7b42669
7ba3f5e
f0727b9
85ffae9
373c4c2
2967b0d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @file array_schema_helpers.cc | ||
* | ||
* @section LICENSE | ||
* | ||
* The MIT License | ||
* | ||
* @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 | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @section DESCRIPTION | ||
* | ||
* This file defines some array schema test suite helper functions. | ||
*/ | ||
|
||
#include "test/support/src/array_schema_helpers.h" | ||
#include "tiledb/api/c_api/enumeration/enumeration_api_internal.h" | ||
#include "tiledb/sm/array_schema/enumeration.h" | ||
#include "tiledb/sm/cpp_api/tiledb" | ||
|
||
using namespace tiledb; | ||
|
||
namespace tiledb::test { | ||
|
||
bool is_equivalent_enumeration( | ||
const Enumeration& left, const Enumeration& right) { | ||
return left.name() == right.name() && left.type() == right.type() && | ||
left.cell_val_num() == right.cell_val_num() && | ||
left.ordered() == right.ordered() && | ||
std::equal( | ||
left.ptr()->data().begin(), | ||
left.ptr()->data().end(), | ||
right.ptr()->data().begin(), | ||
right.ptr()->data().end()); | ||
} | ||
|
||
} // namespace tiledb::test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @file array_schema_helpers.h | ||
* | ||
* @section LICENSE | ||
* | ||
* The MIT License | ||
* | ||
* @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 | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
* @section DESCRIPTION | ||
* | ||
* This file declares some array schema test suite helper functions. | ||
*/ | ||
|
||
#ifndef TILEDB_TEST_ARRAY_SCHEMA_HELPERS_H | ||
#define TILEDB_TEST_ARRAY_SCHEMA_HELPERS_H | ||
|
||
#include "tiledb/sm/cpp_api/tiledb" | ||
#include "tiledb/sm/cpp_api/tiledb_experimental" | ||
|
||
namespace tiledb::test { | ||
|
||
/** | ||
* @return if two enumerations `left` and `right` are equivalent, | ||
* i.e. have the same name, datatype, variants, etc | ||
*/ | ||
bool is_equivalent_enumeration( | ||
const tiledb::Enumeration& left, const tiledb::Enumeration& right); | ||
|
||
} // namespace tiledb::test | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,8 @@ commence(object_library capi_array_schema_stub) | |
this_target_sources(${SOURCES}) | ||
this_target_link_libraries(export) | ||
this_target_object_libraries(array_schema) | ||
this_target_object_libraries(array) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because |
||
this_target_object_libraries(capi_attribute_stub) | ||
this_target_object_libraries(capi_context_stub) | ||
conclude(object_library) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
#include "array_schema_api_experimental.h" | ||
#include "array_schema_api_internal.h" | ||
|
||
#include "tiledb/api/c_api/attribute/attribute_api_external_experimental.h" | ||
#include "tiledb/api/c_api/attribute/attribute_api_internal.h" | ||
#include "tiledb/api/c_api/context/context_api_internal.h" | ||
#include "tiledb/api/c_api/current_domain/current_domain_api_external_experimental.h" | ||
|
@@ -181,6 +182,54 @@ capi_return_t tiledb_array_schema_timestamp_range( | |
return TILEDB_OK; | ||
} | ||
|
||
capi_return_t tiledb_array_schema_get_enumeration_from_name( | ||
tiledb_ctx_t* ctx, | ||
tiledb_array_schema_t* array_schema, | ||
const char* enumeration_name, | ||
tiledb_enumeration_t** enumeration) { | ||
ensure_array_schema_is_valid(array_schema); | ||
ensure_output_pointer_is_valid(enumeration); | ||
|
||
if (enumeration_name == nullptr) { | ||
throw CAPIException("'enumeration_name' must not be null"); | ||
} | ||
|
||
array_schema->load_enumeration(ctx, enumeration_name); | ||
|
||
auto ptr = array_schema->get_enumeration(enumeration_name); | ||
*enumeration = tiledb_enumeration_handle_t::make_handle(ptr); | ||
|
||
return TILEDB_OK; | ||
} | ||
|
||
capi_return_t tiledb_array_schema_get_enumeration_from_attribute_name( | ||
tiledb_ctx_t* ctx, | ||
tiledb_array_schema_t* array_schema, | ||
const char* attribute_name, | ||
tiledb_enumeration_t** enumeration) { | ||
ensure_array_schema_is_valid(array_schema); | ||
ensure_output_pointer_is_valid(enumeration); | ||
|
||
tiledb_attribute_t* attribute; | ||
capi_return_t getattr = tiledb_array_schema_get_attribute_from_name( | ||
rroelke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx, array_schema, attribute_name, &attribute); | ||
if (tiledb_status(getattr) != TILEDB_OK) { | ||
return getattr; | ||
} | ||
|
||
tiledb_string_t* enumeration_name_inner; | ||
capi_return_t getenmr = tiledb_attribute_get_enumeration_name( | ||
ctx, attribute, &enumeration_name_inner); | ||
if (tiledb_status(getenmr) != TILEDB_OK) { | ||
return getenmr; | ||
} | ||
|
||
std::string enumeration_name(enumeration_name_inner->view()); | ||
return api_entry_with_context< | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surprisingly I think the answer is "no" without making changes elsewhere.
and I was initially surprised to see that |
||
tiledb::api::tiledb_array_schema_get_enumeration_from_name>( | ||
ctx, array_schema, enumeration_name.c_str(), enumeration); | ||
} | ||
|
||
capi_return_t tiledb_array_schema_add_enumeration( | ||
tiledb_array_schema_t* array_schema, tiledb_enumeration_t* enumeration) { | ||
ensure_array_schema_is_valid(array_schema); | ||
|
@@ -365,6 +414,10 @@ capi_return_t tiledb_array_schema_get_attribute_from_name( | |
ensure_array_schema_is_valid(array_schema); | ||
ensure_output_pointer_is_valid(attr); | ||
|
||
if (name == nullptr) { | ||
throw CAPIException("'attribute_name' must not be null"); | ||
} | ||
|
||
uint32_t attribute_num = array_schema->attribute_num(); | ||
if (attribute_num == 0) { | ||
*attr = nullptr; | ||
|
@@ -540,6 +593,28 @@ CAPI_INTERFACE( | |
ctx, array_schema, lo, hi); | ||
} | ||
|
||
CAPI_INTERFACE( | ||
array_schema_get_enumeration_from_name, | ||
tiledb_ctx_t* ctx, | ||
tiledb_array_schema_t* array_schema, | ||
const char* enumeration_name, | ||
tiledb_enumeration_t** enumeration) { | ||
return api_entry_with_context< | ||
tiledb::api::tiledb_array_schema_get_enumeration_from_name>( | ||
ctx, array_schema, enumeration_name, enumeration); | ||
} | ||
|
||
CAPI_INTERFACE( | ||
array_schema_get_enumeration_from_attribute_name, | ||
tiledb_ctx_t* ctx, | ||
tiledb_array_schema_t* array_schema, | ||
const char* attribute_name, | ||
tiledb_enumeration_t** enumeration) { | ||
return api_entry_with_context< | ||
tiledb::api::tiledb_array_schema_get_enumeration_from_attribute_name>( | ||
ctx, array_schema, attribute_name, enumeration); | ||
} | ||
|
||
CAPI_INTERFACE( | ||
array_schema_add_enumeration, | ||
tiledb_ctx_t* ctx, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this here, I'm likely going to use it when you merge