Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



arsen.gasparyan.05_188257 avatar image
arsen.gasparyan.05_188257 asked Erick Ramirez edited

Does the Kafka connector allow running a different CQL query based on some condition?

I want to know, Does Datastax Kafka connector gives the ability to choose to insert or update query based on the field to exist in massage or not?

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I don't quite understand what you're asking. Perhaps if you give an example of what query you want and the things you've tried that hasn't work, I'd be able to assist you better. Cheers!

0 Likes 0 ·

The connector gives the following abilities.

topic.my_topic.my_ks.my_table.query=INSERT INTO ks.tbl(pkey,ccol,x) VALUES :pkey, :ccol, :x);

topic.my_topic.my_ks.my_table.query=UPDATE ks.tbl SET somelist = somelist + [:newitem] WHERE pkey = :pkey;

I want to choose if 'newitem' field exists in my message do update query not insert.

0 Likes 0 ·

1 Answer

Tomasz Lelek avatar image
Tomasz Lelek answered arsen.gasparyan.05_188257 commented

Hello, the .query setting can accept any valid CQL query, but currently, we do not support multiple queries set for the same topic.keyspace.table.

You need to pick one CQL query that will be executed for every record that arrives at the Kafka topic.

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

This is my table schema

CREATE TABLE test.test ( id int, user_id text, date timestamp, value double, log list<text>, PRIMARY KEY ((id, user_id), date) );

{"date":"2020-06-05 16:03:44.731","id":1234,"userId":"a1234","value":20.4}


{"date":"2020-06-05 16:03:44.731","id":1234,"userId":"a1234","value":20.4,"log":"log message"}

I want to do insert query when the 'log' field doesn't exist

or do update already existing row when it exists.

0 Likes 0 ·

okay thanks

0 Likes 0 ·