【问题标题】:Enable Json Insert on Amazon Keyspaces在 Amazon Keyspaces 上启用 Json 插入
【发布时间】:2021-02-03 03:01:15
【问题描述】:

我正在从托管的 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 上启用此功能

【问题讨论】:

标签: json amazon-web-services cassandra insert amazon-keyspaces


【解决方案1】:

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

您可以使用 JSON API 对现有表执行插入和选择语句。

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

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

以下是 JSON api 的示例。将以下 create table 语句复制到 Amazon Keyspaces CQL 控制台。然后在创建表后执行以下插入和选择语句。

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

然后 INSERT 语句将使用 JSON API 插入一些 JSON 数据。 Bellow 是一个 SELECT 语句,用于从表中查询数据。


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;

【讨论】:

    猜你喜欢
    • 2021-11-11
    • 2022-11-18
    • 2022-08-22
    • 1970-01-01
    • 2021-05-08
    • 2021-10-15
    • 2021-01-31
    • 2021-10-14
    • 2020-09-24
    相关资源
    最近更新 更多