Home > Software engineering >  Cassandra client's execute function return an error if the query contains a comment
Cassandra client's execute function return an error if the query contains a comment

Time:09-21

I need to make a query to a Cassandra database using the execute function of the Cassandra client provided by the package cassandra-driver.

Here is the code:

const cassandraClient = new cassandra.Client({
    contactPoints: ["localhost"],
    localDataCenter: "datacenter1",
    keyspace: "database"
});

cassandraClient.execute("SELECT * FROM users; -- this is a comment").then(console.log);

But I get the following error:

ResponseError: line 1:47 mismatched character '<EOF>' expecting set null
    at FrameReader.readError (C:\tests\cassandra\src\node_modules\cassandra-driver\lib\readers.js:389:17)
    at Parser.parseBody (C:\tests\cassandra\src\node_modules\cassandra-driver\lib\streams.js:209:66)    
    at Parser._transform (C:\tests\cassandra\src\node_modules\cassandra-driver\lib\streams.js:152:10)   
    at Parser.Transform._write (node:internal/streams/transform:205:23)
    at writeOrBuffer (node:internal/streams/writable:391:12)
    at _write (node:internal/streams/writable:332:10)
    at Parser.Writable.write (node:internal/streams/writable:336:10)
    at Protocol.ondata (node:internal/streams/readable:754:22)
    at Protocol.emit (node:events:513:28)
    at Protocol.emit (node:domain:489:12) {
  info: 'Represents an error message from the server',
  code: 8192,
  coordinator: '127.0.0.1:9042',
  query: 'SELECT * FROM users; -- this is a comment'
}

What is wrong here?

CodePudding user response:

So I was able to reproduce this using the Python driver. I think this is happening because the CQL parser expects a comment to be on its own line.

I was able to get this to work by putting a line break on the end of the comment, so give this a try:

cassandraClient.execute("SELECT * FROM users; -- this is a comment\n").then(console.log);
  • Related