apla / node-clickhouse

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

Termination with comments in query and .query method #54

Open ks-s-a opened 4 years ago

ks-s-a commented 4 years ago

Run such snippet:

const ClickHouse = require('@apla/clickhouse');

const c = new ClickHouse({
  host,
  port,
  auth
});

const q = 'select count() from table
-- ololololoolololololoolololololol
'
const stream = c.query(q);

stream.on('metadata', function (metadata) {
  console.log('metadata', metadata);
});

stream.on('data', function (data) {
  console.log('data!', data);
});

stream.on('error', err => {
  console.log('error', err);
});

stream.on('end', () => {
  console.log('end');
});

stream.on('end', () => {
  console.log('end');
});

And receive nothing. Stream was closed and the script terminated. There were no fired events. However, if I remove comments from the query it will work properly.

I looked at tcpdump and saw that the request was sent to the server. After sending we got 'close' event from http.response inside the client's code then 'response' event and 'close' again.

Tried to send the request with http://ui.tabix.io/ - everything is fine. And it is the reason why I texted here. It looks like client bug, which not related to server settings.

ks-s-a commented 4 years ago

Ok. Swiched clickhouse server to debug mode and got:

2020.02.13 11:53:32.442129 <Debug> executeQuery: (from ${IP}:46934, user: username) select count() from default.events -- FORMAT JSONCompact

Looks like client adds FORMAT statement to the end of the query and it becomes part of comment. Is it expected behavior?