Skip to content

Commit

Permalink
Add '@s' to steps that are streaming (#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Jan 7, 2025
2 parents 12c908f + d34014a commit 5dd99a0
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-tigers-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"grafast": patch
---

Plan diagrams now reveal (via `@s` code) if a step is meant to be streamed.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ graph TD
Constant60{{"Constant[60∈1] ➊<br />ᐸfalseᐳ"}}:::plan
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
PgSelect42[["PgSelect[42∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect42[["PgSelect[42∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect42
PgSelect62[["PgSelect[62∈3]<br />ᐸmessages(aggregate)ᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect62
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ graph TD
Constant60{{"Constant[60∈1] ➊<br />ᐸfalseᐳ"}}:::plan
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
PgSelect42[["PgSelect[42∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect42[["PgSelect[42∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect42
PgSelectSingle15 --> PgClassExpression22
PgSelectSingle15 --> PgClassExpression28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s1]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s1]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s2]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s2]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s1]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ graph TD
__Item14 --> PgSelectSingle15
PgClassExpression16{{"PgClassExpression[16∈2]<br />ᐸ__forums__.”name”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression16
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s1]<br />ᐸmessagesᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__forums__.”id”ᐳ"}}:::plan
PgClassExpression28{{"PgClassExpression[28∈3]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ graph TD
PgSelectSingle15 --> PgClassExpression22
PgClassExpression28{{"PgClassExpression[28∈2]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression28
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
PgSelect42[["PgSelect[42∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect42[["PgSelect[42∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect42
__Item30[/"__Item[30∈4]<br />ᐸ29ᐳ"\]:::itemplan
PgSelect29 ==> __Item30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ graph TD
PgSelectSingle15 --> PgClassExpression22
PgClassExpression28{{"PgClassExpression[28∈2]<br />ᐸ__forums__...chived_at”ᐳ"}}:::plan
PgSelectSingle15 --> PgClassExpression28
PgSelect29[["PgSelect[29∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect29[["PgSelect[29∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect29
PgSelect42[["PgSelect[42∈3]<br />ᐸmessagesᐳ"]]:::plan
PgSelect42[["PgSelect[42∈3@s]<br />ᐸmessagesᐳ"]]:::plan
Object13 & PgClassExpression22 & PgClassExpression28 & Connection27 --> PgSelect42
__Item30[/"__Item[30∈4]<br />ᐸ29ᐳ"\]:::itemplan
PgSelect29 ==> __Item30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ graph TD


%% plan dependencies
Listen9["Listen[9∈0] ➊"]:::plan
Listen9["Listen[9∈0@s] ➊"]:::plan
Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSubscriberᐳ"}}:::plan
Lambda7{{"Lambda[7∈0] ➊"}}:::plan
Access8 & Lambda7 --> Listen9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ graph TD


%% plan dependencies
Listen9["Listen[9∈0] ➊"]:::plan
Listen9["Listen[9∈0@s] ➊"]:::plan
Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSubscriberᐳ"}}:::plan
Lambda7{{"Lambda[7∈0] ➊"}}:::plan
Access8 & Lambda7 --> Listen9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ graph TD


%% plan dependencies
Listen9["Listen[9∈0] ➊"]:::plan
Listen9["Listen[9∈0@s] ➊"]:::plan
Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSubscriberᐳ"}}:::plan
Lambda7{{"Lambda[7∈0] ➊"}}:::plan
Access8 & Lambda7 --> Listen9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ graph TD


%% plan dependencies
Listen9["Listen[9∈0] ➊"]:::plan
Listen9["Listen[9∈0@s] ➊"]:::plan
Access8{{"Access[8∈0] ➊<br />ᐸ2.pgSubscriberᐳ"}}:::plan
Lambda7{{"Lambda[7∈0] ➊"}}:::plan
Access8 & Lambda7 --> Listen9
Expand Down
3 changes: 3 additions & 0 deletions grafast/grafast/src/engine/OperationPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3606,6 +3606,9 @@ export class OperationPlan {
supportsUnbatched:
typeof (step as any).unbatchedExecute === "function" || undefined,
hasSideEffects: step.hasSideEffects || undefined,
stream: step._stepOptions.stream
? { initialCount: step._stepOptions.stream.initialCount }
: undefined,
extra: step.planJSONExtra(),
};
}
Expand Down
10 changes: 7 additions & 3 deletions grafast/grafast/src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ export function planToMermaid(
? ""
: `\n${polyPaths}`;

const planString = `${planName}[${plan.id}${`∈${plan.bucketId}`}]${
plan.isUnary ? " ➊" : ""
}${meta ? `\n<${meta}>` : ""}${polyPathsIfDifferent}`;
const planString = `${planName}[${plan.id}${`∈${plan.bucketId}`}${
plan.stream
? `@s${plan.stream.initialCount > 0 ? plan.stream.initialCount : ""}`
: ""
}]${plan.isUnary ? " ➊" : ""}${
meta ? `\n<${meta}>` : ""
}${polyPathsIfDifferent}`;
const [lBrace, rBrace] =
plan.stepClass === "__ItemStep"
? ["[/", "\\]"]
Expand Down
1 change: 1 addition & 0 deletions grafast/grafast/src/planJSONInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface GrafastPlanStepJSONv1 {
isSyncAndSafe: boolean | undefined;
supportsUnbatched: boolean | undefined;
hasSideEffects: boolean | undefined;
stream: { initialCount: number } | undefined;
extra?: Record<string, JSONValue | undefined>;
}

Expand Down
15 changes: 11 additions & 4 deletions grafast/grafast/src/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,17 @@ export /* abstract */ class ExecutableStep<TData = any> extends BaseStep {
`${this.constructor.name.replace(/Step$/, "")}${
this.layerPlan.id === 0 ? "" : chalk.grey(`{${this.layerPlan.id}}`)
}${this._isUnary ? "➊" : ""}${
meta != null && meta.length ? chalk.grey(`<${meta}>`) : ""
}[${inspect(this.id, {
colors: true,
})}]`,
this._stepOptions.stream
? `@s${
this._stepOptions.stream.initialCount > 0
? this._stepOptions.stream.initialCount
: ""
}`
: ""
}${meta != null && meta.length ? chalk.grey(`<${meta}>`) : ""}[${inspect(
this.id,
{ colors: true },
)}]`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ graph TD
PgSelect19 ==> __Item20
PgSelectSingle21{{"PgSelectSingle[21∈2]<br />ᐸpersonᐳ"}}:::plan
__Item20 --> PgSelectSingle21
PgSelect27[["PgSelect[27∈3]<br />ᐸpostᐳ"]]:::plan
PgSelect27[["PgSelect[27∈3@s2]<br />ᐸpostᐳ"]]:::plan
PgClassExpression22{{"PgClassExpression[22∈3]<br />ᐸ__person__.”id”ᐳ"}}:::plan
Object17 & PgClassExpression22 --> PgSelect27
PgSelectSingle21 --> PgClassExpression22
Expand Down

0 comments on commit 5dd99a0

Please sign in to comment.