-
Notifications
You must be signed in to change notification settings - Fork 29
/
select_parquet_as_file.ts
46 lines (37 loc) · 1.02 KB
/
select_parquet_as_file.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { createClient } from '@clickhouse/client'
import Fs from 'fs'
import { cwd } from 'node:process'
import Path from 'path'
void (async () => {
const client = createClient()
const { stream } = await client.exec({
query: `SELECT * from system.numbers LIMIT 10 FORMAT Parquet`,
clickhouse_settings: {
/** See also https://clickhouse.com/docs/en/interfaces/formats#parquet-format-settings.
* You could specify these (and other settings) here. */
},
})
const filename = Path.resolve(cwd(), './node/out.parquet')
const writeStream = Fs.createWriteStream(filename)
stream.pipe(writeStream)
await new Promise((resolve) => {
stream.on('end', resolve)
})
/*
(examples) $ pqrs cat node/out.parquet
#################
File: node/out.parquet
#################
{number: 0}
{number: 1}
{number: 2}
{number: 3}
{number: 4}
{number: 5}
{number: 6}
{number: 7}
{number: 8}
{number: 9}
*/
await client.close()
})()