【问题标题】:insert list into table: cassandra将列表插入表中:cassandra
【发布时间】:2016-09-05 05:15:20
【问题描述】:

如何在 cassandra 中插入这样的内容:

{
    "custID" : '12736467',
    "date" : '2013-06-10',
    "orderID" : 19482065,
    "amount" : 216.28,
    "items" : [
        {   "id" : 1
            "sku" : 87482734,
            "quantity" : 4
        },
        {    "id":2
            "sku" : 32851042,
            "quantity" : 2
        }
    ]
}

我认为在 cassandra 中存储这些数据的最佳方法是创建一个包含 family 列的表:

custId   | date     | orderID | amount | items
                                        id | sku     | quantity
12736467 2013-06-10  19482065  216.28   1   87482734  4
                                        2   32851042  2

create table items {
id text,
sku int,
quantity int};

create table test  {
  custId   text,
  date bigint,
  orderId text,
  amount float,
  items list<items >,
  PRIMARY KEY ((custId))
};

但是如何在每次不使用更新的情况下插入此表(插入测试...)。

【问题讨论】:

    标签: sql cassandra nosql


    【解决方案1】:

    与其创建表,不如创建一个用户定义类型。

    然后使用以下内容:

    INSERT INTO items ("custId", date, "orderId", amount, items)
           VALUES ( 'custid', 123456, 'orderid', 10.0, 
                    [ { 'id' : '1', 'sku' : 12345, 'quantity' : 4 },
                      { 'id' : '2', 'sku' : 12345, 'quantity' : 2 }]);
    

    【讨论】:

      猜你喜欢
      • 2016-07-06
      • 1970-01-01
      • 2017-06-28
      • 1970-01-01
      • 2017-09-17
      • 2020-10-22
      • 2021-12-10
      • 2021-12-30
      • 2020-11-04
      相关资源
      最近更新 更多