MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / rechunk_sparse

Function rechunk_sparse

nodedb-array/src/query/rechunk.rs:27–77  ·  view source on GitHub ↗

Re-bucket every cell in `tile` according to `target_schema.tile_extents`. Returns one entry per resulting target tile, ordered by [`TileId`].

(
    target_schema: &ArraySchema,
    tile: &SparseTile,
)

Source from the content-addressed store, hash-verified

25/// Re-bucket every cell in `tile` according to `target_schema.tile_extents`.
26/// Returns one entry per resulting target tile, ordered by [`TileId`].
27pub fn rechunk_sparse(
28 target_schema: &ArraySchema,
29 tile: &SparseTile,
30) -> ArrayResult<Vec<(TileId, SparseTile)>> {
31 let n = tile.row_count();
32 let mut live_idx = 0usize;
33 let mut buckets: BTreeMap<TileId, SparseTileBuilder<'_>> = BTreeMap::new();
34 for row in 0..n {
35 // Sentinel rows are not re-bucketed; rechunk is a purely spatial
36 // operation on live cell data.
37 if tile.row_kind(row)? != RowKind::Live {
38 continue;
39 }
40 let attr_row = live_idx;
41 live_idx += 1;
42 let coord: Vec<CoordValue> = tile
43 .dim_dicts
44 .iter()
45 .map(|d| d.values[d.indices[row] as usize].clone())
46 .collect();
47 let attrs: Vec<CellValue> = tile
48 .attr_cols
49 .iter()
50 .map(|col| col[attr_row].clone())
51 .collect();
52 let surrogate = tile
53 .surrogates
54 .get(row)
55 .copied()
56 .unwrap_or(nodedb_types::Surrogate::ZERO);
57 let valid_from_ms = tile.valid_from_ms.get(row).copied().unwrap_or(0);
58 let valid_until_ms = tile
59 .valid_until_ms
60 .get(row)
61 .copied()
62 .unwrap_or(nodedb_types::OPEN_UPPER);
63 let tid = tile_id_for_cell(target_schema, &coord, 0)?;
64 let entry = buckets
65 .entry(tid)
66 .or_insert_with(|| SparseTileBuilder::new(target_schema));
67 entry.push_row(SparseRow {
68 coord: &coord,
69 attrs: &attrs,
70 surrogate,
71 valid_from_ms,
72 valid_until_ms,
73 kind: crate::tile::sparse_tile::RowKind::Live,
74 })?;
75 }
76 Ok(buckets.into_iter().map(|(k, v)| (k, v.build())).collect())
77}
78
79#[cfg(test)]
80mod tests {

Calls 10

tile_id_for_cellFunction · 0.85
row_kindMethod · 0.80
collectMethod · 0.80
entryMethod · 0.80
push_rowMethod · 0.80
row_countMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
getMethod · 0.45
buildMethod · 0.45

Tested by 2