Skip to content
Advertisement

How can I create the Table and insert the json data by using JAVA in CQL?

I am the new learner in CQL. I am using the docker env to run the Cassandra.

In previous, I have the two tables(restaurants and Inspection) with inserted the data by csv and the following setting:

enter image description here

Since join method are not supported in CQL, I need to re-insert the joined data set(JSON) to a new table(call InspectionrestaurantNY).

Therefore, I tried to create the InspectionrestaurantNY table: enter image description here

Then, I have the jav which help me to install the json file. But I got the error, and I don’t know what table(InspectionrestaurantNY) setting should I create to insert the json data.

I ran the java -jar JSonFile2Cassandra.jar -host 192.168.99.101 -port 3000 -keyspace restaurantsNY -columnFamily InspectionsRestaurants -file InspectionsRestaurantsNY.json, it shown the following error:

enter image description here

And, my json file is stored as like this: enter image description hereenter image description hereenter image description hereenter image description here

What table setting should I build up first to insert the JSON data?

How to solve the JAVA error?

Thank you so much.

Advertisement

Answer

Seems like you are using wrong table name when running jar to insert JSON. The command you shared is

java -jar JSonFile2Cassandra.jar -host 192.168.99.101 -port 3000 -keyspace restaurantsNY -columnFamily InspectionsRestaurants -file InspectionsRestaurantsNY.json

Shouldnt it be

java -jar JSonFile2Cassandra.jar -host 192.168.99.101 -port 3000 -keyspace restaurantsNY -columnFamily InspectionsRestaurantsNY -file InspectionsRestaurantsNY.json

i.e use correct table name InspectionsRestaurantsNY for -columnFamily argument in above command.

Also its always better not to use camel case convention as CQL identifier names are case-insensitive. If you really really want case sensitive names then you should enclose names in double quotes. If double quotes are not used then Cassandra will convert names with mixed case to lower case. But in above query I dont think that is cause of error. I think its due to wrong column family name.

Check here for mixed cases names https://docs.datastax.com/en/cql/3.3/cql/cql_reference/ucase-lcase_r.html

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement