Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package: Analytics Engine #399

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6319887
first up
CraigglesO Oct 1, 2022
e6351c5
remove TODOs; adjust readmes
CraigglesO Oct 1, 2022
6eac0a4
migrate to execute sql data inside engine code
CraigglesO Oct 1, 2022
3ae1bfd
parse INTERVAL; add test cases
CraigglesO Oct 2, 2022
da11a07
interval, complete test cases
CraigglesO Oct 2, 2022
b307341
add miniflare api access + tests; drop 'UNIQUE'
CraigglesO Oct 2, 2022
a5d2fee
fix options; all analytics exists inside singular db now
CraigglesO Oct 2, 2022
cc1547d
add jest testings
CraigglesO Oct 2, 2022
5fb6b54
add jest testings
CraigglesO Oct 2, 2022
b2810df
fix get->all; add http testing in minfilare; remove unique
CraigglesO Oct 2, 2022
11b2692
add vitest tests
CraigglesO Oct 2, 2022
13916f2
fix internal problem
CraigglesO Oct 2, 2022
d798479
TODATETIME fix
CraigglesO Oct 2, 2022
9b359ac
support QUANTILEWEIGHTED
CraigglesO Oct 3, 2022
39ed5cf
support QUANTILEWEIGHTED
CraigglesO Oct 3, 2022
7cb5d40
add formatting; minor fixes/adjustments
CraigglesO Oct 3, 2022
556d5eb
import sorting fix
CraigglesO Oct 3, 2022
16b28f0
more error cases
CraigglesO Oct 4, 2022
7abffeb
re-arrange
CraigglesO Oct 4, 2022
8e1e310
writeDataPoint is sync
CraigglesO Oct 4, 2022
44dc3d8
minor fixes
CraigglesO Oct 4, 2022
c25b639
ensure added functions & keywords are working
CraigglesO Oct 5, 2022
5865e9e
temporarily edit npx-import to get passing tests
CraigglesO Oct 6, 2022
62f63d5
pre-add better-sqlite
CraigglesO Oct 6, 2022
55b1d93
tmp move npx-import
CraigglesO Oct 6, 2022
ca5fe4f
ensure TODATETIME sticks to UTC
CraigglesO Oct 6, 2022
aabd9fb
update to latest master
CraigglesO Oct 24, 2022
c9b272d
first fix set
CraigglesO Oct 24, 2022
f93f54e
bug fixes
CraigglesO Oct 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
writeDataPoint is sync
  • Loading branch information
CraigglesO committed Oct 4, 2022
commit 8e1e310d8882afae0ccc43ec8e476ee18f181b8d
2 changes: 1 addition & 1 deletion packages/analytics-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createSQLiteDB } from "@miniflare/shared";

const db = new AnalyticsEngine("DATASET_NAME", await createSQLiteDB(":memory:"));

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["a3cd45"], // Sensor ID
blobs: ["Seattle", "USA", "pro_sensor_9000"], // City, Country, Sensor
doubles: [25, 0.5], // Temperature, Humidity
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics-engine/src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ export class AnalyticsEngine {
buildSQLFunctions(db);
}

async writeDataPoint({
writeDataPoint({
indexes = [],
doubles = [],
blobs = [],
}: AnalyticsEngineEvent): Promise<void> {
}: AnalyticsEngineEvent): void {
const decoder = this.#decoder;
for (const blob of blobs) {
if (
Expand Down
56 changes: 28 additions & 28 deletions packages/analytics-engine/test/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("Analytics Engine: Write a data point using indexes, blobs, and doubles.",
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["t1"],
blobs: ["a", "b", "c"],
doubles: [0, 1, 2],
Expand Down Expand Up @@ -92,7 +92,7 @@ test("Analytics Engine: Write a data point with no data provided.", async (t) =>
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({});
db.writeDataPoint({});

// grab data from sqliteDB
const stmt = sqliteDB.prepare("SELECT * FROM TEST_DATASET");
Expand Down Expand Up @@ -151,7 +151,7 @@ test("Analytics Engine: Write a data point filling indexes, blobs, and doubles."
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["t1"],
blobs: [
"a",
Expand Down Expand Up @@ -239,7 +239,7 @@ test("Analytics Engine: Store AB", async (t) => {

const blob1 = Buffer.from("test string", "utf-8");

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["t1"],
blobs: [new Uint8Array(blob1).buffer],
});
Expand All @@ -257,7 +257,7 @@ test("Analytics Engine: Minimal example test.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["a3cd45"], // Sensor ID
blobs: ["Seattle", "USA", "pro_sensor_9000"],
doubles: [25, 0.5],
Expand Down Expand Up @@ -290,9 +290,9 @@ test("Analytics Engine: Minimal example test.", async (t) => {
test("Analytics Engine: More than one index fails.", async (t) => {
const { db } = t.context;

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1", "t2"],
blobs: ["a", "b", "c"],
doubles: [0, 1, 2],
Expand All @@ -307,9 +307,9 @@ test("Analytics Engine: More than one index fails.", async (t) => {
test("Analytics Engine: More than twenty blobs fails.", async (t) => {
const { db } = t.context;

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1"],
blobs: [
"1",
Expand Down Expand Up @@ -345,9 +345,9 @@ test("Analytics Engine: More than twenty blobs fails.", async (t) => {
test("Analytics Engine: More than twenty doubles fails.", async (t) => {
const { db } = t.context;

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1"],
doubles: [
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
Expand All @@ -368,9 +368,9 @@ test("Analytics Engine: More than 50kB of blob data fails.", async (t) => {
const blob1 = Buffer.alloc(50_000);
const blob2 = Buffer.alloc(5);

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1"],
blobs: [new Uint8Array(blob1).buffer, new Uint8Array(blob2).buffer],
});
Expand All @@ -386,9 +386,9 @@ test("Analytics Engine: blobs with bad inputs", async (t) => {

const blob1 = Buffer.alloc(5);

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1"],
// @ts-expect-error: We are purposely throwing
blobs: [new Uint8Array(blob1).buffer, "2", null, 4],
Expand All @@ -403,9 +403,9 @@ test("Analytics Engine: blobs with bad inputs", async (t) => {
test("Analytics Engine: doubles with bad inputs", async (t) => {
const { db } = t.context;

await t.throwsAsync(
async () => {
await db.writeDataPoint({
t.throws(
() => {
db.writeDataPoint({
indexes: ["t1"],
// @ts-expect-error: We are purposely throwing
doubles: [1, "2"],
Expand All @@ -422,7 +422,7 @@ test("Analytics Engine: Test FORMAT JSON.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["formatJSON"], // Sensor ID
blobs: ["input"],
doubles: [0, 3],
Expand Down Expand Up @@ -451,12 +451,12 @@ test("Analytics Engine: Test FORMAT JSONEachRow.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["formatJSONEachRow"], // Sensor ID
blobs: ["input"],
doubles: [0, 1],
});
await db.writeDataPoint({
db.writeDataPoint({
indexes: ["formatJSONEachRow"], // Sensor ID
blobs: ["input"],
doubles: [2, 3],
Expand Down Expand Up @@ -484,12 +484,12 @@ test("Analytics Engine: Test FORMAT TabSeparated.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["formatTabSeparated"], // Sensor ID
blobs: ["input"],
doubles: [0, 1],
});
await db.writeDataPoint({
db.writeDataPoint({
indexes: ["formatTabSeparated"], // Sensor ID
blobs: ["input"],
doubles: [2, 3],
Expand Down
10 changes: 5 additions & 5 deletions packages/analytics-engine/test/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ test("Analytics Engine: Test each function to ensure they work.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["a3cd45"], // Sensor ID
blobs: ["input"],
doubles: [0.5, 1, 50, 1_000, 10_000],
Expand Down Expand Up @@ -176,22 +176,22 @@ test("Analytics Engine: Test quantileWeighted.", async (t) => {
// @ts-expect-error: protected but does exist
const { sqliteDB } = storage;

await db.writeDataPoint({
db.writeDataPoint({
indexes: ["qw"], // Sensor ID
blobs: ["input"],
doubles: [0, 3],
});
await db.writeDataPoint({
db.writeDataPoint({
indexes: ["qw"], // Sensor ID
blobs: ["input"],
doubles: [2, 1],
});
await db.writeDataPoint({
db.writeDataPoint({
indexes: ["qw"], // Sensor ID
blobs: ["input"],
doubles: [5, 4],
});
await db.writeDataPoint({
db.writeDataPoint({
indexes: ["qw"], // Sensor ID
blobs: ["input"],
doubles: [1, 2],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async function get() {
}

test("AE test 1", async () => {
await AE_TEST_DB.writeDataPoint({
AE_TEST_DB.writeDataPoint({
blobs: ["a", "b", "c"],
doubles: [0, 1, 2],
});
Expand Down
4 changes: 2 additions & 2 deletions packages/miniflare/test/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test("Miniflare: getAnalyticsEngine: gets Analytics Engine from bindings", async
const mf = new Miniflare({
script: `export default {
fetch: async (request, env) => {
return new Response(await env.TEST_DB.writeDataPoint({ blobs: ['a', 'b'], doubles: [1, 2] }));
return new Response(env.TEST_DB.writeDataPoint({ blobs: ['a', 'b'], doubles: [1, 2] }));
}
}`,
modules: true,
Expand All @@ -70,7 +70,7 @@ test("Miniflare: getAnalyticsEngine: gets Analytics Engine from bindings", async
const port = (server.address() as AddressInfo).port;
await mf.dispatchFetch("http:https://localhost/");
const ae = await mf.getAnalyticsEngine("TEST_DB");
await ae.writeDataPoint({ blobs: ["c", "d"], doubles: [3, 4] });
ae.writeDataPoint({ blobs: ["c", "d"], doubles: [3, 4] });
const res = await fetch(
`http:https://localhost:${port}/cdn-cgi/mf/analytics_engine/sql`,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async function get() {
}

test("AE test 1", async () => {
await AE_TEST_DB.writeDataPoint({
AE_TEST_DB.writeDataPoint({
blobs: ["a", "b", "c"],
doubles: [0, 1, 2],
});
Expand Down