Skip to content

Cannot use JSONEachRow format #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vibl opened this issue Oct 14, 2020 · 1 comment
Open

Cannot use JSONEachRow format #67

vibl opened this issue Oct 14, 2020 · 1 comment

Comments

@vibl
Copy link

vibl commented Oct 14, 2020

I was trying to sending an INSERT query with a JSONEachRow format and any of my attempts failed.

While debugging I found two problems:

The line

if (!options.omitFormat && formatMatch) {
overrides the options.format = "JSONEachRow" I have explicitly set. Is that on purpose? If so, why?

The regexp

var formatRegexp = /FORMAT\s+(BlockTabSeparated|CSV|CSVWithNames|JSON|JSONCompact|JSONEachRow|Native|Null|Pretty|PrettyCompact|PrettyCompactMonoBlock|PrettyNoEscapes|PrettyCompactNoEscapes|PrettySpaceNoEscapes|PrettySpace|RowBinary|TabSeparated|TabSeparatedRaw|TabSeparatedWithNames|TabSeparatedWithNamesAndTypes|TSKV|Values|Vertical|XML)/i;
should have a \b on each side of the parentheses group, otherwise e.g. JSON is matched instead of JSONEachRow.

So:

 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; 

So options.format ended up being set as JSON whatever I was doing.

@vincenzon
Copy link

I hit this issue as well. In case others do a fix is to explicitly set the format option:

const clickhouseStream = clickhouse.query(
      `insert into some_table`,
      { format: "JSONEachRow" }
    );

instead of:

const clickhouseStream = clickhouse.query(
      `insert into some_table format JSONEachRow`,
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants