Skip to content

Commit

Permalink
Minor changes to assist cargo update in tables repo (#185)
Browse files Browse the repository at this point in the history
* Enumeration cell_val_num switch from u32 to CellValNum

* Add some 'pub use' based on common imports in tables
  • Loading branch information
rroelke authored Oct 22, 2024
1 parent 87c3897 commit a8b6ff4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
25 changes: 13 additions & 12 deletions tiledb/api/src/array/enumeration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::ops::Deref;
#[cfg(any(test, feature = "pod"))]
use std::fmt::{Debug, Formatter, Result as FmtResult};

use tiledb_common::array::CellValNum;

use crate::context::{CApiInterface, Context, ContextBound};
use crate::string::{RawTDBString, TDBString};
use crate::{Datatype, Result as TileDBResult};
Expand Down Expand Up @@ -71,18 +73,17 @@ impl Enumeration {
Ok(Datatype::try_from(dtype)?)
}

pub fn cell_val_num(&self) -> TileDBResult<u32> {
pub fn cell_val_num(&self) -> TileDBResult<CellValNum> {
let c_enmr = self.capi();
let mut c_cvn: u32 = 0;
self.capi_call(|ctx| unsafe {
ffi::tiledb_enumeration_get_cell_val_num(ctx, c_enmr, &mut c_cvn)
})?;

Ok(c_cvn)
Ok(CellValNum::try_from(c_cvn)?)
}

pub fn is_var_sized(&self) -> TileDBResult<bool> {
Ok(self.cell_val_num()? == u32::MAX)
Ok(self.cell_val_num()? == CellValNum::Var)
}

pub fn ordered(&self) -> TileDBResult<bool> {
Expand Down Expand Up @@ -235,7 +236,7 @@ pub struct Builder<'data, 'offsets> {
context: Context,
name: String,
dtype: Datatype,
cell_val_num: u32,
cell_val_num: CellValNum,
ordered: bool,
data: &'data [u8],
offsets: Option<&'offsets [u64]>,
Expand Down Expand Up @@ -278,14 +279,14 @@ impl<'data, 'offsets> Builder<'data, 'offsets> {
context: context.clone(),
name: name.to_owned(),
dtype,
cell_val_num: 1,
cell_val_num: CellValNum::single(),
ordered: false,
data,
offsets,
}
}

pub fn cell_val_num(self, cell_val_num: u32) -> Self {
pub fn cell_val_num(self, cell_val_num: CellValNum) -> Self {
Self {
cell_val_num,
..self
Expand All @@ -294,7 +295,7 @@ impl<'data, 'offsets> Builder<'data, 'offsets> {

pub fn var_sized(self) -> Self {
Self {
cell_val_num: u32::MAX,
cell_val_num: CellValNum::Var,
..self
}
}
Expand Down Expand Up @@ -330,7 +331,7 @@ impl<'data, 'offsets> Builder<'data, 'offsets> {
ctx,
c_name.as_c_str().as_ptr(),
c_dtype,
self.cell_val_num,
u32::from(self.cell_val_num),
if self.ordered { 1 } else { 0 },
self.data.as_ptr() as *const std::ffi::c_void,
std::mem::size_of_val(self.data) as u64,
Expand Down Expand Up @@ -459,7 +460,7 @@ mod tests {
let base = EnumerationData {
name: "foo".to_owned(),
datatype: Datatype::StringAscii,
cell_val_num: Some(u32::MAX),
cell_val_num: Some(CellValNum::Var),
ordered: Some(false),
data: Box::from("foobarbazbam".as_bytes()),
offsets: Some(Box::from(&vec![0, 3, 6, 9][..])),
Expand Down Expand Up @@ -523,7 +524,7 @@ mod tests {
let base = EnumerationData {
name: "foo".to_owned(),
datatype: Datatype::UInt8,
cell_val_num: Some(1),
cell_val_num: Some(CellValNum::single()),
ordered: Some(false),
data: Box::from(&vec![0u8, 1, 2, 3, 4, 5][..]),
offsets: None,
Expand All @@ -532,7 +533,7 @@ mod tests {
let enmr1 = base.create(&ctx)?;

let base2 = EnumerationData {
cell_val_num: Some(2),
cell_val_num: Some(CellValNum::try_from(2).unwrap()),
..base
};

Expand Down
2 changes: 2 additions & 0 deletions tiledb/common/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use proptest::prelude::*;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

pub use dimension::DimensionConstraints;

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum Mode {
Read,
Expand Down
3 changes: 3 additions & 0 deletions tiledb/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub mod metadata;
pub mod range;
pub mod vfs;

pub use datatype::Datatype;
pub use key::LookupKey;

mod private {
// The "sealed trait" pattern is a way to prevent downstream crates from implementing traits
// that you don't think they should implement. If you have `trait Foo: Sealed`, then
Expand Down
3 changes: 2 additions & 1 deletion tiledb/pod/src/array/enumeration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tiledb_utils::option::OptionSubset;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use tiledb_common::array::CellValNum;
use tiledb_common::datatype::Datatype;

/// Encapsulation of data needed to construct an Enumeration
Expand All @@ -16,7 +17,7 @@ use tiledb_common::datatype::Datatype;
pub struct EnumerationData {
pub name: String,
pub datatype: Datatype,
pub cell_val_num: Option<u32>,
pub cell_val_num: Option<CellValNum>,
pub ordered: Option<bool>,
pub data: Box<[u8]>,
pub offsets: Option<Box<[u64]>>,
Expand Down
3 changes: 2 additions & 1 deletion tiledb/pod/src/array/enumeration/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::cmp::Ordering;

use proptest::collection::vec;
use proptest::prelude::*;
use tiledb_common::array::CellValNum;
use tiledb_common::datatype::{Datatype, PhysicalType};
use tiledb_common::physical_type_go;

Expand All @@ -12,7 +13,7 @@ pub fn prop_enumeration_name() -> impl Strategy<Value = String> {
.expect("Error creating enumeration name strategy")
}

fn prop_cell_val_num() -> impl Strategy<Value = Option<u32>> {
fn prop_cell_val_num() -> impl Strategy<Value = Option<CellValNum>> {
Just(None)
}

Expand Down
6 changes: 6 additions & 0 deletions tiledb/pod/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ pub mod dimension;
pub mod domain;
pub mod enumeration;
pub mod schema;

pub use attribute::AttributeData;
pub use dimension::DimensionData;
pub use domain::DomainData;
pub use enumeration::EnumerationData;
pub use schema::SchemaData;

0 comments on commit a8b6ff4

Please sign in to comment.