Skip to content

Commit

Permalink
User attributes handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paraseba committed Aug 1, 2024
1 parent 2282611 commit 8ea8577
Show file tree
Hide file tree
Showing 5 changed files with 312 additions and 95 deletions.
71 changes: 69 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ publish = false
[dependencies]
arrow = "52.2.0"
async-trait = "0.1.81"
rand = "0.8.5"

[profile.release-with-debug]
inherits = "release"
Expand Down
23 changes: 14 additions & 9 deletions src/dataset.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::sync::Arc;

use crate::{
AddNodeError, ArrayIndices, ArrayStructure, AttributesTable, ChunkPayload, Dataset,
GroupStructure, ManifestsTable, NodeStructure, Path, StructureTable, UpdateNodeError,
UserAttributes, ZarrArrayMetadata,
AddNodeError, ArrayIndices, AttributesTable, ChunkPayload, Dataset, ManifestsTable, NodeData,
NodeStructure, Path, StructureTable, UpdateNodeError, UserAttributes, ZarrArrayMetadata,
};

/// FIXME: what do we want to do with implicit groups?
Expand Down Expand Up @@ -47,11 +46,14 @@ impl Dataset {
) -> Result<(), UpdateNodeError> {
match self.get_node(&path).await {
None => Err(UpdateNodeError::NotFound),
Some(NodeStructure::Group(..)) => Err(UpdateNodeError::NotAnArray),
Some(NodeStructure::Array(..)) => {
Some(NodeStructure {
node_data: NodeData::Array(..),
..
}) => {
self.updated_arrays.insert(path, metadata);
Ok(())
}
Some(_) => Err(UpdateNodeError::NotAnArray),
}
}

Expand Down Expand Up @@ -81,11 +83,14 @@ impl Dataset {
) -> Result<(), UpdateNodeError> {
match self.get_node(&path).await {
None => Err(UpdateNodeError::NotFound),
Some(NodeStructure::Group(..)) => Err(UpdateNodeError::NotAnArray),
Some(NodeStructure::Array(..)) => {
Some(NodeStructure {
node_data: NodeData::Array(..),
..
}) => {
self.set_chunks.insert((path, coord), data);
Ok(())
}
Some(_) => Err(UpdateNodeError::NotAnArray),
}
}

Expand All @@ -101,10 +106,10 @@ impl Dataset {
structure.get_node(path)
}

pub async fn get_user_attributes(&self, path: Path) -> Option<UserAttributes> {
pub async fn get_user_attributes(&self, _path: Path) -> Option<UserAttributes> {
todo!()
}
pub async fn get_chunk(&self, path: Path, coord: ArrayIndices) -> ChunkPayload {
pub async fn get_chunk(&self, _path: Path, _coord: ArrayIndices) -> ChunkPayload {
todo!()
}

Expand Down
67 changes: 43 additions & 24 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ use std::{
};
use structure::StructureTable;

#[derive(Clone, Debug)]
pub enum NodeType {
Group,
Array,
}

/// An ND index to an element in an array.
pub type ArrayIndices = Vec<u64>;

Expand Down Expand Up @@ -194,30 +188,56 @@ pub type NodeId = u32;

/// The id of a file in object store
/// FIXME: should this be passed by ref everywhere?
pub type ObjectId = [u8; 16]; // FIXME: this doesn't need to be this big
#[derive(Debug, Hash, Clone, PartialEq, Eq)]
pub struct ObjectId([u8; 16]); // FIXME: this doesn't need to be this big

impl ObjectId {
const SIZE: usize = 16;

pub fn random() -> ObjectId {
ObjectId(rand::random())
}
}

impl TryFrom<&[u8]> for ObjectId {
type Error = &'static str;

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
let buf = value.try_into();
buf.map(ObjectId)
.map_err(|_| "Invalid ObjectId buffer length")
}
}

pub type ChunkOffset = u64;
pub type ChunkLength = u64;

type TableOffset = usize;
type TableLength = usize;
type TableOffset = u32;
type TableLength = u32;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TableRegion(TableOffset, TableLength);

#[derive(Debug, Clone, PartialEq, Eq)]
struct Flags(); // FIXME: implement

#[derive(Debug, Clone, PartialEq, Eq)]
struct UserAttributesRef {
object_id: ObjectId,
location: TableOffset,
flags: Flags,
}

#[derive(Debug, Clone, PartialEq, Eq)]
enum UserAttributesStructure {
Inline(UserAttributes),
Ref(UserAttributesRef),
}

#[derive(Debug, Clone, PartialEq)]
struct ManifestExtents(Vec<ArrayIndices>);

#[derive(Debug, Clone, PartialEq)]
struct ManifestRef {
object_id: ObjectId,
location: TableRegion,
Expand All @@ -234,29 +254,28 @@ pub struct ZarrArrayMetadata {
fill_value: FillValue,
codecs: Codecs,
storage_transformers: Option<StorageTransformers>,
// each dimension name can be null in Zarr
dimension_names: Option<Vec<Option<DimensionName>>>,
}

#[derive(Debug, PartialEq)]
pub struct ArrayStructure {
id: NodeId,
path: Path,
zarr_metadata: ZarrArrayMetadata,
//user_attributes: UserAttributesStructure,
//manifests: Vec<ManifestRef>,
#[derive(Clone, Debug)]
pub enum NodeType {
Group,
Array,
}

#[derive(Debug, PartialEq, Eq)]
pub struct GroupStructure {
id: NodeId,
path: Path,
//user_attributes: UserAttributesStructure,
#[derive(Debug, PartialEq)]
pub enum NodeData {
Array(ZarrArrayMetadata), //(manifests: Vec<ManifestRef>)
Group,
}

#[derive(Debug, PartialEq)]
pub enum NodeStructure {
Array(ArrayStructure),
Group(GroupStructure),
pub struct NodeStructure {
id: NodeId,
path: Path,
user_attributes: Option<UserAttributesStructure>,
node_data: NodeData,
}

pub struct VirtualChunkRef {
Expand Down
Loading

0 comments on commit 8ea8577

Please sign in to comment.