| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- /*
- Before you execute the program, Launch `cqlsh` and execute:
- create keyspace example with replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
- create table example.tweet(timeline text, id UUID, text text, PRIMARY KEY(id));
- create index on example.tweet(timeline);
- */
- package main
- import (
- // "time"
- "flag"
- "fmt"
- // "strconv"
- "strings"
- "git.wecise.com/wecise/odbserver/odb/cqlfilter"
- "git.wecise.com/wecise/odbserver/odb/stmt"
- "git.wecise.com/wecise/odbserver/odb/test"
- "gitee.com/wecisecode/util/logger"
- )
- func main() {
- // connect to the cluster
- //cluster := gocql.NewCluster("192.168.40.14")
- keyspace := flag.String("keyspace", "matrix", "keyspace")
- flag.Parse()
- option := &Option{Cache: CacheAll, Keyspace: *keyspace, DisableInitialHostLookup: true}
- g, err := test.NewG(option)
- if err != nil {
- logger.Error(err.Error())
- } else {
- defer g.Close()
- }
- //logger.SetRollingDaily("C:/test/zkcron/src/test", "test.log")
- logger.SetConsole(true)
- for cls := range g.MICache.ToMap() {
- for _, relation := range g.Relations_col_as_field(nil) {
- fs := strings.Split(relation, " as ")
- column := fs[0] + "$_all"
- field := column
- if len(fs) == 2 {
- field = fs[1]
- }
- cql := fmt.Sprintf(`select class, %s from object where class='%s' and expr(object_lucene, ?) limit 1`, relation, cls)
- stru := &stmt.FilterStruct{Type: "range", Field: column}
- lucene, _ := cqlfilter.ToLucene(stru, false)
- if rows, err := g.RawQuery(cql, lucene); err != nil {
- logger.Errorf(" error: %v", err)
- } else {
- if len(rows) > 0 {
- value := rows[0][field].(map[string][]string)
- g.RefreshRelationsStats1(rows[0]["class"].(string), field, value)
- //logger.Error(rows[0]["class"], value["_all"])
- }
- }
- }
- }
- }
|