【发布时间】:2017-10-10 20:35:03
【问题描述】:
我正在开发一个带有聚类列的时间序列数据模型,即
CREATE TABLE events (
id text,
time timestamp,
type text,
val double,
PRIMARY KEY (id, time)
) WITH CLUSTERING ORDER BY (time DESC)
我希望对分区列“id”和聚类列“时间”执行选择。例如 id:='1', timestamp:='2017-10-09'
query := "SELECT id, time, type, val FROM events WHERE id=? AND time>=?"
iterable := Cassandra.Session.Query(query, id, timestamp).Consistency(gocql.One).Iter()
for iterable.MapScan(m) {
found = true
event = Event{
ID: m["id"].(string),
Time: m["time"].(time.Time),
Type: m["type"].(string),
Val: m["val"].(float64),
}
}
在iterable.Close()上检查err后,发现marshalling出错
{"errors":["无法将字符串编组为时间戳"]}
我该如何解决这个问题?
【问题讨论】:
-
你可以尝试使用this
fmt.Println(reflect.TypeOf(m["time"])打印m["time"]的类型吗? -
类型为time.Time。
-
我已经解决了这个问题。似乎时间戳需要是 time.Time 的类型,它目前使用字符串文字。在我将字符串转换为 time.Time 并输入函数后,一切正常。
-
很高兴你修好了 :)