diff --git a/packages/db-ivm/src/operators/distinct.ts b/packages/db-ivm/src/operators/distinct.ts index dc2f5a177..887695f9d 100644 --- a/packages/db-ivm/src/operators/distinct.ts +++ b/packages/db-ivm/src/operators/distinct.ts @@ -32,14 +32,28 @@ export class DistinctOperator extends UnaryOperator { // Compute the new multiplicity for each value for (const message of this.inputMessages()) { for (const [value, diff] of message.getInner()) { + console.log(`value in distinct:`, JSON.stringify(value, null, 2)) + console.log(`diff in distinct:`, JSON.stringify(diff, null, 2)) const hashedValue = hash(this.#by(value)) + console.log(`by in distinct:`, JSON.stringify(this.#by(value), null, 2)) + console.log( + `hashedValue in distinct:`, + JSON.stringify(hashedValue, null, 2) + ) const oldMultiplicity = updatedValues.get(hashedValue)?.[0] ?? this.#values.get(hashedValue) ?? 0 + console.log( + `oldMultiplicity in distinct:`, + JSON.stringify(oldMultiplicity, null, 2) + ) const newMultiplicity = oldMultiplicity + diff - + console.log( + `newMultiplicity in distinct:`, + JSON.stringify(newMultiplicity, null, 2) + ) updatedValues.set(hashedValue, [newMultiplicity, value]) } } diff --git a/packages/db/tests/query/distinct.test.ts b/packages/db/tests/query/distinct.test.ts index 101444294..e3e57c2f1 100644 --- a/packages/db/tests/query/distinct.test.ts +++ b/packages/db/tests/query/distinct.test.ts @@ -675,6 +675,11 @@ function createDistinctTests(autoIndex: `off` | `eager`): void { }) test(`distinct with join operations`, () => { + console.log(`**************************************************`) + console.log(`**************************************************`) + console.log(`**************************************************`) + console.log(`**************************************************`) + console.log(`**************************************************`) // Create a simple departments collection to join with const departmentsData = [ { id: `Engineering`, budget: 1000000 }, @@ -707,11 +712,12 @@ function createDistinctTests(autoIndex: `off` | `eager`): void { .distinct(), }) + const results = Array.from(distinctJoinedData.values()) + // There are 3 distinct departments that have active users + console.log(`results:`, JSON.stringify(results, null, 2)) expect(distinctJoinedData.size).toBe(3) - const results = Array.from(distinctJoinedData.values()) - // Should have distinct combinations of department const combinations = results.map((r) => `${r.department}`) const uniqueCombinations = [...new Set(combinations)]