| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package main
- import (
- "fmt"
- "strconv"
- "strings"
- "git.wecise.com/wecise/odbserver/odb"
- "gitee.com/wecisecode/util/logger"
- )
- func main() {
- obj := `create table if not exists object(
- id varchar,
- day date,
- class text,
- tokens text,
- vtime timestamp,
- `
- vobj := `CREATE TABLE IF NOT EXISTS vobject (
- id varchar,
- day date,
- class text,
- tokens text,
- vtime timestamp,
- `
- obj_lucene := `CREATE CUSTOM INDEX IF NOT EXISTS object_lucene ON object ()
- USING 'com.stratio.cassandra.lucene.Index'
- WITH OPTIONS = {
- 'refresh_seconds' : '1',
- 'indexing_threads': '16',
- 'indexing_queues_size' : '200',
- 'schema' : '{
- fields : {
- class : {type : "string"},
- tokens: {type : "text"},
- day : {type : "date", pattern :"yyyy-MM-dd"},
- vtime : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"},
- `
- vobj_lucene := `CREATE CUSTOM INDEX IF NOT EXISTS vobject_lucene ON vobject ()
- USING 'com.stratio.cassandra.lucene.Index'
- WITH OPTIONS = {
- 'refresh_seconds' : '1',
- 'ram_buffer_mb' : '128',
- 'indexing_threads': '16',
- 'indexing_queues_size' : '200',
- 'schema' : '{
- fields : {
- class : {type : "string"},
- tokens: {type : "text"},
- day : {type : "date", pattern :"yyyy-MM-dd"},
- vtime : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"},
- `
- option := &odb.Option{Cache: odb.CacheAll}
- g, err := odb.test.NewG(option)
- if err != nil {
- logger.Error(err.Error())
- } else {
- defer g.Close()
- }
- if colcap, err := g.GetSession().SliceMap(`SELECT cap FROM bulkmeta WHERE domain = ? limit 1`, "matrix"); err != nil {
- return
- } else {
- cols := colcap[0]["cap"].(map[string]int)
- col_type := []string{}
- col_lucene := []string{}
- for name, count := range cols {
- t := strings.Split(name, "_")
- for i := 0; i < count; i++ {
- colname := name + "_" + strconv.Itoa(i)
- colname_noidx := "n" + colname
- switch len(t) {
- case 1:
- col_type = append(col_type, colname+" "+name)
- col_type = append(col_type, colname_noidx+" "+name)
- switch t[0] {
- case "varchar":
- col_lucene = append(col_lucene, colname+` : {type : "string"} `)
- case "text":
- col_lucene = append(col_lucene, colname+` : {type : "text"} `)
- case "int":
- col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
- case "bigint":
- col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
- case "double":
- col_lucene = append(col_lucene, colname+` : {type : "double"} `)
- case "float":
- col_lucene = append(col_lucene, colname+` : {type : "float"} `)
- case "boolean":
- col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
- case "blob":
- col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
- case "date":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
- case "timestamp":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
- case "uuid":
- col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
- case "inet":
- col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
- }
- case 2:
- col_type = append(col_type, colname+" "+t[0]+"<"+t[1]+">")
- col_type = append(col_type, colname_noidx+" "+t[0]+"<"+t[1]+">")
- switch t[1] {
- case "varchar":
- col_lucene = append(col_lucene, colname+` : {type : "string"} `)
- case "text":
- col_lucene = append(col_lucene, colname+` : {type : "text"} `)
- case "int":
- col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
- case "bigint":
- col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
- case "double":
- col_lucene = append(col_lucene, colname+` : {type : "double"} `)
- case "float":
- col_lucene = append(col_lucene, colname+` : {type : "float"} `)
- case "boolean":
- col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
- case "blob":
- col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
- case "date":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
- case "timestamp":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
- case "uuid":
- col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
- case "inet":
- col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
- }
- case 3:
- if t[2] != "set" {
- col_type = append(col_type, colname+" "+t[0]+"<"+t[1]+", "+t[2]+">")
- col_type = append(col_type, colname_noidx+" "+t[0]+"<"+t[1]+", "+t[2]+">")
- switch t[2] {
- case "varchar":
- col_lucene = append(col_lucene, colname+` : {type : "string"} `)
- case "text":
- col_lucene = append(col_lucene, colname+` : {type : "text"} `)
- case "int":
- col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
- case "bigint":
- col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
- case "double":
- col_lucene = append(col_lucene, colname+` : {type : "double"} `)
- case "float":
- col_lucene = append(col_lucene, colname+` : {type : "float"} `)
- case "boolean":
- col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
- case "blob":
- col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
- case "date":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
- case "timestamp":
- col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
- case "uuid":
- col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
- case "inet":
- col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
- }
- } else {
- col_type = append(col_type, colname+" "+" map<varchar,frozen<set<varchar>>>")
- col_lucene = append(col_lucene, colname+` : {type : "string"} `)
- }
- }
- }
- }
- obj = obj + strings.Join(col_type, ",\n") + ","
- vobj = vobj + strings.Join(col_type, ",\n") + ","
- obj_lucene = obj_lucene + strings.Join(col_lucene, ",\n")
- vobj_lucene = vobj_lucene + strings.Join(col_lucene, ",\n")
- }
- obj = obj + `
- primary key (id, class)
- ) WITH compaction = {'class' : 'LeveledCompactionStrategy'};
- `
- vobj = vobj + `
- PRIMARY KEY ( (id, day), vtime)
- ) WITH CLUSTERING ORDER BY (vtime DESC) AND compaction = { 'class' : 'TimeWindowCompactionStrategy', 'compaction_window_unit': 'DAYS', 'compaction_window_size': '7' } AND read_repair_chance = 0.2;
- `
- obj_lucene = obj_lucene + ` }
- }'
- };
- `
- vobj_lucene = vobj_lucene + ` }
- }'
- };
- `
- fmt.Println(obj)
- fmt.Println(vobj)
- fmt.Println(obj_lucene)
- fmt.Println(vobj_lucene)
- }
|