如何使用 API、QueryBuilder 和批处理将 Json 插入 cassandra [英] How to insert Json into cassandra using API, QueryBuilder and batch

查看:68
本文介绍了如何使用 API、QueryBuilder 和批处理将 Json 插入 cassandra的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到所有 JSON 示例都将查询用作字符串,如

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\"}'";

但我想使用 QueryBuilder,因为我想批量插入.

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

谢谢

推荐答案

使用 Insert.json() 方法

使用 Cassandra 2.2 中引入的 INSERT INTO ... JSON 语法插入提供的对象.

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

示例:

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

注意:任何从 JSON 字符串中省略的列都将默认为 NULL 值(这将导致创建墓碑).

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).

这篇关于如何使用 API、QueryBuilder 和批处理将 Json 插入 cassandra的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆