Search code examples
jsonamazon-web-servicescassandrainsertamazon-keyspaces

Enable Json Insert on Amazon Keyspaces


I am migrating from an hosted Cassandra to Amazon Keyspace.

Some production processes use the Cassandra Json Insert. When I try to run one of this processes to store data in Amazon Keyspaces I get the following error:

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

I suppose that this functionality is not enabled in Amazon Keyspace. On my local Cassandra i didn't enable anything to use JSON insert. There is a way to enable this functionality on Amazon Keyspaces


Solution

  • Keyspaces started supporting JSON on January 22, 2021. You can enter Inserts and Selects using the JSON API the same way you did using Cassandra.

    You can execute insert and select statements using the JSON API against your existing tables.

    Here is a link of Information on how Keyspaces and JSON work together: https://aws.amazon.com/about-aws/whats-new/2021/01/amazon-keyspaces-for-apache-cassandra-now-supports-json-syntax/

    Keyspaces is adding new features all the time. to To see supported APIs visit this.

    Below is an example of the JSON api. Copy the following create table statement into the Amazon Keyspaces CQL Console. Then execute the following insert and select statements after the table has been created.

    The code bellow will create a json_keyspaces Keyspace, then it CREATES a table called shoppingcart. Replace the keyspace name with your own. When its finished you will have a new table called shoppingcart.

    Then the INSERT statement will insert some JSON data using the JSON API. Bellow is a SELECT statement to query the data from the 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;