Pond arrow

node v10.24.1
version: 2.0.0
endpointsharetweet
const { Table, DateVector, FloatVector, predicate} = require("apache-arrow")
Function to build a table from the standard Pond TimeSeries JSON format:
const makeTable = (timeseries) => { const { name, columns, points } = timeseries; const length = points.length; // Timestamp array const times = new Array(length); // Setup named channels of Float32Arrays const channels = {}; columns.forEach(c => (channels[c] = new Float32Array(length))); // Fill each channel points.forEach((point, pointIndex) => { const [timestamp, ...values] = point; times[pointIndex] = timestamp; values.forEach((value, valueIndex) => { const channelName = columns[valueIndex]; channels[channelName][pointIndex] = value; }); }); const fieldNames = ["time", ...Object.keys(channels)]; const dateVector = DateVector.from(times); const valueVectors = Object.keys(channels).map(c => FloatVector.from(channels[c]) ); const table = Table.new([dateVector, ...valueVectors], fieldNames); return table; }
Here's some JSON, let's try it:
const data = { name: "weather", columns: ["temperature", "pressure"], points: [ [1594491206349, 92, 29.1], [1594491356349, 95, 28.8], [1594491456349, 91, 28.3], [1594491556349, 88, 27.2] ] };
const table = makeTable(data);
Print out what's in the table, at least I think toArray() should give me a list of Rows and then each of those has a toJSON() function on it, or you can use row.get("temperature") etc.
table.toArray().map(row => row.toJSON())
Ok, the big test, make a filter for pressures less than 28.5, of which there should be 2:
filtered = table.filter(predicate.col("pressure").lt(28.5))
Get the count of the filtered table:
filtered.count()
Looks good! But then when I iterate over the filtered table I get all rows:
filtered.toArray().map(row => row.toJSON())
That doesn't seem right. Scanning does work however:
filteredResult = []; filtered.scan((idx) => { const row = filtered.get(idx).toJSON(); filteredResult.push(row) }); filteredResult;
Loading…

no comments

    sign in to comment