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>>") 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) }