How to insert Json into cassandra using API, QueryBuilder and batch

此生再无相见时 提交于 2019-12-12 03:46:00

问题


I see that all examples for JSON uses the query as string like

String cqlStatement = "INSERT INTO users JSON '{\"id\":888 , \"age\":21 ,\"state\":\"TX\"}'";

but I want to use QueryBuilder, since I would like to insert in batch.

Thanks


回答1:


Use Insert.json() method

Inserts the provided object, using the INSERT INTO ... JSON syntax introduced in Cassandra 2.2.

Example :

QueryBuilder.insertInto("my_data").json("{\"id\": 1, \"value\": \"This is a test\"}");

Note : Any columns which are omitted from the JSON string will be defaulted to a NULL value (which will result in a tombstone being created).



来源:https://stackoverflow.com/questions/43236799/how-to-insert-json-into-cassandra-using-api-querybuilder-and-batch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!