put this in the APIs too: python, ts, rust

This commit is contained in:
Dan Tasse
2026-07-31 13:43:45 -04:00
parent 13b378814f
commit de7065ae50
10 changed files with 229 additions and 1 deletions
+27
View File
@@ -240,9 +240,36 @@ describe.each([arrow15, arrow16, arrow17, arrow18])(
numIndices: 0,
numRows: 3,
totalBytes: 44,
columnBytes: { id: 44 },
});
});
it("should report per-column bytes, including nested fields", async () => {
const conn = await connect(tmpDir.name);
const nested = await conn.createTable("nested_stats", [
{ id: 1, meta: { a: 1, b: "one" } },
{ id: 2, meta: { a: 2, b: "two" } },
]);
const stats = await nested.stats();
const columnBytes = stats.columnBytes!;
// Nested fields get their own dotted-path entries.
expect(Object.keys(columnBytes).sort()).toEqual([
"id",
"meta",
"meta.a",
"meta.b",
]);
expect(columnBytes["meta.a"]).toBeGreaterThan(0);
expect(columnBytes["meta.b"]).toBeGreaterThan(0);
// A struct's entry covers its whole subtree.
expect(columnBytes["meta"]).toBeGreaterThanOrEqual(
columnBytes["meta.a"] + columnBytes["meta.b"],
);
// Top-level entries alone sum to the table total.
expect(columnBytes["id"] + columnBytes["meta"]).toBe(stats.totalBytes);
});
it("should overwrite data if asked", async () => {
const addRes = await table.add([{ id: 1 }, { id: 2 }]);
expect(addRes).toHaveProperty("version");
+17
View File
@@ -1017,6 +1017,17 @@ pub struct TableStatistics {
/// Statistics on table fragments
pub fragment_stats: FragmentStatistics,
/// The compressed on-disk bytes of each column, keyed by dotted field path
/// ("meta", "meta.geo", "meta.geo.lat"). Every nesting level gets an entry
/// covering the field's own bytes plus its whole subtree, so a struct
/// reports its total while its children report the breakdown (the
/// top-level entries alone sum to `totalBytes`). Counts data-file bytes
/// only: blob sidecar payloads and index files are not included, and blob
/// columns therefore report just their descriptor bytes. Undefined when
/// the backend provides no per-column breakdown (e.g. older remote
/// servers).
pub column_bytes: Option<HashMap<String, i64>>,
}
#[napi(object)]
@@ -1074,6 +1085,12 @@ impl From<lancedb::table::TableStatistics> for TableStatistics {
p99: v.fragment_stats.lengths.p99 as i64,
},
},
column_bytes: v.column_bytes.map(|columns| {
columns
.into_iter()
.map(|(path, bytes)| (path, bytes as i64))
.collect()
}),
}
}
}