Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/pretty-ties-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-sync-rules': patch
---

Support multiple references between the same tables as join conditions for Sync Streams (the compiler would previously crash due to an "internal circular reference error").
21 changes: 19 additions & 2 deletions packages/sync-rules/src/compiler/querier_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,28 @@ class PendingQuerierPath {
} else {
// Must be a match term.
const partitionBy = (key: PartitionKey, otherRow: SingleDependencyExpression) => {
const otherResultSet = otherRow.resultSet;
if (
otherResultSet &&
this.resolveStack.find(
(s) =>
s === otherResultSet ||
(otherResultSet instanceof TableValuedResultSet && otherResultSet.inputResultSet == s)
)
) {
// The other result set is already being resolved (so this is a circular reference). We will encounter this
// expression again as we go up the stack and the other result set would visit this expression (where the
// parameters are essentially swapped, the key here would be the otherRow from that perspective). Since this
// parameter lookup would have been resolved at that point, we can simply add the key as an output
// expression at that stage.
return;
}

this.removePendingExpression(expression);
const values = state.partition.putIfAbsent(key, () => []);

if (otherRow.resultSet != null) {
const lookup = this.resolveExpandingLookup(otherRow.resultSet);
if (otherResultSet != null) {
const lookup = this.resolveExpandingLookup(otherResultSet);
const index = lookup.addOutput(new RowExpression(otherRow));
const value = new LookupResultParameterValue(index);
lookup.dependents.push(value);
Expand Down
Loading
Loading