-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Parquet format support for streaming
- Loading branch information
Showing
12 changed files
with
156 additions
and
6 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
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,58 @@ | ||
import { createClient } from '@clickhouse/client' | ||
import type { Row } from '@clickhouse/client-common' | ||
import Fs from 'fs' | ||
import { cwd } from 'node:process' | ||
import Path from 'path' | ||
|
||
void (async () => { | ||
const client = createClient() | ||
const tableName = 'insert_file_stream_parquet' | ||
await client.command({ | ||
query: `DROP TABLE IF EXISTS ${tableName}`, | ||
}) | ||
await client.command({ | ||
query: ` | ||
CREATE TABLE ${tableName} | ||
(id UInt64, name String, sku Array(UInt8)) | ||
ENGINE MergeTree() | ||
ORDER BY (id) | ||
`, | ||
}) | ||
|
||
const filename = Path.resolve(cwd(), './node/resources/data.parquet') | ||
|
||
/* | ||
(examples) $ pqrs cat node/resources/data.parquet | ||
############################ | ||
File: node/resources/data.parquet | ||
############################ | ||
{id: 0, name: [97], sku: [1, 2]} | ||
{id: 1, name: [98], sku: [3, 4]} | ||
{id: 2, name: [99], sku: [5, 6]} | ||
*/ | ||
|
||
await client.insert({ | ||
table: tableName, | ||
values: Fs.createReadStream(filename), | ||
format: 'Parquet', | ||
}) | ||
|
||
const rs = await client.query({ | ||
query: `SELECT * from ${tableName}`, | ||
format: 'JSONEachRow', | ||
}) | ||
|
||
for await (const rows of rs.stream()) { | ||
// or just `rows.json()` | ||
// to consume the entire response at once | ||
rows.forEach((row: Row) => { | ||
console.log(row.json()) | ||
}) | ||
} | ||
|
||
await client.close() | ||
})() |
Binary file not shown.
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,42 @@ | ||
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`, | ||
}) | ||
|
||
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() | ||
})() |
Binary file added
BIN
+831 Bytes
packages/client-common/__tests__/fixtures/streaming_e2e_data.parquet
Binary file not shown.
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 |
---|---|---|
@@ -1 +1 @@ | ||
export default '0.2.5' | ||
export default '0.2.6' |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export default '0.2.5' | ||
export default '0.2.6' |
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 |
---|---|---|
@@ -1 +1 @@ | ||
export default '0.2.5' | ||
export default '0.2.6' |