testtype.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package main
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "git.wecise.com/wecise/odbserver/odb"
  7. "gitee.com/wecisecode/util/logger"
  8. )
  9. func main() {
  10. obj := `create table if not exists object(
  11. id varchar,
  12. day date,
  13. class text,
  14. tokens text,
  15. vtime timestamp,
  16. `
  17. vobj := `CREATE TABLE IF NOT EXISTS vobject (
  18. id varchar,
  19. day date,
  20. class text,
  21. tokens text,
  22. vtime timestamp,
  23. `
  24. obj_lucene := `CREATE CUSTOM INDEX IF NOT EXISTS object_lucene ON object ()
  25. USING 'com.stratio.cassandra.lucene.Index'
  26. WITH OPTIONS = {
  27. 'refresh_seconds' : '1',
  28. 'indexing_threads': '16',
  29. 'indexing_queues_size' : '200',
  30. 'schema' : '{
  31. fields : {
  32. class : {type : "string"},
  33. tokens: {type : "text"},
  34. day : {type : "date", pattern :"yyyy-MM-dd"},
  35. vtime : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"},
  36. `
  37. vobj_lucene := `CREATE CUSTOM INDEX IF NOT EXISTS vobject_lucene ON vobject ()
  38. USING 'com.stratio.cassandra.lucene.Index'
  39. WITH OPTIONS = {
  40. 'refresh_seconds' : '1',
  41. 'ram_buffer_mb' : '128',
  42. 'indexing_threads': '16',
  43. 'indexing_queues_size' : '200',
  44. 'schema' : '{
  45. fields : {
  46. class : {type : "string"},
  47. tokens: {type : "text"},
  48. day : {type : "date", pattern :"yyyy-MM-dd"},
  49. vtime : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"},
  50. `
  51. option := &odb.Option{Cache: odb.CacheAll}
  52. g, err := odb.test.NewG(option)
  53. if err != nil {
  54. logger.Error(err.Error())
  55. } else {
  56. defer g.Close()
  57. }
  58. if colcap, err := g.GetSession().SliceMap(`SELECT cap FROM bulkmeta WHERE domain = ? limit 1`, "matrix"); err != nil {
  59. return
  60. } else {
  61. cols := colcap[0]["cap"].(map[string]int)
  62. col_type := []string{}
  63. col_lucene := []string{}
  64. for name, count := range cols {
  65. t := strings.Split(name, "_")
  66. for i := 0; i < count; i++ {
  67. colname := name + "_" + strconv.Itoa(i)
  68. colname_noidx := "n" + colname
  69. switch len(t) {
  70. case 1:
  71. col_type = append(col_type, colname+" "+name)
  72. col_type = append(col_type, colname_noidx+" "+name)
  73. switch t[0] {
  74. case "varchar":
  75. col_lucene = append(col_lucene, colname+` : {type : "string"} `)
  76. case "text":
  77. col_lucene = append(col_lucene, colname+` : {type : "text"} `)
  78. case "int":
  79. col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
  80. case "bigint":
  81. col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
  82. case "double":
  83. col_lucene = append(col_lucene, colname+` : {type : "double"} `)
  84. case "float":
  85. col_lucene = append(col_lucene, colname+` : {type : "float"} `)
  86. case "boolean":
  87. col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
  88. case "blob":
  89. col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
  90. case "date":
  91. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
  92. case "timestamp":
  93. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
  94. case "uuid":
  95. col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
  96. case "inet":
  97. col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
  98. }
  99. case 2:
  100. col_type = append(col_type, colname+" "+t[0]+"<"+t[1]+">")
  101. col_type = append(col_type, colname_noidx+" "+t[0]+"<"+t[1]+">")
  102. switch t[1] {
  103. case "varchar":
  104. col_lucene = append(col_lucene, colname+` : {type : "string"} `)
  105. case "text":
  106. col_lucene = append(col_lucene, colname+` : {type : "text"} `)
  107. case "int":
  108. col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
  109. case "bigint":
  110. col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
  111. case "double":
  112. col_lucene = append(col_lucene, colname+` : {type : "double"} `)
  113. case "float":
  114. col_lucene = append(col_lucene, colname+` : {type : "float"} `)
  115. case "boolean":
  116. col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
  117. case "blob":
  118. col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
  119. case "date":
  120. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
  121. case "timestamp":
  122. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
  123. case "uuid":
  124. col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
  125. case "inet":
  126. col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
  127. }
  128. case 3:
  129. if t[2] != "set" {
  130. col_type = append(col_type, colname+" "+t[0]+"<"+t[1]+", "+t[2]+">")
  131. col_type = append(col_type, colname_noidx+" "+t[0]+"<"+t[1]+", "+t[2]+">")
  132. switch t[2] {
  133. case "varchar":
  134. col_lucene = append(col_lucene, colname+` : {type : "string"} `)
  135. case "text":
  136. col_lucene = append(col_lucene, colname+` : {type : "text"} `)
  137. case "int":
  138. col_lucene = append(col_lucene, colname+` : {type : "integer"} `)
  139. case "bigint":
  140. col_lucene = append(col_lucene, colname+` : {type : "bigint"} `)
  141. case "double":
  142. col_lucene = append(col_lucene, colname+` : {type : "double"} `)
  143. case "float":
  144. col_lucene = append(col_lucene, colname+` : {type : "float"} `)
  145. case "boolean":
  146. col_lucene = append(col_lucene, colname+` : {type : "boolean"} `)
  147. case "blob":
  148. col_lucene = append(col_lucene, colname+` : {type : "bytes"} `)
  149. case "date":
  150. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd"} `)
  151. case "timestamp":
  152. col_lucene = append(col_lucene, colname+` : {type : "date", pattern :"yyyy-MM-dd HH:mm:ss.SSS"} `)
  153. case "uuid":
  154. col_lucene = append(col_lucene, colname+` : {type : "uuid"} `)
  155. case "inet":
  156. col_lucene = append(col_lucene, colname+` : {type : "inet"} `)
  157. }
  158. } else {
  159. col_type = append(col_type, colname+" "+" map<varchar,frozen<set<varchar>>>")
  160. col_lucene = append(col_lucene, colname+` : {type : "string"} `)
  161. }
  162. }
  163. }
  164. }
  165. obj = obj + strings.Join(col_type, ",\n") + ","
  166. vobj = vobj + strings.Join(col_type, ",\n") + ","
  167. obj_lucene = obj_lucene + strings.Join(col_lucene, ",\n")
  168. vobj_lucene = vobj_lucene + strings.Join(col_lucene, ",\n")
  169. }
  170. obj = obj + `
  171. primary key (id, class)
  172. ) WITH compaction = {'class' : 'LeveledCompactionStrategy'};
  173. `
  174. vobj = vobj + `
  175. PRIMARY KEY ( (id, day), vtime)
  176. ) WITH CLUSTERING ORDER BY (vtime DESC) AND compaction = { 'class' : 'TimeWindowCompactionStrategy', 'compaction_window_unit': 'DAYS', 'compaction_window_size': '7' } AND read_repair_chance = 0.2;
  177. `
  178. obj_lucene = obj_lucene + ` }
  179. }'
  180. };
  181. `
  182. vobj_lucene = vobj_lucene + ` }
  183. }'
  184. };
  185. `
  186. fmt.Println(obj)
  187. fmt.Println(vobj)
  188. fmt.Println(obj_lucene)
  189. fmt.Println(vobj_lucene)
  190. }