Cassandra - 更新集类型列

时间:2018-05-17 23:24:11

标签: collections cassandra datastax

我们在cassandra有一张表格,结构如下:

import json
import http.client
import requests
import csv
conn = http.client.HTTPSConnection("api.themoviedb.org")
payload = "{}"
conn.request("GET", "/3/discover/movie?page=20&include_video=false&include_adult=false&sort_by=primary_release_date.desc&language=en-US&api_key=XXXXXXXXXXXXXXXXXXXXXXXXXXX", payload)
res = conn.getresponse()
data = res.read()
json_data = json.loads(data)
results=json_data["results"]
for item in results:
    print (item('vote_count'))
    #write code to get necessary objects to write in csv

我需要使用java驱动程序为州建立城市的价值, 有这个代码:

OrderProformaInvoice::where('opi_id', $poi)
    ->with('buyer', 'buyerJobs', 'buyerOrders')
    ->orderBy('created_at', 'DESC')
    ->get()
    ->groupBy('invoice_no');

@foreach($orderProformaInvoiceDetails as $invoice_no => $details)
    @foreach($details as $detail)
        {{ $detail->quantity }}
    @endforeach
@endforeach

给出错误,例如“HashSet无法转换为String” 我应该总是需要在现有城市增加更多城市。 那么我如何在cassandra中使用绑定参数附加set列。

1 个答案:

答案 0 :(得分:1)

下面一段代码就可以了:

PreparedStatement prepared = session.prepare("UPDATE test.st SET cities = cities + ? WHERE zip = ? and state = ?");
BoundStatement bound = prepared.bind(Collections.singleton("t2"), "2", "1");
session.execute(bound);

您的问题是您开始使用1计数,而Java驱动程序使用基于0的索引。下面的代码片段只是找到我是否将每个索引减少1:

BoundStatement bound2 = prepared.bind();
bound2.setSet(0, Collections.singleton("t3"));
bound2.setString(1, "2");
bound2.setString(2, "1");
session.execute(bound2);