gocql - 使用 Cassandra 3 timeuuid 函数
gocql - using Cassandra 3 timeuuid functions
在 cqlsh 中,我可以执行如下操作:
SELECT id FROM names WHERE name = 'dave' AND id > maxTimeuuid('2015-04-05 00:05') AND id < minTimeuuid('2019-01-01 00:05');
...这个 returns 符合预期的列表。
id
--------------------------------------
632f4960-375b-11e8-90b1-02420a000203
91f03523-3761-11e8-a777-02420a000a05
32dbffc4-3762-11e8-a778-02420a000a05
9ffb1ab8-3762-11e8-a779-02420a000a05
c28a0372-3764-11e8-a77b-02420a000a05
但是我正在努力让它在 gocql 中工作:
var found bool = false
m := map[string]interface{}{}
qString := "SELECT id FROM names WHERE name=? AND id > maxTimeuuid(?) AND id < minTimeuuid(?);"
query := Cassandra.Sessionds.Query(qString, name, toFrom.From, toFrom.To).Consistency(gocql.One)
fmt.Println("sending IsRunning query: " + query.String())
iterable := query.Iter()
for iterable.MapScan(m) {
found = true
lookupTable = HostLookup {
Id: m["id"].(gocql.UUID),
}
}
尽管调试行看起来没问题,
sending IsRunning query: [query statement="SELECT id FROM names WHERE name=? AND id > maxTimeuuid(?) AND id < minTimeuuid(?);" values=[dave 2015-04-05 00:05 2019-01-01 00:05] consistency=ONE]
...我总是以一个空的可迭代结束。我在其他地方成功地使用了非常相似的代码,这里的区别是 timeuuid 函数。我已经尝试了各种带有文字引号的安排,但都无济于事,我们不胜感激。
当我更详细地查看可迭代对象时,我发现:
"can not marshal string into timestamp"
...这让我找到了答案 -
在 cqlsh 中,我可以执行如下操作:
SELECT id FROM names WHERE name = 'dave' AND id > maxTimeuuid('2015-04-05 00:05') AND id < minTimeuuid('2019-01-01 00:05');
...这个 returns 符合预期的列表。
id
--------------------------------------
632f4960-375b-11e8-90b1-02420a000203
91f03523-3761-11e8-a777-02420a000a05
32dbffc4-3762-11e8-a778-02420a000a05
9ffb1ab8-3762-11e8-a779-02420a000a05
c28a0372-3764-11e8-a77b-02420a000a05
但是我正在努力让它在 gocql 中工作:
var found bool = false
m := map[string]interface{}{}
qString := "SELECT id FROM names WHERE name=? AND id > maxTimeuuid(?) AND id < minTimeuuid(?);"
query := Cassandra.Sessionds.Query(qString, name, toFrom.From, toFrom.To).Consistency(gocql.One)
fmt.Println("sending IsRunning query: " + query.String())
iterable := query.Iter()
for iterable.MapScan(m) {
found = true
lookupTable = HostLookup {
Id: m["id"].(gocql.UUID),
}
}
尽管调试行看起来没问题,
sending IsRunning query: [query statement="SELECT id FROM names WHERE name=? AND id > maxTimeuuid(?) AND id < minTimeuuid(?);" values=[dave 2015-04-05 00:05 2019-01-01 00:05] consistency=ONE]
...我总是以一个空的可迭代结束。我在其他地方成功地使用了非常相似的代码,这里的区别是 timeuuid 函数。我已经尝试了各种带有文字引号的安排,但都无济于事,我们不胜感激。
当我更详细地查看可迭代对象时,我发现:
"can not marshal string into timestamp"
...这让我找到了答案 -