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

refactor(zql): move splitting of edits up to source #3936

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions packages/zql/src/builder/builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,50 @@ test('self-join edit', () => {
},
"type": "remove",
},
{
"node": {
"relationships": {
"recruiter": [
{
"relationships": {},
"row": {
"id": 1,
"name": "aaron",
"recruiterID": null,
},
},
],
},
"row": {
"id": 4,
"name": "matt",
"recruiterID": 1,
},
},
"type": "add",
},
{
"node": {
"relationships": {
"recruiter": [
{
"relationships": {},
"row": {
"id": 1,
"name": "aaron",
"recruiterID": null,
},
},
],
},
"row": {
"id": 4,
"name": "matt",
"recruiterID": 1,
},
},
"type": "remove",
},
{
"node": {
"relationships": {
Expand Down
25 changes: 22 additions & 3 deletions packages/zql/src/builder/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,35 @@ function buildPipelineInternal(
if (!source) {
throw new Error(`Source not found: ${ast.table}`);
}
const conn = source.connect(must(ast.orderBy), ast.where);
ast = uniquifyCorrelatedSubqueryConditionAliases(ast);

const csqsFromCondition = gatherCorrelatedSubqueryQueriesFromCondition(
ast.where,
);
const splitEditKeys: Set<string> = partitionKey
? new Set(partitionKey)
: new Set();
for (const csq of csqsFromCondition) {
for (const key of csq.correlation.parentField) {
splitEditKeys.add(key);
}
}
if (ast.related) {
for (const csq of ast.related) {
for (const key of csq.correlation.parentField) {
splitEditKeys.add(key);
}
}
}
const conn = source.connect(must(ast.orderBy), ast.where, splitEditKeys);
let end: Input = delegate.decorateInput(conn, `${name}:source(${ast.table})`);
const {fullyAppliedFilters} = conn;
ast = uniquifyCorrelatedSubqueryConditionAliases(ast);

if (ast.start) {
end = delegate.decorateInput(new Skip(end, ast.start), `${name}:skip)`);
}

for (const csq of gatherCorrelatedSubqueryQueriesFromCondition(ast.where)) {
for (const csq of csqsFromCondition) {
end = applyCorrelatedSubQuery(csq, delegate, end, name);
}

Expand Down
5 changes: 4 additions & 1 deletion packages/zql/src/ivm/exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ export class Exists implements Operator {
this.#relationshipName = relationshipName;
this.#input.setOutput(this);
this.#storage = storage as ExistsStorage;
assert(this.#input.getSchema().relationships[relationshipName]);
assert(
this.#input.getSchema().relationships[relationshipName],
`Input schema missing ${relationshipName}`,
);
this.#not = type === 'NOT EXISTS';
this.#parentJoinKey = parentJoinKey;

Expand Down
Loading
Loading