-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Don't consolidate aggregated and non-aggregated queries without …
…a groupby
- Loading branch information
1 parent
279d7be
commit 0fc6da9
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import assert from 'node:assert'; | ||
import { Query } from '@uwdata/mosaic-sql/src/Query.js'; | ||
import { count, sum } from '@uwdata/mosaic-sql/src/aggregates.js'; | ||
import { consolidator } from '../src/QueryConsolidator.js'; | ||
import { Priority } from '../src/QueryManager.js'; | ||
import { voidCache } from '../src/util/cache.js'; | ||
|
||
describe('QueryConsolidation', () => { | ||
async function getConsolidatedQueries(...qs) { | ||
const consolidated = []; | ||
const c = consolidator(q => consolidated.push(q.request.query.toString()), voidCache(), () => {/*ignore*/}); | ||
for(const q of qs) { | ||
c.add({request: { type: 'arrow', query: q }}, Priority.Normal); | ||
} | ||
await new Promise(resolve => setImmediate(resolve)); | ||
return consolidated; | ||
} | ||
|
||
it('should consolidate non-grouped aggregated queries', async () => { | ||
const q1 = Query.from({ source: 'table' }).select({ c: count() }); | ||
const q2 = Query.from({ source: 'table' }).select({ c: sum() }); | ||
const consolidated = await getConsolidatedQueries(q1, q2); | ||
assert.deepEqual(consolidated, [ | ||
Query.from({ source: 'table' }).select({ col0: count(), col1: sum() }).toString(), | ||
]); | ||
}); | ||
|
||
it('should consolidate non-grouped non-aggregated queries', async () => { | ||
const q1 = Query.from({ source: 'table' }).select({ c: 'x' }); | ||
const q2 = Query.from({ source: 'table' }).select({ c: 'y' }); | ||
const consolidated = await getConsolidatedQueries(q1, q2); | ||
assert.deepEqual(consolidated, [ | ||
Query.from({ source: 'table' }).select({ col0: 'x', col1: 'y' }).toString(), | ||
]); | ||
}); | ||
|
||
it('should not consolidate non-grouped aggregated and non-aggregated queries', async () => { | ||
const q1 = Query.from({ source: 'table' }).select({ c: 'x' }); | ||
const q2 = Query.from({ source: 'table' }).select({ c: count() }); | ||
const consolidated = await getConsolidatedQueries(q1, q2); | ||
assert.deepEqual(consolidated, [ | ||
q1.toString(), | ||
q2.toString(), | ||
]); | ||
}); | ||
}); |