Creating table in Cassandra within Flink Code

198 Views Asked by At

I have created keyspace and table in Cassandra from cqlsh shell

 CREATE KEYSPACE data WITH replication= {'class':'SimpleStrategy', 'replication_factor':1;

 CREATE TABLE test.patient(id int, heart_rate int, PRIMARY KEY(id));

I want to create keyspace and Table if it does not exists from Flink code, Can someone please tell me how it can be done?

2

There are 2 best solutions below

0
On

Flink-Cassandra connector does not have the feature to create keyspace/tables in Cassandra. You can check available methods in the connector here.

If you want to create keyspace/tables in C* if they are not already created by Flink you can do:

CREATE KEYSPACE IF NOT EXISTS data WITH replication= {'class':'SimpleStrategy', 'replication_factor':1;
CREATE TABLE IF NOT EXISTS test.patient(id int, heart_rate int, PRIMARY KEY(id));
0
On

You can look the test case org.apache.flink.streaming.connectors.cassandra.CassandraConnectorITCase.java, may be able to help you.