Public
Edited
Aug 15, 2024
1 fork
Insert cell
Insert cell
getTableMemoryUsage(inputTable)
Insert cell
getTableMemoryUsage(outputTable)
Insert cell
Insert cell
tableSize = 10000
Insert cell
function repeatString(val, numRows) {
return arrow.vectorFromArray(
Array.from({ length: numRows }).fill(val),
new arrow.Dictionary(new arrow.Utf8, new arrow.Uint8),
)
}
Insert cell
inputTable = arrow.makeTable({
foo: repeatString("someRepeatedStringHere00000000", tableSize)
})
Insert cell
db = {
return tableSize && DuckDBClient.of({});
}
Insert cell
conn = await db._db.connect()
Insert cell
insertionComplete = {
const buffer = arrow.tableToIPC(inputTable, 'stream');
conn.insertArrowFromIPCStream(buffer, {
name: "arrowTable",
schema: "main"
});
return true;
}
Insert cell
outputTable = tableSize && insertionComplete && conn.query('SELECT * FROM arrowTable')
Insert cell
Insert cell
inputTable.getChild("foo")
Insert cell
inputTable.getChild("foo").get(0)
Insert cell
outputTable.getChild("foo")
Insert cell
outputTable.getChild("foo").get(0)
Insert cell
inputTable.batches.length === 1
Insert cell
outputTable.batches.length === 1
Insert cell
outputTable.batches[0].data.children[0]
Insert cell
inputTable.batches[0].data.children[0].values
Insert cell
outputTable.batches[0].data.children[0].values
Insert cell
inputTable.batches[0].data.children[0].dictionary.data[0].values
Insert cell
outputTable.batches[0].data.children[0].values
Insert cell
outputTable.batches[0].data.children[0].valueOffsets
Insert cell
getTableMemoryUsage = (t) => {
const typedArrs = [];
t.batches.forEach(b => {
if(b.data.children[0].dictionary === undefined) {
typedArrs.push(b.data.children[0].values);
typedArrs.push(b.data.children[0].valueOffsets);
} else {
typedArrs.push(b.data.children[0].values);
typedArrs.push(b.data.children[0].dictionary.data[0].values);
}
})
return typedArrs.map(a => a.length * a.BYTES_PER_ELEMENT).reduce((a, h) => a + h, 0);
}
Insert cell
// Reference: https://github.com/observablehq/feedback/issues/623#issuecomment-1999937586
arrow = await import('https://cdn.observableusercontent.com/npm/apache-arrow@11.0.0/+esm')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more