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
3 changes: 1 addition & 2 deletions cmake/oxidize.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,9 @@ if (TILEDB_RUST)
set(bridge_h_src "${bridge_generated_dir}/src/${bridge}.h")
set(bridge_cc_src "${bridge_generated_dir}/src/${bridge}.cc")

string(REPLACE "-" "_" bridge_sanitize_relpath ${bridge_sanitize_relpath})
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not directly related to the PR description but was causing problems in some of my build environments.

I was building in $HOME/tiledb/TileDB-4 and the previous code was replacing that with $HOME/tiledb/TileDB_4 which was messing up include paths.

This correction only makes this substitution for the path components after tiledb/oxidize.

set(bridge_h_dst "${OXIDIZE_INCLUDE_DIR}/tiledb/oxidize/${bridge_sanitize_relpath}.h")
set(bridge_cc_dst "${OXIDIZE_INCLUDE_DIR}/tiledb/oxidize/${bridge_sanitize_relpath}.cc")
string(REPLACE "-" "_" bridge_h_dst ${bridge_h_dst})
string(REPLACE "-" "_" bridge_cc_dst ${bridge_cc_dst})

cmake_path(GET bridge_h_dst PARENT_PATH bridge_sanitize_dirname)

Expand Down
4 changes: 2 additions & 2 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ TEST_CASE_METHOD(
auto enmr_name = schema->attribute("attr1")->get_enumeration_name();
REQUIRE(enmr_name.has_value());

auto enmr_path = schema->get_enumeration_path_name(enmr_name.value());
auto enmr_path = schema->get_enumeration_path_name(enmr_name.value().get());

auto loaded =
ad->load_enumerations_from_paths({enmr_path}, enc_key_, memory_tracker_);
Expand Down Expand Up @@ -1292,7 +1292,7 @@ TEST_CASE_METHOD(
auto ad = get_array_directory();

auto enmr_name = schema->attribute("attr1")->get_enumeration_name();
auto enmr_path = schema->get_enumeration_path_name(enmr_name.value());
auto enmr_path = schema->get_enumeration_path_name(enmr_name.value().get());

memory_tracker_->set_budget(memory_tracker_->get_memory_usage() + 1);

Expand Down
8 changes: 7 additions & 1 deletion test/support/src/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,13 @@ void schema_equiv(
CHECK(a->name() == b->name());
CHECK(a->type() == b->type());
CHECK(a->nullable() == b->nullable());
CHECK(a->get_enumeration_name() == b->get_enumeration_name());

const auto a_enmr = a->get_enumeration_name(),
b_enmr = b->get_enumeration_name();
CHECK(a_enmr.has_value() == b_enmr.has_value());
if (a_enmr.has_value() && b_enmr.has_value()) {
CHECK(a_enmr.value().get() == b_enmr.value().get());
}
}
CHECK(schema1.capacity() == schema2.capacity());
CHECK(schema1.cell_order() == schema2.cell_order());
Expand Down
4 changes: 2 additions & 2 deletions tiledb/api/c_api/array_schema/array_schema_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ capi_return_t tiledb_array_schema_get_enumeration_from_attribute_name(
return TILEDB_OK;
}

array_schema->load_enumeration(ctx, enumeration_name->c_str());
array_schema->load_enumeration(ctx, enumeration_name->get().c_str());

auto ptr = array_schema->get_enumeration(enumeration_name->c_str());
auto ptr = array_schema->get_enumeration(enumeration_name->get().c_str());
*enumeration = tiledb_enumeration_handle_t::make_handle(ptr);

return TILEDB_OK;
Expand Down
7 changes: 6 additions & 1 deletion tiledb/api/c_api/attribute/attribute_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ struct tiledb_attribute_handle_t
* Facade for `Attribute` function
*/
[[nodiscard]] std::optional<std::string> get_enumeration_name() const {
return attr_->get_enumeration_name();
const auto eref = attr_->get_enumeration_name();
if (eref.has_value()) {
return eref.value().get();
} else {
return std::nullopt;
}
};
/**
* Facade for `Attribute` function
Expand Down
24 changes: 21 additions & 3 deletions tiledb/oxidize/cxx-interface/cc/array_schema.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
#include "tiledb/oxidize/cxx-interface/cc/array_schema.h"

namespace tiledb::oxidize {

using namespace tiledb::sm;

namespace tiledb::oxidize::sm {

namespace attribute {

const std::string* enumeration_name_cxx(const Attribute& attribute) {
std::optional<std::reference_wrapper<const std::string>> e =
attribute.get_enumeration_name();
if (e.has_value()) {
return &e.value().get();
} else {
return nullptr;
}
}

} // namespace attribute

namespace dimension {

void set_domain(Dimension& dimension, rust::Slice<const uint8_t> domain) {
dimension.set_domain(static_cast<const void*>(domain.data()));
}
Expand All @@ -12,4 +28,6 @@ void set_tile_extent(Dimension& dimension, rust::Slice<const uint8_t> domain) {
dimension.set_tile_extent(static_cast<const void*>(domain.data()));
}

} // namespace tiledb::oxidize
} // namespace dimension

} // namespace tiledb::oxidize::sm
19 changes: 16 additions & 3 deletions tiledb/oxidize/cxx-interface/cc/array_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,27 @@
#include "tiledb/sm/array_schema/dimension.h"
#include "tiledb/sm/array_schema/domain.h"

namespace tiledb::oxidize {
namespace tiledb::oxidize::sm {

using namespace tiledb::sm;

namespace attribute {

using ConstAttribute = const Attribute;
using ConstDimension = const Dimension;

const std::string* enumeration_name_cxx(const Attribute& attribute);

} // namespace attribute

namespace dimension {

using namespace tiledb::sm;

using ConstDimension = const tiledb::sm::Dimension;

void set_domain(Dimension& dimension, rust::Slice<const uint8_t> domain);
void set_tile_extent(Dimension& dimension, rust::Slice<const uint8_t> domain);

} // namespace tiledb::oxidize
} // namespace dimension

} // namespace tiledb::oxidize::sm
53 changes: 49 additions & 4 deletions tiledb/oxidize/cxx-interface/src/sm/array_schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod ffi {
type Layout = crate::sm::enums::Layout;
}

#[namespace = "tiledb::oxidize"]
#[namespace = "tiledb::oxidize::sm::attribute"]
unsafe extern "C++" {
include!("tiledb/oxidize/cxx-interface/cc/array_schema.h");
type ConstAttribute;
Expand All @@ -26,6 +26,9 @@ mod ffi {
#[cxx_name = "type"]
fn datatype(&self) -> Datatype;

#[namespace = "tiledb::oxidize::sm::attribute"]
fn enumeration_name_cxx(attr: &Attribute) -> *const CxxString;

fn set_cell_val_num(self: Pin<&mut Attribute>, cell_val_num: u32);
}

Expand All @@ -42,10 +45,10 @@ mod ffi {
#[cxx_name = "type"]
fn datatype(&self) -> Datatype;

#[namespace = "tiledb::oxidize"]
#[namespace = "tiledb::oxidize::sm::dimension"]
fn set_domain(dimension: Pin<&mut Dimension>, domain: &[u8]) -> Result<()>;

#[namespace = "tiledb::oxidize"]
#[namespace = "tiledb::oxidize::sm::dimension"]
fn set_tile_extent(dimension: Pin<&mut Dimension>, extent: &[u8]) -> Result<()>;
}

Expand All @@ -63,6 +66,19 @@ mod ffi {
fn add_dimension(self: Pin<&mut Domain>, dim: SharedPtr<Dimension>);
}

#[namespace = "tiledb::sm"]
unsafe extern "C++" {
include!("tiledb/sm/array_schema/enumeration.h");

type Enumeration;

#[cxx_name = "cell_val_num"]
fn cell_val_num_cxx(&self) -> u32;

#[cxx_name = "type"]
fn datatype(&self) -> Datatype;
}

#[namespace = "tiledb::sm"]
unsafe extern "C++" {
include!("tiledb/sm/array_schema/array_schema.h");
Expand Down Expand Up @@ -117,7 +133,7 @@ use std::str::Utf8Error;

use num_traits::ToBytes;

pub use ffi::{ArraySchema, Attribute, ConstAttribute, Datatype, Dimension, Domain};
pub use ffi::{ArraySchema, Attribute, ConstAttribute, Datatype, Dimension, Domain, Enumeration};

#[derive(Debug)]
pub enum CellValNum {
Expand Down Expand Up @@ -222,6 +238,19 @@ impl Attribute {
// SAFETY: non-zero would have been validated by the ArraySchema
CellValNum::from_cxx(cxx).unwrap()
}

pub fn enumeration_name_cxx(&self) -> *const cxx::CxxString {
ffi::enumeration_name_cxx(self)
}

pub fn enumeration_name(&self) -> Option<Result<&str, Utf8Error>> {
let ptr = self.enumeration_name_cxx();
if ptr.is_null() {
return None;
}
let cxx = unsafe { &*ptr };
Some(cxx.to_str())
}
}

impl Debug for Attribute {
Expand Down Expand Up @@ -274,6 +303,22 @@ impl Field<'_> {
Self::Dimension(_) => false,
}
}

pub fn enumeration_name(&self) -> Option<Result<&str, Utf8Error>> {
match self {
Self::Attribute(a) => a.enumeration_name(),
Self::Dimension(_) => None,
}
}
}

impl Enumeration {
pub fn cell_val_num(&self) -> CellValNum {
let cxx = self.cell_val_num_cxx();

// SAFETY: non-zero would have been validated by the ArraySchema
CellValNum::from_cxx(cxx).unwrap()
}
}

impl ArraySchema {
Expand Down
2 changes: 1 addition & 1 deletion tiledb/oxidize/test-support/cxx-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod ffi {
type ResultTile = tiledb_cxx_interface::sm::query::readers::ResultTile;
}

#[namespace = "tiledb::oxidize"]
#[namespace = "tiledb::oxidize::sm::attribute"]
extern "C++" {
type ConstAttribute = tiledb_cxx_interface::sm::array_schema::ConstAttribute;
}
Expand Down
13 changes: 7 additions & 6 deletions tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -806,13 +806,13 @@ void ArraySchema::add_attribute(

auto enmr_name = attr->get_enumeration_name();
if (enmr_name.has_value()) {
// The referenced enumeration must exist when the attribut is added
auto iter = enumeration_map_.find(enmr_name.value());
// The referenced enumeration must exist when the attribute is added
auto iter = enumeration_map_.find(enmr_name.value().get());
if (iter == enumeration_map_.end()) {
std::string msg =
"Cannot add attribute; Attribute refers to an "
"unknown enumeration named '" +
enmr_name.value() + "'.";
enmr_name.value().get() + "'.";
throw ArraySchemaException(msg);
}

Expand All @@ -835,14 +835,15 @@ void ArraySchema::add_attribute(
auto enmr = get_enumeration(enmr_name.value());
if (enmr == nullptr) {
throw ArraySchemaException(
"Cannot add attribute referencing enumeration '" + enmr_name.value() +
"Cannot add attribute referencing enumeration '" +
enmr_name.value().get() +
"' as the enumeration has not been loaded.");
}

// The +1 here is because of 0 being a valid index into the enumeration.
if (datatype_max_integral_value(attr->type()) <= enmr->elem_count()) {
throw ArraySchemaException(
"Unable to use enumeration '" + enmr_name.value() +
"Unable to use enumeration '" + enmr_name.value().get() +
"' for attribute '" + attr->name() +
"' because the attribute's type is not large enough to represent "
"all enumeration values.");
Expand Down Expand Up @@ -1147,7 +1148,7 @@ void ArraySchema::drop_enumeration(const std::string& enmr_name) {
if (!attr_enmr_name.has_value()) {
continue;
}
if (attr_enmr_name.value() == enmr_name) {
if (attr_enmr_name.value().get() == enmr_name) {
throw ArraySchemaException(
"Unable to drop enumeration '" + enmr_name + "' as it is used by" +
" attribute '" + attr->name() + "'.");
Expand Down
5 changes: 3 additions & 2 deletions tiledb/sm/array_schema/attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ void Attribute::set_enumeration_name(std::optional<std::string> enmr_name) {
enumeration_name_ = enmr_name;
}

std::optional<std::string> Attribute::get_enumeration_name() const {
std::optional<std::reference_wrapper<const std::string>>
Attribute::get_enumeration_name() const {
return enumeration_name_;
}

Expand Down Expand Up @@ -496,7 +497,7 @@ std::ostream& operator<<(std::ostream& os, const tiledb::sm::Attribute& a) {
}
if (a.get_enumeration_name().has_value()) {
os << std::endl;
os << "- Enumeration name: " << a.get_enumeration_name().value();
os << "- Enumeration name: " << a.get_enumeration_name().value().get();
}
os << std::endl;

Expand Down
3 changes: 2 additions & 1 deletion tiledb/sm/array_schema/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class Attribute {
void set_enumeration_name(std::optional<std::string> enmr_name);

/** Get the enumeration for this attribute. */
std::optional<std::string> get_enumeration_name() const;
std::optional<std::reference_wrapper<const std::string>>
get_enumeration_name() const;

private:
/* ********************************* */
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/query/ast/query_ast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void ASTNodeVal::rewrite_for_schema(const ArraySchema& array_schema) {
return;
}

auto enumeration = array_schema.get_enumeration(enmr_name.value());
auto enumeration = array_schema.get_enumeration(enmr_name.value().get());
if (!enumeration) {
throw std::logic_error(
"Missing required enumeration for field '" + field_name_ + "'");
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/query/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ Status Query::process() {
}
auto enmr_name = attr->get_enumeration_name();
if (enmr_name.has_value()) {
deduped_enmr_names.insert(enmr_name.value());
deduped_enmr_names.insert(enmr_name.value().get());
}
}
std::vector<std::string> enmr_names;
Expand Down
2 changes: 1 addition & 1 deletion tiledb/sm/serialization/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void attribute_to_capnp(

auto enmr_name = attribute->get_enumeration_name();
if (enmr_name.has_value()) {
attribute_builder->setEnumerationName(enmr_name.value());
attribute_builder->setEnumerationName(enmr_name.value().get());
}
}

Expand Down
Loading