/* 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 ( "fmt" "os" "strconv" "strings" "time" "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 := "demo" if len(os.Args) > 1 { keyspace = os.Args[1] } 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) colcap := map[string]int{} if rows, err := g.RawQuery(`select column_name from system_schema.columns where keyspace_name=? and table_name='object'`, keyspace); err != nil { logger.Error(err) return } else { for _, row := range rows { col := row["column_name"].(string) if strings.HasPrefix(col, "_") { continue } if idx := strings.LastIndex(col, "_"); idx == -1 { continue } else { prefix := col[:idx] n, _ := strconv.Atoi(col[idx+1:]) if max, ok := colcap[prefix]; ok { if n > max { colcap[prefix] = n } } else { colcap[prefix] = n } } } } var collucene = map[string]string{ "varchar": `{"type" : "string"}`, "text": `{"type" : "text"}`, "smallint": `{"type" : "integer"}`, "int": `{"type" : "integer"}`, "bigint": `{"type" : "bigint"}`, "double": `{"type" : "double"}`, "float": `{"type" : "float"}`, "boolean": `{"type" : "boolean"}`, "blob": `{"type" : "bytes"}`, "date": `{"type" : "date", "pattern" :"yyyy-MM-dd"}`, "timestamp": `{"type" : "date", "pattern" :"yyyy-MM-dd HH:mm:ss.SSS"}`, "set_varchar": `{"type" : "string"}`, "set_text": `{"type" : "text"}`, "set_double": `{"type" : "double"}`, "set_float": `{"type" : "float"}`, "set_int": `{"type" : "integer"}`, "list_varchar": `{"type" : "string"}`, "list_text": `{"type" : "text"}`, "list_double": `{"type" : "double"}`, "list_float": `{"type" : "float"}`, "list_int": `{"type" : "integer"}`, "map_varchar_text": `{"type" : "text"}`, "map_varchar_varchar": `{"type" : "string"}`, "map_varchar_float": `{"type" : "float"}`, "map_varchar_set": `{"type" : "string"}`, } var colstamp = map[string]time.Time{} now := time.Now() for colprefix := range colcap { colstamp[colprefix] = now } fmt.Println("update colbulk ...") logger.Warn(colcap) if _, err := g.RawQuery(`INSERT INTO colbulk (domain, cap, collucene, colstamp) VALUES(?, ?, ?, ?)`, keyspace, colcap, collucene, colstamp); err != nil { logger.Errorf(" error: %v", err) } }