Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4f91839
Bulldozer DB
N2D4 Mar 24, 2026
9694c33
declareGroupByTable
N2D4 Mar 24, 2026
09ba416
Fix Prisma schema
N2D4 Mar 24, 2026
4232a94
declareMapTable
N2D4 Mar 24, 2026
31b6ac6
Performance tests
N2D4 Mar 24, 2026
2f7f09a
Load tests
N2D4 Mar 24, 2026
863ee05
Interface updates
N2D4 Mar 24, 2026
109cf5d
Bulldozer Studio
N2D4 Mar 25, 2026
53f7302
Remove unnecessary table
N2D4 Mar 25, 2026
006cf5e
Add flat map interface
N2D4 Mar 25, 2026
4cdc057
FlatMap table
N2D4 Mar 25, 2026
49dc922
Flat map fuzz tests
N2D4 Mar 25, 2026
3eccc22
Build MapTable from FlatMapTable
N2D4 Mar 25, 2026
e041e7d
Filter tables
N2D4 Mar 25, 2026
e2b0d3d
Limit tables
N2D4 Mar 25, 2026
f7f21aa
Speed up fuzzing
N2D4 Mar 26, 2026
90f61ec
Concat table
N2D4 Mar 26, 2026
69b3d4f
Bulldozer Studio: Better node placing algorithm
N2D4 Mar 26, 2026
e306770
Add left-join table
N2D4 Mar 26, 2026
5036c2a
Sort table
N2D4 Mar 27, 2026
d55470b
LFold table
N2D4 Mar 27, 2026
43d7304
Left join table
N2D4 Mar 27, 2026
a33faa0
Improve left join performance
N2D4 Mar 27, 2026
aaeb7d1
Improved performance for most tables
N2D4 Mar 27, 2026
ef9915a
Refactor Bulldozer into individual files
N2D4 Mar 27, 2026
037d20f
Merge branch 'dev' into bulldozer-db
N2D4 Mar 27, 2026
2403c17
Update apps/backend/src/lib/bulldozer/db/tables/group-by-table.ts
N2D4 Mar 27, 2026
d3a2daa
Performance improvements
N2D4 Mar 28, 2026
b459240
PR comments
N2D4 Mar 29, 2026
c01d931
Some more perf changes
N2D4 Mar 30, 2026
2d49d23
Fix various comparison key bugs
N2D4 Mar 31, 2026
2bb89c2
Performance improvements
N2D4 Mar 31, 2026
199cdf2
Lint fixes
N2D4 Apr 1, 2026
1dc76dc
Merge remote-tracking branch 'origin/dev' into bulldozer-db
N2D4 Apr 1, 2026
e4a5221
More fixes...
N2D4 Apr 3, 2026
e353232
Various changes
N2D4 Apr 6, 2026
4b400e2
Comments from Aman
N2D4 Apr 8, 2026
5b69a18
Fix tests
N2D4 Apr 8, 2026
a7f999f
Improve perf tests
N2D4 Apr 10, 2026
19abfb3
TimeFold table
N2D4 Apr 11, 2026
9cb5f5b
Clean up Prisma schema
N2D4 Apr 11, 2026
e3c3865
Make migration warnings into errors
N2D4 Apr 13, 2026
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
Build MapTable from FlatMapTable
  • Loading branch information
N2D4 committed Mar 25, 2026
commit 3eccc22f80ab11ba4ba2e671921bc4e888f86a46
170 changes: 87 additions & 83 deletions apps/backend/src/lib/bulldozer/db/index.fuzz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function mapGroups<OldRow extends Record<string, unknown>, NewRow extends Record
for (const [groupKey, group] of groups) {
mapped.set(groupKey, {
groupKey: group.groupKey,
rows: new Map([...group.rows.entries()].map(([rowIdentifier, rowData]) => [rowIdentifier, mapperFn(rowData)])),
rows: new Map([...group.rows.entries()].map(([rowIdentifier, rowData]) => [`${rowIdentifier}:1`, mapperFn(rowData)])),
});
}
return mapped;
Expand Down Expand Up @@ -284,7 +284,7 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
const identifiers = ["u1", "u2", "u3", "u4", "u:5", "u 6", "u/7", "u'8"] as const;
const teams = ["alpha", "beta", "gamma", null] as const;

for (const seed of [101, 202, 303]) {
for (const seed of [101]) {
const rng = createRng(seed);
const sourceRows = new Map<string, SourceRow>();

Expand Down Expand Up @@ -328,7 +328,7 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
await runStatements(mapTable2.init());
await runStatements(groupedByBucket.init());

for (let step = 0; step < 60; step++) {
for (let step = 0; step < 24; step++) {
const roll = rng();
if (roll < 0.62) {
const rowIdentifier = choose(rng, identifiers);
Expand Down Expand Up @@ -359,34 +359,36 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
}
}

const expectedGrouped = computeTeamGroups(sourceRows);
const expectedMap1 = mapGroups(expectedGrouped, (row): TeamMappedRow => ({
team: (row.team as string | null),
valuePlusTen: (row.value as number) + 10,
}));
const expectedMap2 = mapGroups(expectedMap1, (row): TeamBucketRow => {
const valueScaled = (row.valuePlusTen as number) * 2;
return {
if (step % 3 === 0 || step === 23) {
const expectedGrouped = computeTeamGroups(sourceRows);
const expectedMap1 = mapGroups(expectedGrouped, (row): TeamMappedRow => ({
team: (row.team as string | null),
valueScaled,
bucket: valueScaled >= 30 ? "high" : "low",
};
});
const expectedBucket = regroupByField(expectedMap2, (row) => row.bucket as string);

await assertTableMatches(groupedTable, expectedGrouped);
await assertTableMatches(mapTable1, expectedMap1);
await assertTableMatches(mapTable2, expectedMap2);
await assertTableMatches(groupedByBucket, expectedBucket);
valuePlusTen: (row.value as number) + 10,
}));
const expectedMap2 = mapGroups(expectedMap1, (row): TeamBucketRow => {
const valueScaled = (row.valuePlusTen as number) * 2;
return {
team: (row.team as string | null),
valueScaled,
bucket: valueScaled >= 30 ? "high" : "low",
};
});
const expectedBucket = regroupByField(expectedMap2, (row) => row.bucket as string);

await assertTableMatches(groupedTable, expectedGrouped);
await assertTableMatches(mapTable1, expectedMap1);
await assertTableMatches(mapTable2, expectedMap2);
await assertTableMatches(groupedByBucket, expectedBucket);
}
}
}
});
}, 120_000);

test("fuzz: flatMap/map/group pipelines preserve invariants under random mutations and re-inits", async () => {
const identifiers = ["f1", "f2", "f3", "f4", "f:5", "f 6", "f/7", "f'8"] as const;
const teams = ["alpha", "beta", "gamma", null] as const;

for (const seed of [501, 502, 503]) {
for (const seed of [501]) {
const rng = createRng(seed);
const sourceRows = new Map<string, SourceRow>();
let pipelineInitialized = true;
Expand Down Expand Up @@ -439,7 +441,7 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
await runStatements(mapAfterFlat.init());
await runStatements(groupedByKind.init());

for (let step = 0; step < 60; step++) {
for (let step = 0; step < 24; step++) {
const roll = rng();
if (roll < 0.6) {
const rowIdentifier = choose(rng, identifiers);
Expand Down Expand Up @@ -469,67 +471,69 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
}
}

const expectedGrouped = computeTeamGroups(sourceRows);
const expectedFlat = flatMapGroups(expectedGrouped, (row): TeamFlatMappedRow[] => {
if ((row.value as number) < 0) return [];
return [
{
team: row.team as string | null,
kind: "base",
mappedValue: (row.value as number) + 100,
},
{
team: row.team as string | null,
kind: "double",
mappedValue: (row.value as number) * 2,
},
];
});
const expectedMapped = mapGroups(expectedFlat, (row): TeamFlatMappedPlusRow => ({
team: row.team as string | null,
kind: row.kind as string,
mappedValuePlusOne: (row.mappedValue as number) + 1,
}));
const expectedKind = regroupByField(expectedMapped, (row) => row.kind as string);

await assertTableMatches(groupedTable, expectedGrouped);
if (pipelineInitialized) {
expect(await readBoolean(flatMapTable.isInitialized())).toBe(true);
expect(await readBoolean(mapAfterFlat.isInitialized())).toBe(true);
expect(await readBoolean(groupedByKind.isInitialized())).toBe(true);
await assertTableMatches(flatMapTable, expectedFlat);
await assertTableMatches(mapAfterFlat, expectedMapped);
await assertTableMatches(groupedByKind, expectedKind);
} else {
expect(await readBoolean(flatMapTable.isInitialized())).toBe(false);
expect(await readBoolean(mapAfterFlat.isInitialized())).toBe(false);
expect(await readBoolean(groupedByKind.isInitialized())).toBe(false);

const flatGroups = await readRows(flatMapTable.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
}));
const mappedGroups = await readRows(mapAfterFlat.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
}));
const kindGroups = await readRows(groupedByKind.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
if (step % 3 === 0 || step === 23) {
const expectedGrouped = computeTeamGroups(sourceRows);
const expectedFlat = flatMapGroups(expectedGrouped, (row): TeamFlatMappedRow[] => {
if ((row.value as number) < 0) return [];
return [
{
team: row.team as string | null,
kind: "base",
mappedValue: (row.value as number) + 100,
},
{
team: row.team as string | null,
kind: "double",
mappedValue: (row.value as number) * 2,
},
];
});
const expectedMapped = mapGroups(expectedFlat, (row): TeamFlatMappedPlusRow => ({
team: row.team as string | null,
kind: row.kind as string,
mappedValuePlusOne: (row.mappedValue as number) + 1,
}));
expect(flatGroups).toEqual([]);
expect(mappedGroups).toEqual([]);
expect(kindGroups).toEqual([]);
const expectedKind = regroupByField(expectedMapped, (row) => row.kind as string);

await assertTableMatches(groupedTable, expectedGrouped);
if (pipelineInitialized) {
expect(await readBoolean(flatMapTable.isInitialized())).toBe(true);
expect(await readBoolean(mapAfterFlat.isInitialized())).toBe(true);
expect(await readBoolean(groupedByKind.isInitialized())).toBe(true);
await assertTableMatches(flatMapTable, expectedFlat);
await assertTableMatches(mapAfterFlat, expectedMapped);
await assertTableMatches(groupedByKind, expectedKind);
} else {
expect(await readBoolean(flatMapTable.isInitialized())).toBe(false);
expect(await readBoolean(mapAfterFlat.isInitialized())).toBe(false);
expect(await readBoolean(groupedByKind.isInitialized())).toBe(false);

const flatGroups = await readRows(flatMapTable.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
}));
const mappedGroups = await readRows(mapAfterFlat.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
}));
const kindGroups = await readRows(groupedByKind.listGroups({
start: "start",
end: "end",
startInclusive: true,
endInclusive: true,
}));
expect(flatGroups).toEqual([]);
expect(mappedGroups).toEqual([]);
expect(kindGroups).toEqual([]);
}
}
}
}
});
}, 120_000);

test("fuzz: parallel map tables remain isolated with independent re-inits", async () => {
const identifiers = ["m1", "m2", "m3", "m 4", "m:5"] as const;
Expand Down Expand Up @@ -646,7 +650,7 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
}
}
}
});
}, 120_000);

test("fuzz: parallel flatMap tables remain isolated with independent re-inits", async () => {
const identifiers = ["pf1", "pf2", "pf3", "pf 4", "pf:5"] as const;
Expand Down Expand Up @@ -801,5 +805,5 @@ describe.sequential("bulldozer db fuzz composition (real postgres)", () => {
}
}
}
});
}, 120_000);
});
2 changes: 1 addition & 1 deletion apps/backend/src/lib/bulldozer/db/index.perf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ describe.sequential("bulldozer db performance (real postgres)", () => {
startInclusive: true,
endInclusive: true,
}));
const highBucketRow = highBucketRows.find((row) => row.rowidentifier === "seed-100000");
const highBucketRow = highBucketRows.find((row) => row.rowidentifier === "seed-100000:1:1");
expect(highBucketRow).toBeDefined();
expect(highBucketRow?.rowdata).toEqual({
team: "delta",
Expand Down
Loading
Loading