-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change incorrect totals TS type (#280)
- Loading branch information
Showing
7 changed files
with
76 additions
and
7 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
65 changes: 65 additions & 0 deletions
65
packages/client-common/__tests__/integration/totals.test.ts
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,65 @@ | ||
import type { ClickHouseClient } from '@clickhouse/client-common' | ||
import { createSimpleTable } from '@test/fixtures/simple_table' | ||
import { createTestClient, guid } from '@test/utils' | ||
|
||
describe('Queries with totals', () => { | ||
let client: ClickHouseClient | ||
let tableName: string | ||
|
||
beforeEach(async () => { | ||
client = createTestClient() | ||
tableName = `totals_test_${guid()}` | ||
await createSimpleTable(client, tableName) | ||
}) | ||
afterEach(async () => { | ||
await client.close() | ||
}) | ||
|
||
it('should return the expected totals', async () => { | ||
await client.insert({ | ||
table: tableName, | ||
values: [ | ||
{ id: '42', name: 'hello', sku: [0, 1] }, | ||
{ id: '43', name: 'hello', sku: [2, 3] }, | ||
{ id: '44', name: 'foo', sku: [3, 4] }, | ||
{ id: '45', name: 'foo', sku: [4, 5] }, | ||
{ id: '46', name: 'foo', sku: [6, 7] }, | ||
], | ||
format: 'JSONEachRow', | ||
}) | ||
|
||
const rs1 = await client.query({ | ||
query: `SELECT *, count(*) AS count FROM ${tableName} GROUP BY id, name, sku WITH TOTALS ORDER BY id ASC`, | ||
format: 'JSON', | ||
}) | ||
const result1 = await rs1.json() | ||
expect(result1.data).toEqual([ | ||
{ id: '42', name: 'hello', sku: [0, 1], count: '1' }, | ||
{ id: '43', name: 'hello', sku: [2, 3], count: '1' }, | ||
{ id: '44', name: 'foo', sku: [3, 4], count: '1' }, | ||
{ id: '45', name: 'foo', sku: [4, 5], count: '1' }, | ||
{ id: '46', name: 'foo', sku: [6, 7], count: '1' }, | ||
]) | ||
expect(result1.totals).toEqual({ | ||
id: '0', | ||
name: '', | ||
sku: [], | ||
count: '5', | ||
}) | ||
|
||
const rs2 = await client.query({ | ||
query: `SELECT 1 :: Int16 AS x, name, count(*) AS count FROM ${tableName} GROUP BY name WITH TOTALS ORDER BY name ASC`, | ||
format: 'JSON', | ||
}) | ||
const result2 = await rs2.json() | ||
expect(result2.data).toEqual([ | ||
{ x: 1, name: 'foo', count: '3' }, | ||
{ x: 1, name: 'hello', count: '2' }, | ||
]) | ||
expect(result2.totals).toEqual({ | ||
x: 1, | ||
name: '', | ||
count: '5', | ||
}) | ||
}) | ||
}) |
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
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
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