-
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.
- Loading branch information
Showing
15 changed files
with
173 additions
and
27 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
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,39 @@ | ||
import { createClient } from '@clickhouse/client' | ||
import { isProgressRow } from '@clickhouse/client-common' | ||
|
||
/** See the format spec - https://clickhouse.com/docs/en/interfaces/formats#jsoneachrowwithprogress | ||
* When JSONEachRowWithProgress format is used in TypeScript, | ||
* the ResultSet should infer the final row type as `{ row: Data } | ProgressRow`. */ | ||
type Data = { number: string } | ||
|
||
void (async () => { | ||
const client = createClient() | ||
const rs = await client.query({ | ||
query: 'SELECT number FROM system.numbers LIMIT 100', | ||
format: 'JSONEachRowWithProgress', | ||
}) | ||
|
||
let totalRows = 0 | ||
let totalProgressRows = 0 | ||
|
||
const stream = rs.stream<Data>() | ||
for await (const rows of stream) { | ||
for (const row of rows) { | ||
const decodedRow = row.json() | ||
if (isProgressRow(decodedRow)) { | ||
console.log('Got a progress row:', decodedRow) | ||
totalProgressRows++ | ||
} else { | ||
totalRows++ | ||
if (totalRows % 100 === 0) { | ||
console.log('Sample row:', decodedRow) | ||
} | ||
} | ||
} | ||
} | ||
|
||
console.log('Total rows:', totalRows) | ||
console.log('Total progress rows:', totalProgressRows) | ||
|
||
await client.close() | ||
})() |
29 changes: 29 additions & 0 deletions
29
packages/client-common/__tests__/unit/clickhouse_types.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,29 @@ | ||
import { isProgressRow } from '@clickhouse/client-common' | ||
|
||
describe('ClickHouse types', () => { | ||
it('should check if a row is progress row', async () => { | ||
const row = { | ||
progress: { | ||
read_rows: '1', | ||
read_bytes: '1', | ||
written_rows: '1', | ||
written_bytes: '1', | ||
total_rows_to_read: '1', | ||
result_rows: '1', | ||
result_bytes: '1', | ||
elapsed_ns: '1', | ||
}, | ||
} | ||
expect(isProgressRow(row)).toBeTruthy() | ||
expect(isProgressRow({})).toBeFalsy() | ||
expect( | ||
isProgressRow({ | ||
...row, | ||
extra: 'extra', | ||
}), | ||
).toBeFalsy() | ||
expect(isProgressRow(null)).toBeFalsy() | ||
expect(isProgressRow(42)).toBeFalsy() | ||
expect(isProgressRow({ foo: 'bar' })).toBeFalsy() | ||
}) | ||
}) |
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
3 changes: 1 addition & 2 deletions
3
packages/client-node/__tests__/integration/node_query_format_types.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
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
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