apla / node-clickhouse

Yandex ClickHouse driver for nodejs
MIT License
216 stars 50 forks source link

The last blank is trimed,so how to fix this error #25

Closed gclinux closed 5 years ago

gclinux commented 5 years ago

error: Error: Unknown format CSV1550220733

Code

let statement = 'INSERT INTO testTable FORMAT CSV '; let csvStream = fs.createReadStream (‘csv.csv’); let clickhouseStream = ch.query (statement, {inputFormat: 'CSV'}); csvStream.pipe (clickhouseStream); clickhouseStream.on('end',function(){ ac(file_name+'->success'); }); clickhouseStream.on ('error', function (err) { console.log(err); ac(file_name+'->false'); });

csv file

1550220733,22222,33333

gclinux commented 5 years ago

I have fixed。 let clickhouseStream = ch.query (statement, {inputFormat: 'CSV'}); clickhouseStream.write('\n'); csvStream.pipe (clickhouseStream);

nezed commented 5 years ago

There is a bug with while serializing the body of request — data aren't separated from query with space or newline. Also, the inputFormat option from readme aren't supported.

I'll prepare fix for this.

For now better way is to use format options instead of FORMAT statement.

let clickhouseStream = ch.query ('INSERT INTO testTable', {format: 'CSV'});
nezed commented 4 years ago

@gclinux Fixed in @apla/clickhouse@1.6.1

https://github.com/apla/node-clickhouse/releases/tag/v1.6.1