PostHog / node-clickhouse

ClickHouse driver for Node.js
MIT License
6 stars 1 forks source link

A bug in regexp prevents using JSONEachRow format in INSERT queries #2

Open vibl opened 3 years ago

vibl commented 3 years ago

There's a bug that prevents sending an INSERT query with a JSONEachRow format: https://github.com/PostHog/node-clickhouse/blob/1d45ede758e0d9a1ac9e76f065f9238d61b5cec8/src/clickhouse.js#L255

There's a \b missing on each side of the parenthese group, which makes the regexp match JSON instead of JSONEachRow.

The regexp should be:

 var formatRegexp = /FORMAT\s+\b(BlockTabSeparated|CSV|CSVWithNames|JSON|JSONCompact|JSONEachRow|Native|Null|Pretty|PrettyCompact|PrettyCompactMonoBlock|PrettyNoEscapes|PrettyCompactNoEscapes|PrettySpaceNoEscapes|PrettySpace|RowBinary|TabSeparated|TabSeparatedRaw|TabSeparatedWithNames|TabSeparatedWithNamesAndTypes|TSKV|Values|Vertical|XML)\b/i; 

This fixes the issue.

I filed an issue several months ago on the @apla/node-clickhouse repo but I got no answer.

Could you correct this?

Twixes commented 2 years ago

Hey! Since you propose a way to fix this, we'd be super happy to take PR if you're up for it?