Skip to content

Commit

Permalink
feat: use separate directory for downsampling data
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Sep 19, 2023
1 parent 2152181 commit 57217da
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions examples/basic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,16 @@ async function main() {
console.log(`max is ${row.max}`)
}

const downsamplingQuery = `\
SELECT
date_bin('5 minutes', "time") as window_start,
AVG("avg") as avg,
MAX("max") as max
FROM "stat"
WHERE
"time" >= now() - interval '1 hour'
GROUP BY window_start
ORDER BY window_start DESC;`

// Execute downsampling query into pointValues
// Execute query again as points
const queryPointsResult = client.queryPoints(
downsamplingQuery,
query,
database,
queryType
)

for await (const row of queryPointsResult) {
console.log(`avg is ${row.getField('avg', 'float')}`)
console.log(`max is ${row.getField('max', 'float')}`)

// write back downsampled point
const point = row.asPoint('stat_downsampled')
const windowStart = point.getFloatField('window_start') as number
point.setTimestamp(windowStart)

await client.write(point, database, undefined, {
precision: 'ms',
})
}
} catch (err) {
console.error(err)
Expand Down

0 comments on commit 57217da

Please sign in to comment.