在 Amazon Keyspaces 上启用 Json 插入

Enable Json Insert on Amazon Keyspaces

我正在从托管的 Cassandra 迁移到 Amazon Keyspace。

一些生产过程使用Cassandra Json Insert。当我尝试 运行 此过程之一将数据存储在 Amazon Keyspaces 中时,出现以下错误:

Unsupported statement: org.apache.cassandra.cql3.statements.UpdateStatement$ParsedInsertJson@7ba2351

我想 Amazon Keyspace 中未启用此功能。在我本地的 Cassandra 上,我没有启用任何东西来使用 JSON insert。有一种方法可以在 Amazon Keyspaces

上启用此功能

Keyspaces 于 2021 年 1 月 22 日开始支持 JSON。 您可以像使用 Cassandra 一样使用 JSON API 输入插入和选择。

您可以使用 JSON API 对现有 table 执行插入和 select 语句。

这是关于键空间和 JSON 如何协同工作的 link 信息:https://aws.amazon.com/about-aws/whats-new/2021/01/amazon-keyspaces-for-apache-cassandra-now-supports-json-syntax/

Keyspaces 一直在添加新功能。要查看受支持的 APIs,请访问 this

下面是JSONapi的例子。将以下 create table 语句复制到 Amazon Keyspaces CQL 控制台中。然后在 table 创建后执行下面的 insert 和 select 语句。

下面的代码将创建一个 json_keyspaces 键空间,然后创建一个名为 shoppingcart 的 table。 将键空间名称替换为您自己的名称。完成后,您将拥有一个名为 shoppingcart 的新 table。

然后 INSERT 语句将使用 JSON API 插入一些 JSON 数据。下面是一个 SELECT 语句来查询 table.

中的数据

CREATE TABLE "json_keyspaces”.”shoppingcart"(
    "user_id" text,
    "item_id" text,
    "quantity" int,
    PRIMARY KEY("user_id", "item_id"))
WITH CUSTOM_PROPERTIES = {
    'capacity_mode':{'throughput_mode':'PAY_PER_REQUEST'}, 
    'point_in_time_recovery':{'status':'enabled'}
} AND CLUSTERING ORDER BY("item_id" ASC)


INSERT INTO json_keyspaces.shoppingcart JSON '{
  "user_id": "id123",
  "item_id": "blue_shirt",
  "quantity" : 5
 }';
  

SELECT json user_id, item_id, quantity from json_keyspaces.shoppingcart;