basic.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692
  1. package basic
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "testing"
  6. "time"
  7. . "git.wecise.com/wecise/odbserver/odb"
  8. "git.wecise.com/wecise/odbserver/odb/test"
  9. "gitee.com/wecisecode/util/logger"
  10. "github.com/stretchr/testify/assert"
  11. "github.com/stretchr/testify/require"
  12. )
  13. type BasicTests struct {
  14. Test *testing.T
  15. g *Gutil
  16. }
  17. func BasicTest(t *testing.T) {
  18. g := test.TestG()
  19. t.Run("InitG", func(t *testing.T) {
  20. test := &BasicTests{Test: t, g: g}
  21. test.InitG()
  22. })
  23. t.Run("Class", func(t *testing.T) {
  24. test := &BasicTests{Test: t, g: g}
  25. test.Class()
  26. })
  27. t.Run("Data", func(t *testing.T) {
  28. test := &BasicTests{Test: t, g: g}
  29. test.Data()
  30. })
  31. time.Sleep(time.Duration(5) * time.Second)
  32. t.Run("Valid", func(t *testing.T) {
  33. test := &BasicTests{Test: t, g: g}
  34. test.Valid()
  35. })
  36. t.Run("Int", func(t *testing.T) {
  37. test := &BasicTests{Test: t, g: g}
  38. test.Int()
  39. })
  40. t.Run("Bool", func(t *testing.T) {
  41. test := &BasicTests{Test: t, g: g}
  42. test.Bool()
  43. })
  44. t.Run("FullSearch", func(t *testing.T) {
  45. test := &BasicTests{Test: t, g: g}
  46. test.FullSearch()
  47. })
  48. t.Run("Prefix", func(t *testing.T) {
  49. test := &BasicTests{Test: t, g: g}
  50. test.Prefix()
  51. })
  52. t.Run("NotIn", func(t *testing.T) {
  53. test := &BasicTests{Test: t, g: g}
  54. test.NotIn()
  55. })
  56. /*t.Run("Rename", func(t *testing.T) {
  57. test := &BasicTests{Test: t, g: g}
  58. test.Rename()
  59. })*/
  60. t.Run("Float", func(t *testing.T) {
  61. test := &BasicTests{Test: t, g: g}
  62. test.Float()
  63. })
  64. t.Run("Double", func(t *testing.T) {
  65. test := &BasicTests{Test: t, g: g}
  66. test.Double()
  67. })
  68. t.Run("Aggr", func(t *testing.T) {
  69. test := &BasicTests{Test: t, g: g}
  70. test.Aggr()
  71. })
  72. t.Run("PrivateField", func(t *testing.T) {
  73. test := &BasicTests{Test: t, g: g}
  74. test.PrivateField()
  75. })
  76. t.Run("Data2", func(t *testing.T) {
  77. test := &BasicTests{Test: t, g: g}
  78. test.Data2()
  79. })
  80. t.Run("Valid2", func(t *testing.T) {
  81. test := &BasicTests{Test: t, g: g}
  82. test.Valid2()
  83. })
  84. t.Run("Int2", func(t *testing.T) {
  85. test := &BasicTests{Test: t, g: g}
  86. test.Int2()
  87. })
  88. t.Run("Bool2", func(t *testing.T) {
  89. test := &BasicTests{Test: t, g: g}
  90. test.Bool2()
  91. })
  92. t.Run("FullSearch2", func(t *testing.T) {
  93. test := &BasicTests{Test: t, g: g}
  94. test.FullSearch2()
  95. })
  96. t.Run("Prefix2", func(t *testing.T) {
  97. test := &BasicTests{Test: t, g: g}
  98. test.Prefix2()
  99. })
  100. t.Run("NotIn2", func(t *testing.T) {
  101. test := &BasicTests{Test: t, g: g}
  102. test.NotIn2()
  103. })
  104. t.Run("Float2", func(t *testing.T) {
  105. test := &BasicTests{Test: t, g: g}
  106. test.Float2()
  107. })
  108. t.Run("Double2", func(t *testing.T) {
  109. test := &BasicTests{Test: t, g: g}
  110. test.Double2()
  111. })
  112. t.Run("Aggr2", func(t *testing.T) {
  113. test := &BasicTests{Test: t, g: g}
  114. test.Aggr2()
  115. })
  116. }
  117. func (t *BasicTests) InitG() {
  118. require.NotNil(t.Test, t.g)
  119. // namespace test
  120. _, _, err := t.g.Query(` create class if not exists /test() with namespace="test" `)
  121. if err != nil {
  122. fmt.Printf("%s, %v", t.g.Keyspace, err)
  123. logger.Errorf("%v", err)
  124. }
  125. _, _, err = t.g.Query(` create edge type if not exists test.connect `)
  126. if err != nil {
  127. fmt.Printf("%s, %v", t.g.Keyspace, err)
  128. logger.Errorf("%v", err)
  129. }
  130. //normal test
  131. //t.g.Query(` create class if not exists /test() `)
  132. }
  133. func (t *BasicTests) Class() {
  134. // clear exists data
  135. t.g.Query(`
  136. delete from /test/basic with version;
  137. `)
  138. t.g.Query(`
  139. delete from /test/basic2 with version;
  140. `)
  141. _, _, err := t.g.Query(`
  142. drop class if exists /test/basic/;
  143. `)
  144. if err != nil {
  145. fmt.Printf("%s, %v", t.g.Keyspace, err)
  146. logger.Errorf("%v", err)
  147. }
  148. _, _, err = t.g.Query(`
  149. drop class if exists /test/basic2/;
  150. `)
  151. if err != nil {
  152. fmt.Printf("%s, %v", t.g.Keyspace, err)
  153. logger.Errorf("%v", err)
  154. }
  155. require.Nil(t.Test, err, fmt.Sprint(err))
  156. _, _, err = t.g.Query(`
  157. typedef if not exists STRSTR = varchar ;
  158. typedef if not exists DOUDOU = double ;
  159. `)
  160. if err != nil {
  161. fmt.Printf("%s, %v", t.g.Keyspace, err)
  162. logger.Errorf("%v", err)
  163. }
  164. require.Nil(t.Test, err, fmt.Sprint(err))
  165. _, _, err = t.g.Query(`
  166. create class if not exists /test/basic (
  167. v_varchar STRSTR,
  168. v_text text,
  169. v_int int,
  170. v_bigint bigint,
  171. v_smalldouble double,
  172. v_double DOUDOU,
  173. v_float float,
  174. v_bool bool,
  175. v_blob blob,
  176. indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
  177. keys(v_varchar, v_text)
  178. );
  179. create class if not exists /test/basic2 (
  180. v_varchar STRSTR,
  181. v_text text,
  182. v_int int,
  183. v_bigint bigint,
  184. v_smalldouble double,
  185. v_double DOUDOU,
  186. v_float float,
  187. v_bool bool,
  188. v_blob blob,
  189. indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
  190. keys(v_varchar, v_text)
  191. ) with core=memory ;
  192. create class if not exists /test/basic/mxfield () with autosearch=true , version=false , key=manu, nickname = 'mxfield' ;
  193. --must have nickname for private field
  194. alter class /test/basic with nickname='basic' ;
  195. --taget define in tools, its string
  196. alter class /test/basic add column target int ;
  197. --test hello:version, hello:policy field
  198. create class if not exists /matrix/system/test (
  199. version int,
  200. policy int,
  201. keys(name)
  202. )with nickname='hello';
  203. create class if not exists /test/basic2 (
  204. name text,
  205. keys(name)
  206. ) with nickname='basic2';
  207. `)
  208. if err != nil {
  209. fmt.Printf("%s, %v", t.g.Keyspace, err)
  210. logger.Errorf("%v", err)
  211. }
  212. require.Nil(t.Test, err, fmt.Sprint(err))
  213. }
  214. func (t *BasicTests) Data() {
  215. var err error
  216. _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 1, 1)`)
  217. require.Nil(t.Test, err, fmt.Sprint(err))
  218. _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 2, 2)`)
  219. require.Nil(t.Test, err, fmt.Sprint(err))
  220. _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 3, 3)`)
  221. require.Nil(t.Test, err, fmt.Sprint(err))
  222. _, _, err = t.g.Query(`update /matrix/system/test set version = 4, policy = 4 where name = 'hello' `)
  223. require.Nil(t.Test, err, fmt.Sprint(err))
  224. _, _, err = t.g.Query(`update /matrix/system/test set version = 5, policy = 5 where name = 'hello' `)
  225. require.Nil(t.Test, err, fmt.Sprint(err))
  226. _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool, v_blob) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 5, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, "hello" )`)
  227. require.Nil(t.Test, err, fmt.Sprint(err))
  228. //reinsert
  229. _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  230. require.Nil(t.Test, err, fmt.Sprint(err))
  231. _, _, err = t.g.Query(`insert into /test/basic (name) values ('hello')`)
  232. //require.Nil(t.Test, err, fmt.Sprint(err))
  233. _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'because in both case, Cassandra guarantees that these queries performance will be proportional to the amount of data returned. In particular, if no users are born in 1981, then the second query performance will not depend of the number of user profile stored in the database (not directly at least: due to secondary index implementation consideration, this query may still depend on the number of node in the cluster, which indirectly depends on the amount of data stored. Nevertheless, the number of nodes will always be multiple number of magnitude lower than the number of user profile stored). Of course, both query may return very large result set in practice, but the amount of data returned can always be controlled by adding a LIMIT.', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456,false )`)
  234. require.Nil(t.Test, err, fmt.Sprint(err))
  235. _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('3', '{
  236. "id": "omdb-query-query",
  237. "bid": "omdb-query-query",
  238. "type": "json-update",
  239. "data": {
  240. "message": [
  241. {
  242. "graph": {
  243. "nodes": [
  244. {
  245. "_icon": "app",
  246. "class": "/matrix/entity/app",
  247. "id": "app:demoapp3",
  248. "name": "app:demoapp3",
  249. "status": 5
  250. },
  251. {
  252. "class": "/matrix/entity/pod",
  253. "id": "pod:web-demo-f6dsp"
  254. },
  255. {
  256. "_icon": "mysql",
  257. "class": "/matrix/entity/mysql",
  258. "id": "mysql:demodb",
  259. "name": "mysql:demodb",
  260. "status": 0
  261. },
  262. {
  263. "_icon": "biz",
  264. "class": "/matrix/entity/biz",
  265. "id": "biz:开发测试",
  266. "name": "biz:开发测试",
  267. "status": 4
  268. },
  269. {
  270. "_icon": "linux",
  271. "class": "/matrix/entity/linux",
  272. "id": "linux:node2",
  273. "name": "linux:node2",
  274. "status": 0
  275. },
  276. {
  277. "_icon": "mysql",
  278. "class": "/matrix/entity/mysql",
  279. "id": "mysql:appdb",
  280. "name": "mysql:appdb",
  281. "status": 0
  282. },
  283. {
  284. "_icon": "app",
  285. "class": "/matrix/entity/app",
  286. "id": "app:demoapp2",
  287. "name": "app:demoapp2",
  288. "status": 0
  289. },
  290. {
  291. "_icon": "app",
  292. "class": "/matrix/entity/app",
  293. "id": "app:tomcat-app3",
  294. "name": "app:tomcat-app3",
  295. "status": 5
  296. },
  297. {
  298. "_icon": "linux",
  299. "class": "/matrix/entity/linux",
  300. "id": "linux:node1",
  301. "name": "linux:node1",
  302. "status": 0
  303. },
  304. {
  305. "_icon": "pod",
  306. "class": "/matrix/entity/pod",
  307. "id": "pod:tomcat-pod1",
  308. "name": "pod:tomcat-pod1",
  309. "status": 4
  310. },
  311. {
  312. "_icon": "linux",
  313. "class": "/matrix/entity/linux",
  314. "id": "linux:node4",
  315. "name": "linux:node4",
  316. "status": 0
  317. },
  318. {
  319. "_icon": "app",
  320. "class": "/matrix/entity/app",
  321. "id": "app:demoapp1",
  322. "name": "app:demoapp1",
  323. "status": 0
  324. },
  325. {
  326. "_icon": "pod",
  327. "class": "/matrix/entity/pod",
  328. "id": "pod:mysql-demo-pod1",
  329. "name": "pod:mysql-demo-pod1",
  330. "status": 4
  331. },
  332. {
  333. "_icon": "pod",
  334. "class": "/matrix/entity/pod",
  335. "id": "pod:tomcat-pod2",
  336. "name": "pod:tomcat-pod2",
  337. "status": 4
  338. },
  339. {
  340. "class": "/matrix/entity/pod",
  341. "id": "pod:tomcat-pod3"
  342. },
  343. {
  344. "_icon": "app",
  345. "class": "/matrix/entity/app",
  346. "id": "app:tomcat-app1",
  347. "name": "app:tomcat-app1",
  348. "status": 0
  349. },
  350. {
  351. "_icon": "app",
  352. "class": "/matrix/entity/app",
  353. "id": "app:tomcat-app2",
  354. "name": "app:tomcat-app2",
  355. "status": 0
  356. },
  357. {
  358. "class": "/matrix/entity/pod",
  359. "id": "pod:web-demo-j6qxj"
  360. },
  361. {
  362. "class": "/matrix/entity/pod",
  363. "id": "pod:web-demo-9rfxj"
  364. },
  365. {
  366. "_icon": "biz",
  367. "class": "/matrix/entity/biz",
  368. "id": "biz:数字国网",
  369. "name": "biz:数字国网",
  370. "status": 4
  371. }
  372. ],
  373. "edges": [
  374. {
  375. "attrs": {},
  376. "class": "connect",
  377. "id": "app:demoapp1-mysql:demodb",
  378. "source": "app:demoapp1",
  379. "target": "mysql:demodb"
  380. },
  381. {
  382. "attrs": {},
  383. "class": "contain",
  384. "id": "biz:开发测试-app:demoapp2",
  385. "source": "biz:开发测试",
  386. "target": "app:demoapp2"
  387. },
  388. {
  389. "attrs": {},
  390. "class": "runon",
  391. "id": "mysql:appdb-linux:node4",
  392. "source": "mysql:appdb",
  393. "target": "linux:node4"
  394. },
  395. {
  396. "attrs": {},
  397. "class": "runon",
  398. "id": "mysql:demodb-pod:mysql",
  399. "source": "mysql:demodb",
  400. "target": "pod:mysql"
  401. },
  402. {
  403. "attrs": {},
  404. "class": "runon",
  405. "id": "app:tomcat-app2",
  406. "source": "app:tomcat",
  407. "target": "app2"
  408. },
  409. {
  410. "attrs": {},
  411. "class": "runon",
  412. "id": "pod:tomcat-pod2",
  413. "source": "pod:tomcat",
  414. "target": "pod2"
  415. },
  416. {
  417. "attrs": {},
  418. "class": "runon",
  419. "id": "app:demoapp1-pod:web",
  420. "source": "app:demoapp1",
  421. "target": "pod:web"
  422. },
  423. {
  424. "attrs": {},
  425. "class": "runon",
  426. "id": "pod:mysql-demo",
  427. "source": "pod:mysql",
  428. "target": "demo"
  429. },
  430. {
  431. "attrs": {},
  432. "class": "runon",
  433. "id": "app:demoapp2-pod:web",
  434. "source": "app:demoapp2",
  435. "target": "pod:web"
  436. },
  437. {
  438. "attrs": {},
  439. "class": "connect",
  440. "id": "app:demoapp3-mysql:demodb",
  441. "source": "app:demoapp3",
  442. "target": "mysql:demodb"
  443. },
  444. {
  445. "attrs": {},
  446. "class": "runon",
  447. "id": "app:demoapp3-pod:web",
  448. "source": "app:demoapp3",
  449. "target": "pod:web"
  450. },
  451. {
  452. "attrs": {
  453. "floatp": 3.4,
  454. "intp": 1
  455. },
  456. "class": "contain",
  457. "id": "biz:数字国网-app:tomcat",
  458. "source": "biz:数字国网",
  459. "target": "app:tomcat"
  460. },
  461. {
  462. "attrs": {},
  463. "class": "connect",
  464. "id": "app:tomcat-app3",
  465. "source": "app:tomcat",
  466. "target": "app3"
  467. },
  468. {
  469. "attrs": {},
  470. "class": "contain",
  471. "id": "biz:开发测试-app:demoapp3",
  472. "source": "biz:开发测试",
  473. "target": "app:demoapp3"
  474. },
  475. {
  476. "attrs": {},
  477. "class": "contain",
  478. "id": "biz:开发测试-app:demoapp1",
  479. "source": "biz:开发测试",
  480. "target": "app:demoapp1"
  481. },
  482. {
  483. "attrs": {},
  484. "class": "runon",
  485. "id": "pod:tomcat-pod1",
  486. "source": "pod:tomcat",
  487. "target": "pod1"
  488. },
  489. {
  490. "attrs": {},
  491. "class": "connect",
  492. "id": "app:tomcat-app1",
  493. "source": "app:tomcat",
  494. "target": "app1"
  495. },
  496. {
  497. "attrs": {},
  498. "class": "connect",
  499. "id": "app:demoapp2-mysql:demodb",
  500. "source": "app:demoapp2",
  501. "target": "mysql:demodb"
  502. }
  503. ],
  504. "paths": null,
  505. "diff": null,
  506. "pathtags": null
  507. }
  508. }
  509. ],
  510. "meta": {
  511. "type": "graph"
  512. },
  513. "status": "ok"
  514. }
  515. }', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  516. if err != nil {
  517. logger.Errorf("%v", err)
  518. }
  519. require.Nil(t.Test, err, fmt.Sprint(err))
  520. }
  521. func (t *BasicTests) Data2() {
  522. var err error
  523. _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool, v_blob) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 5, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, "hello" )`)
  524. require.Nil(t.Test, err, fmt.Sprint(err))
  525. //reinsert
  526. _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  527. require.Nil(t.Test, err, fmt.Sprint(err))
  528. //_, _, err = t.g.Query(`insert into /test/basic2 (name) values ('hello')`)
  529. require.Nil(t.Test, err, fmt.Sprint(err))
  530. _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'because in both case, Cassandra guarantees that these queries performance will be proportional to the amount of data returned. In particular, if no users are born in 1981, then the second query performance will not depend of the number of user profile stored in the database (not directly at least: due to secondary index implementation consideration, this query may still depend on the number of node in the cluster, which indirectly depends on the amount of data stored. Nevertheless, the number of nodes will always be multiple number of magnitude lower than the number of user profile stored). Of course, both query may return very large result set in practice, but the amount of data returned can always be controlled by adding a LIMIT.', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456,false )`)
  531. require.Nil(t.Test, err, fmt.Sprint(err))
  532. _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('3', '{
  533. "id": "omdb-query-query",
  534. "bid": "omdb-query-query",
  535. "type": "json-update",
  536. "data": {
  537. "message": [
  538. {
  539. "graph": {
  540. "nodes": [
  541. {
  542. "_icon": "app",
  543. "class": "/matrix/entity/app",
  544. "id": "app:demoapp3",
  545. "name": "app:demoapp3",
  546. "status": 5
  547. },
  548. {
  549. "class": "/matrix/entity/pod",
  550. "id": "pod:web-demo-f6dsp"
  551. },
  552. {
  553. "_icon": "mysql",
  554. "class": "/matrix/entity/mysql",
  555. "id": "mysql:demodb",
  556. "name": "mysql:demodb",
  557. "status": 0
  558. },
  559. {
  560. "_icon": "biz",
  561. "class": "/matrix/entity/biz",
  562. "id": "biz:开发测试",
  563. "name": "biz:开发测试",
  564. "status": 4
  565. },
  566. {
  567. "_icon": "linux",
  568. "class": "/matrix/entity/linux",
  569. "id": "linux:node2",
  570. "name": "linux:node2",
  571. "status": 0
  572. },
  573. {
  574. "_icon": "mysql",
  575. "class": "/matrix/entity/mysql",
  576. "id": "mysql:appdb",
  577. "name": "mysql:appdb",
  578. "status": 0
  579. },
  580. {
  581. "_icon": "app",
  582. "class": "/matrix/entity/app",
  583. "id": "app:demoapp2",
  584. "name": "app:demoapp2",
  585. "status": 0
  586. },
  587. {
  588. "_icon": "app",
  589. "class": "/matrix/entity/app",
  590. "id": "app:tomcat-app3",
  591. "name": "app:tomcat-app3",
  592. "status": 5
  593. },
  594. {
  595. "_icon": "linux",
  596. "class": "/matrix/entity/linux",
  597. "id": "linux:node1",
  598. "name": "linux:node1",
  599. "status": 0
  600. },
  601. {
  602. "_icon": "pod",
  603. "class": "/matrix/entity/pod",
  604. "id": "pod:tomcat-pod1",
  605. "name": "pod:tomcat-pod1",
  606. "status": 4
  607. },
  608. {
  609. "_icon": "linux",
  610. "class": "/matrix/entity/linux",
  611. "id": "linux:node4",
  612. "name": "linux:node4",
  613. "status": 0
  614. },
  615. {
  616. "_icon": "app",
  617. "class": "/matrix/entity/app",
  618. "id": "app:demoapp1",
  619. "name": "app:demoapp1",
  620. "status": 0
  621. },
  622. {
  623. "_icon": "pod",
  624. "class": "/matrix/entity/pod",
  625. "id": "pod:mysql-demo-pod1",
  626. "name": "pod:mysql-demo-pod1",
  627. "status": 4
  628. },
  629. {
  630. "_icon": "pod",
  631. "class": "/matrix/entity/pod",
  632. "id": "pod:tomcat-pod2",
  633. "name": "pod:tomcat-pod2",
  634. "status": 4
  635. },
  636. {
  637. "class": "/matrix/entity/pod",
  638. "id": "pod:tomcat-pod3"
  639. },
  640. {
  641. "_icon": "app",
  642. "class": "/matrix/entity/app",
  643. "id": "app:tomcat-app1",
  644. "name": "app:tomcat-app1",
  645. "status": 0
  646. },
  647. {
  648. "_icon": "app",
  649. "class": "/matrix/entity/app",
  650. "id": "app:tomcat-app2",
  651. "name": "app:tomcat-app2",
  652. "status": 0
  653. },
  654. {
  655. "class": "/matrix/entity/pod",
  656. "id": "pod:web-demo-j6qxj"
  657. },
  658. {
  659. "class": "/matrix/entity/pod",
  660. "id": "pod:web-demo-9rfxj"
  661. },
  662. {
  663. "_icon": "biz",
  664. "class": "/matrix/entity/biz",
  665. "id": "biz:数字国网",
  666. "name": "biz:数字国网",
  667. "status": 4
  668. }
  669. ],
  670. "edges": [
  671. {
  672. "attrs": {},
  673. "class": "connect",
  674. "id": "app:demoapp1-mysql:demodb",
  675. "source": "app:demoapp1",
  676. "target": "mysql:demodb"
  677. },
  678. {
  679. "attrs": {},
  680. "class": "contain",
  681. "id": "biz:开发测试-app:demoapp2",
  682. "source": "biz:开发测试",
  683. "target": "app:demoapp2"
  684. },
  685. {
  686. "attrs": {},
  687. "class": "runon",
  688. "id": "mysql:appdb-linux:node4",
  689. "source": "mysql:appdb",
  690. "target": "linux:node4"
  691. },
  692. {
  693. "attrs": {},
  694. "class": "runon",
  695. "id": "mysql:demodb-pod:mysql",
  696. "source": "mysql:demodb",
  697. "target": "pod:mysql"
  698. },
  699. {
  700. "attrs": {},
  701. "class": "runon",
  702. "id": "app:tomcat-app2",
  703. "source": "app:tomcat",
  704. "target": "app2"
  705. },
  706. {
  707. "attrs": {},
  708. "class": "runon",
  709. "id": "pod:tomcat-pod2",
  710. "source": "pod:tomcat",
  711. "target": "pod2"
  712. },
  713. {
  714. "attrs": {},
  715. "class": "runon",
  716. "id": "app:demoapp1-pod:web",
  717. "source": "app:demoapp1",
  718. "target": "pod:web"
  719. },
  720. {
  721. "attrs": {},
  722. "class": "runon",
  723. "id": "pod:mysql-demo",
  724. "source": "pod:mysql",
  725. "target": "demo"
  726. },
  727. {
  728. "attrs": {},
  729. "class": "runon",
  730. "id": "app:demoapp2-pod:web",
  731. "source": "app:demoapp2",
  732. "target": "pod:web"
  733. },
  734. {
  735. "attrs": {},
  736. "class": "connect",
  737. "id": "app:demoapp3-mysql:demodb",
  738. "source": "app:demoapp3",
  739. "target": "mysql:demodb"
  740. },
  741. {
  742. "attrs": {},
  743. "class": "runon",
  744. "id": "app:demoapp3-pod:web",
  745. "source": "app:demoapp3",
  746. "target": "pod:web"
  747. },
  748. {
  749. "attrs": {
  750. "floatp": 3.4,
  751. "intp": 1
  752. },
  753. "class": "contain",
  754. "id": "biz:数字国网-app:tomcat",
  755. "source": "biz:数字国网",
  756. "target": "app:tomcat"
  757. },
  758. {
  759. "attrs": {},
  760. "class": "connect",
  761. "id": "app:tomcat-app3",
  762. "source": "app:tomcat",
  763. "target": "app3"
  764. },
  765. {
  766. "attrs": {},
  767. "class": "contain",
  768. "id": "biz:开发测试-app:demoapp3",
  769. "source": "biz:开发测试",
  770. "target": "app:demoapp3"
  771. },
  772. {
  773. "attrs": {},
  774. "class": "contain",
  775. "id": "biz:开发测试-app:demoapp1",
  776. "source": "biz:开发测试",
  777. "target": "app:demoapp1"
  778. },
  779. {
  780. "attrs": {},
  781. "class": "runon",
  782. "id": "pod:tomcat-pod1",
  783. "source": "pod:tomcat",
  784. "target": "pod1"
  785. },
  786. {
  787. "attrs": {},
  788. "class": "connect",
  789. "id": "app:tomcat-app1",
  790. "source": "app:tomcat",
  791. "target": "app1"
  792. },
  793. {
  794. "attrs": {},
  795. "class": "connect",
  796. "id": "app:demoapp2-mysql:demodb",
  797. "source": "app:demoapp2",
  798. "target": "mysql:demodb"
  799. }
  800. ],
  801. "paths": null,
  802. "diff": null,
  803. "pathtags": null
  804. }
  805. }
  806. ],
  807. "meta": {
  808. "type": "graph"
  809. },
  810. "status": "ok"
  811. }
  812. }', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  813. if err != nil {
  814. logger.Errorf("%v", err)
  815. }
  816. require.Nil(t.Test, err, fmt.Sprint(err))
  817. }
  818. func (t *BasicTests) Valid() {
  819. rtn, _, err := t.g.Query(`select * from /test/basic refresh`)
  820. if err != nil {
  821. logger.Errorf("%v", err)
  822. }
  823. if assert.Nil(t.Test, err) {
  824. if assert.NotNil(t.Test, rtn) {
  825. assert.Equal(t.Test, 3, len(rtn), "they should be equal")
  826. for _, row := range rtn {
  827. switch row["v_varchar"].(string) {
  828. case "*abc*":
  829. assert.Equal(t.Test, `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, row["v_text"].(string), "they should be equal")
  830. }
  831. }
  832. }
  833. }
  834. rtn, _, err = t.g.Query(` select * from /test/basic where v_varchar=='*abc*' `)
  835. if err != nil {
  836. logger.Errorf("%v", err)
  837. }
  838. if assert.Nil(t.Test, err) {
  839. if assert.NotNil(t.Test, rtn) {
  840. assert.Equal(t.Test, 1, len(rtn), "they should be equal")
  841. }
  842. }
  843. rtn, _, err = t.g.Query(`select * from / where v_varchar=='*abc*' `)
  844. if err != nil {
  845. logger.Errorf("%v", err)
  846. }
  847. if assert.Nil(t.Test, err) {
  848. count := 0
  849. for _, m := range rtn {
  850. v := m["class"]
  851. if c, ok := v.(string); ok && c == "/test/basic" {
  852. count++
  853. }
  854. }
  855. assert.Equal(t.Test, 1, count, "they should be equal")
  856. }
  857. rtn, _, err = t.g.Query(`select * from /test/ where v_varchar=='*abc*' `)
  858. if err != nil {
  859. logger.Errorf("%v", err)
  860. }
  861. if assert.Nil(t.Test, err) {
  862. count := 0
  863. for _, m := range rtn {
  864. v := m["class"]
  865. if c, ok := v.(string); ok && c == "/test/basic" {
  866. count++
  867. }
  868. }
  869. assert.Equal(t.Test, 1, count, "they should be equal")
  870. }
  871. }
  872. func (t *BasicTests) Valid2() {
  873. rtn, _, err := t.g.Query(`select * from /test/basic2`)
  874. if err != nil {
  875. logger.Errorf("%v", err)
  876. }
  877. if false {
  878. bs, _ := json.MarshalIndent(rtn, "", " ")
  879. fmt.Println("/test/basic2 data:\n", string(bs))
  880. }
  881. if assert.Nil(t.Test, err) {
  882. if assert.NotNil(t.Test, rtn) {
  883. assert.Equal(t.Test, 3, len(rtn), "they should be equal")
  884. for _, row := range rtn {
  885. switch row["v_varchar"].(string) {
  886. case "*abc*":
  887. assert.Equal(t.Test, `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, row["v_text"].(string), "they should be equal")
  888. }
  889. }
  890. }
  891. }
  892. rtn, _, err = t.g.Query(` select * from /test/basic2 where v_varchar=='*abc*' `)
  893. if err != nil {
  894. logger.Errorf("%v", err)
  895. }
  896. if assert.Nil(t.Test, err) {
  897. if assert.NotNil(t.Test, rtn) {
  898. assert.Equal(t.Test, 1, len(rtn), "they should be equal")
  899. }
  900. }
  901. // 内存库延迟持久化写入 1s + cassandra索引延迟 1s + cassandra分布式数据同步 1s
  902. time.Sleep(3 * time.Second)
  903. rtn, _, err = t.g.Query(`select * from / where v_varchar=='*abc*' `)
  904. if err != nil {
  905. logger.Errorf("%v", err)
  906. }
  907. if assert.Nil(t.Test, err) {
  908. count := 0
  909. for _, m := range rtn {
  910. v := m["class"]
  911. if c, ok := v.(string); ok && (c == "/test/basic" || c == "/test/basic2") {
  912. count++
  913. }
  914. }
  915. assert.Equal(t.Test, 2, count, "they should be equal")
  916. }
  917. rtn, _, err = t.g.Query(`select * from /test/ where v_varchar=='*abc*' `)
  918. if err != nil {
  919. logger.Errorf("%v", err)
  920. }
  921. if assert.Nil(t.Test, err) {
  922. count := 0
  923. for _, m := range rtn {
  924. v := m["class"]
  925. if c, ok := v.(string); ok && (c == "/test/basic" || c == "/test/basic2") {
  926. count++
  927. }
  928. }
  929. assert.Equal(t.Test, 2, count, "they should be equal")
  930. }
  931. }
  932. func (t *BasicTests) Int() {
  933. var err error
  934. var rtn []map[string]interface{}
  935. rtn, _, err = t.g.Query(`select * from /test/basic where v_int = 1`)
  936. if err != nil {
  937. logger.Errorf("%v", err)
  938. }
  939. if assert.Nil(t.Test, err) {
  940. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int = %v", "1"))
  941. }
  942. rtn, _, err = t.g.Query(`select * from /test/basic where v_int > 0`)
  943. if err != nil {
  944. logger.Errorf("%v", err)
  945. }
  946. if assert.Nil(t.Test, err) {
  947. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int > %v", "0"))
  948. }
  949. rtn, _, err = t.g.Query(`select * from /test/basic where v_int < 2`)
  950. if err != nil {
  951. logger.Errorf("%v", err)
  952. }
  953. if assert.Nil(t.Test, err) {
  954. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int < %v", "2"))
  955. }
  956. rtn, _, err = t.g.Query(`select * from /test/basic where v_int >= 1`)
  957. if err != nil {
  958. logger.Errorf("%v", err)
  959. }
  960. if assert.Nil(t.Test, err) {
  961. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int >= %v", "1"))
  962. }
  963. rtn, _, err = t.g.Query(`select * from /test/basic where v_int <= 1`)
  964. if err != nil {
  965. logger.Errorf("%v", err)
  966. }
  967. if assert.Nil(t.Test, err) {
  968. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int <= %v", "1"))
  969. }
  970. rtn, _, err = t.g.Query(`select * from /test/basic where v_int >= 1.1`)
  971. if err != nil {
  972. logger.Errorf("%v", err)
  973. }
  974. if assert.Nil(t.Test, err) {
  975. assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int >= %v", "1.1"))
  976. }
  977. rtn, _, err = t.g.Query(`select * from /test/basic where v_int > 1`)
  978. if err != nil {
  979. logger.Errorf("%v", err)
  980. }
  981. if assert.Nil(t.Test, err) {
  982. assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int > %v", "1"))
  983. }
  984. }
  985. func (t *BasicTests) Int2() {
  986. var err error
  987. var rtn []map[string]interface{}
  988. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int = 1`)
  989. if err != nil {
  990. logger.Errorf("%v", err)
  991. }
  992. if assert.Nil(t.Test, err) {
  993. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int = %v", "1"))
  994. }
  995. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int > 0`)
  996. if err != nil {
  997. logger.Errorf("%v", err)
  998. }
  999. if assert.Nil(t.Test, err) {
  1000. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int > %v", "0"))
  1001. }
  1002. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int < 2`)
  1003. if err != nil {
  1004. logger.Errorf("%v", err)
  1005. }
  1006. if assert.Nil(t.Test, err) {
  1007. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int < %v", "2"))
  1008. }
  1009. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int >= 1`)
  1010. if err != nil {
  1011. logger.Errorf("%v", err)
  1012. }
  1013. if assert.Nil(t.Test, err) {
  1014. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int >= %v", "1"))
  1015. }
  1016. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int <= 1`)
  1017. if err != nil {
  1018. logger.Errorf("%v", err)
  1019. }
  1020. if assert.Nil(t.Test, err) {
  1021. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int <= %v", "1"))
  1022. }
  1023. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int >= 1.1`)
  1024. if err != nil {
  1025. logger.Errorf("%v", err)
  1026. }
  1027. if assert.Nil(t.Test, err) {
  1028. assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int >= %v", "1.1"))
  1029. }
  1030. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int > 1`)
  1031. if err != nil {
  1032. logger.Errorf("%v", err)
  1033. }
  1034. if assert.Nil(t.Test, err) {
  1035. assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int > %v", "1"))
  1036. }
  1037. }
  1038. func (t *BasicTests) Bool() {
  1039. var err error
  1040. var rtn []map[string]interface{}
  1041. rtn, _, err = t.g.Query(`select * from /test/basic where v_bool = true`)
  1042. if err != nil {
  1043. logger.Errorf("%v", err)
  1044. }
  1045. if assert.Nil(t.Test, err) {
  1046. assert.Equal(t.Test, 2, len(rtn), fmt.Sprintf("not find v_bool = %v", "true"))
  1047. }
  1048. rtn, _, err = t.g.Query(`select * from /test/basic where v_bool = false`)
  1049. if err != nil {
  1050. logger.Errorf("%v", err)
  1051. }
  1052. if assert.Nil(t.Test, err) {
  1053. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find v_bool = %v", "false"))
  1054. }
  1055. }
  1056. func (t *BasicTests) Bool2() {
  1057. var err error
  1058. var rtn []map[string]interface{}
  1059. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_bool = true`)
  1060. if err != nil {
  1061. logger.Errorf("%v", err)
  1062. }
  1063. if assert.Nil(t.Test, err) {
  1064. assert.Equal(t.Test, 2, len(rtn), fmt.Sprintf("not find v_bool = %v", "true"))
  1065. }
  1066. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_bool = false`)
  1067. if err != nil {
  1068. logger.Errorf("%v", err)
  1069. }
  1070. if assert.Nil(t.Test, err) {
  1071. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find v_bool = %v", "false"))
  1072. }
  1073. }
  1074. func (t *BasicTests) Float() {
  1075. var err error
  1076. var rtn []map[string]interface{}
  1077. var allfalse = false
  1078. rtn, _, err = t.g.Query(`select * from /test/basic where v_float >= 1.1`)
  1079. if err != nil {
  1080. logger.Errorf("%v", err)
  1081. }
  1082. if assert.Nil(t.Test, err) {
  1083. allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float >= %v", "1.1"))
  1084. }
  1085. rtn, _, err = t.g.Query(`select * from /test/basic where v_float > 1`)
  1086. if err != nil {
  1087. logger.Errorf("%v", err)
  1088. }
  1089. if assert.Nil(t.Test, err) {
  1090. allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float > %v", "1"))
  1091. }
  1092. rtn, _, err = t.g.Query(`select * from /test/basic where v_float = 1.1`)
  1093. if err != nil {
  1094. logger.Errorf("%v", err)
  1095. }
  1096. if assert.Nil(t.Test, err) {
  1097. allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float = %v", "1.1"))
  1098. }
  1099. rtn, _, err = t.g.Query(`select * from /test/basic where v_float < 2`)
  1100. if err != nil {
  1101. logger.Errorf("%v", err)
  1102. }
  1103. if assert.Nil(t.Test, err) {
  1104. allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float < %v", "2"))
  1105. }
  1106. rtn, _, err = t.g.Query(`select * from /test/basic where v_float <= 1.1`)
  1107. if err != nil {
  1108. logger.Errorf("%v", err)
  1109. }
  1110. if assert.Nil(t.Test, err) {
  1111. allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float <= %v", "1.1"))
  1112. }
  1113. if allfalse == false {
  1114. assert.Nil(t.Test, "浮点数怎么判断都不对,重启cassandra试试")
  1115. }
  1116. }
  1117. func (t *BasicTests) Float2() {
  1118. var err error
  1119. var rtn []map[string]interface{}
  1120. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float >= 1.1`)
  1121. if err != nil {
  1122. logger.Errorf("%v", err)
  1123. }
  1124. if assert.Nil(t.Test, err) {
  1125. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float >= %v", "1.1"))
  1126. }
  1127. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float > 1`)
  1128. if err != nil {
  1129. logger.Errorf("%v", err)
  1130. }
  1131. if assert.Nil(t.Test, err) {
  1132. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float > %v", "1"))
  1133. }
  1134. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float = 1.1`)
  1135. if err != nil {
  1136. logger.Errorf("%v", err)
  1137. }
  1138. if assert.Nil(t.Test, err) {
  1139. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float = %v", "1.1"))
  1140. }
  1141. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float < 2`)
  1142. if err != nil {
  1143. logger.Errorf("%v", err)
  1144. }
  1145. if assert.Nil(t.Test, err) {
  1146. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float < %v", "2"))
  1147. }
  1148. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float <= 1.1`)
  1149. if err != nil {
  1150. logger.Errorf("%v", err)
  1151. }
  1152. if assert.Nil(t.Test, err) {
  1153. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float <= %v", "1.1"))
  1154. }
  1155. }
  1156. func (t *BasicTests) Double() {
  1157. var err error
  1158. var rtn []map[string]interface{}
  1159. rtn, _, err = t.g.Query(`select * from /test/basic where v_double >= 1.1234567890123456`)
  1160. if assert.Nil(t.Test, err) {
  1161. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
  1162. }
  1163. //??????
  1164. rtn, _, err = t.g.Query(`select * from /test/basic where v_smalldouble >= 1.123456`)
  1165. if err != nil {
  1166. logger.Errorf("%v", err)
  1167. }
  1168. if assert.Nil(t.Test, err) {
  1169. if assert.NotNil(t.Test, rtn) {
  1170. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
  1171. }
  1172. }
  1173. rtn, _, err = t.g.Query(`select * from /test/basic where v_double > 1`)
  1174. if err != nil {
  1175. logger.Errorf("%v", err)
  1176. }
  1177. if assert.Nil(t.Test, err) {
  1178. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double > %v", "1"))
  1179. }
  1180. rtn, _, err = t.g.Query(`select * from /test/basic where v_double = 1.1234567890123456`)
  1181. if err != nil {
  1182. logger.Errorf("%v", err)
  1183. }
  1184. if assert.Nil(t.Test, err) {
  1185. assert.NotEqual(t.Test, int64(3), len(rtn), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
  1186. }
  1187. rtn, _, err = t.g.Query(`select * from /test/basic where v_double < 2`)
  1188. if err != nil {
  1189. logger.Errorf("%v", err)
  1190. }
  1191. if assert.Nil(t.Test, err) {
  1192. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double < %v", "2"))
  1193. }
  1194. rtn, _, err = t.g.Query(`select * from /test/basic where v_double <= 1.1234567890123456`)
  1195. if err != nil {
  1196. logger.Errorf("%v", err)
  1197. }
  1198. if assert.Nil(t.Test, err) {
  1199. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
  1200. }
  1201. }
  1202. func (t *BasicTests) Double2() {
  1203. var err error
  1204. var rtn []map[string]interface{}
  1205. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double >= 1.1234567890123456`)
  1206. if assert.Nil(t.Test, err) {
  1207. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
  1208. }
  1209. //??????
  1210. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_smalldouble >= 1.123456`)
  1211. if err != nil {
  1212. logger.Errorf("%v", err)
  1213. }
  1214. if assert.Nil(t.Test, err) {
  1215. if assert.NotNil(t.Test, rtn) {
  1216. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
  1217. }
  1218. }
  1219. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double > 1`)
  1220. if err != nil {
  1221. logger.Errorf("%v", err)
  1222. }
  1223. if assert.Nil(t.Test, err) {
  1224. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double > %v", "1"))
  1225. }
  1226. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double = 1.1234567890123456`)
  1227. if err != nil {
  1228. logger.Errorf("%v", err)
  1229. }
  1230. if assert.Nil(t.Test, err) {
  1231. assert.NotEqual(t.Test, int64(3), len(rtn), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
  1232. }
  1233. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double < 2`)
  1234. if err != nil {
  1235. logger.Errorf("%v", err)
  1236. }
  1237. if assert.Nil(t.Test, err) {
  1238. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double < %v", "2"))
  1239. }
  1240. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double <= 1.1234567890123456`)
  1241. if err != nil {
  1242. logger.Errorf("%v", err)
  1243. }
  1244. if assert.Nil(t.Test, err) {
  1245. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
  1246. }
  1247. }
  1248. func (t *BasicTests) NotIn() {
  1249. var err error
  1250. var rtn []map[string]interface{}
  1251. rtn, _, err = t.g.Query(`select * from /test/basic where v_varchar not in('2', '3')`)
  1252. if err != nil {
  1253. logger.Errorf("%v", err)
  1254. }
  1255. if assert.Nil(t.Test, err) {
  1256. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1257. }
  1258. }
  1259. func (t *BasicTests) NotIn2() {
  1260. var err error
  1261. var rtn []map[string]interface{}
  1262. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_varchar not in('2', '3')`)
  1263. if err != nil {
  1264. logger.Errorf("%v", err)
  1265. }
  1266. if assert.Nil(t.Test, err) {
  1267. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1268. }
  1269. }
  1270. func (t *BasicTests) Prefix() {
  1271. var err error
  1272. var rtn []map[string]interface{}
  1273. rtn, _, err = t.g.Query(`select * from /test/basic where v_text=^'hell'`)
  1274. if err != nil {
  1275. logger.Errorf("%v", err)
  1276. }
  1277. if assert.Nil(t.Test, err) {
  1278. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1279. }
  1280. rtn, _, err = t.g.Query(`select *from /test/basic where v_text='*20*'`)
  1281. if err != nil {
  1282. logger.Errorf("%v", err)
  1283. }
  1284. if assert.Nil(t.Test, err) {
  1285. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
  1286. }
  1287. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*123-456*'`)
  1288. if err != nil {
  1289. logger.Errorf("%v", err)
  1290. }
  1291. if assert.Nil(t.Test, err) {
  1292. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
  1293. }
  1294. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*中*'`)
  1295. if err != nil {
  1296. logger.Errorf("%v", err)
  1297. }
  1298. if assert.Nil(t.Test, err) {
  1299. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
  1300. }
  1301. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*magni*'`)
  1302. if err != nil {
  1303. logger.Errorf("%v", err)
  1304. }
  1305. if assert.Nil(t.Test, err) {
  1306. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
  1307. }
  1308. }
  1309. func (t *BasicTests) Prefix2() {
  1310. var err error
  1311. var rtn []map[string]interface{}
  1312. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text=^'hell'`)
  1313. if err != nil {
  1314. logger.Errorf("%v", err)
  1315. }
  1316. if assert.Nil(t.Test, err) {
  1317. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1318. }
  1319. rtn, _, err = t.g.Query(`select *from /test/basic2 where v_text='*20*'`)
  1320. if err != nil {
  1321. logger.Errorf("%v", err)
  1322. }
  1323. if assert.Nil(t.Test, err) {
  1324. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
  1325. }
  1326. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*123-456*'`)
  1327. if err != nil {
  1328. logger.Errorf("%v", err)
  1329. }
  1330. if assert.Nil(t.Test, err) {
  1331. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
  1332. }
  1333. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*中*'`)
  1334. if err != nil {
  1335. logger.Errorf("%v", err)
  1336. }
  1337. if assert.Nil(t.Test, err) {
  1338. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
  1339. }
  1340. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*magni*'`)
  1341. if err != nil {
  1342. logger.Errorf("%v", err)
  1343. }
  1344. if assert.Nil(t.Test, err) {
  1345. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
  1346. }
  1347. }
  1348. func (t *BasicTests) FullSearch() {
  1349. var err error
  1350. var rtn []map[string]interface{}
  1351. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='hello'`)
  1352. if err != nil {
  1353. logger.Errorf("%v", err)
  1354. }
  1355. if assert.Nil(t.Test, err) {
  1356. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1357. }
  1358. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='2003'`)
  1359. if err != nil {
  1360. logger.Errorf("%v", err)
  1361. }
  1362. if assert.Nil(t.Test, err) {
  1363. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
  1364. }
  1365. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='123-456-789'`)
  1366. if err != nil {
  1367. logger.Errorf("%v", err)
  1368. }
  1369. if assert.Nil(t.Test, err) {
  1370. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
  1371. }
  1372. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='中国'`)
  1373. if err != nil {
  1374. logger.Errorf("%v", err)
  1375. }
  1376. if assert.Nil(t.Test, err) {
  1377. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
  1378. }
  1379. rtn, _, err = t.g.Query(`select * from /test/basic where v_text='magnitude'`)
  1380. if err != nil {
  1381. logger.Errorf("%v", err)
  1382. }
  1383. if assert.Nil(t.Test, err) {
  1384. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
  1385. }
  1386. }
  1387. func (t *BasicTests) FullSearch2() {
  1388. var err error
  1389. var rtn []map[string]interface{}
  1390. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='hello'`)
  1391. if err != nil {
  1392. logger.Errorf("%v", err)
  1393. }
  1394. if assert.Nil(t.Test, err) {
  1395. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
  1396. }
  1397. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='2003'`)
  1398. if err != nil {
  1399. logger.Errorf("%v", err)
  1400. }
  1401. if assert.Nil(t.Test, err) {
  1402. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
  1403. }
  1404. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='123-456-789'`)
  1405. if err != nil {
  1406. logger.Errorf("%v", err)
  1407. }
  1408. if assert.Nil(t.Test, err) {
  1409. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
  1410. }
  1411. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='中国'`)
  1412. if err != nil {
  1413. logger.Errorf("%v", err)
  1414. }
  1415. if assert.Nil(t.Test, err) {
  1416. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
  1417. }
  1418. rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='magnitude'`)
  1419. if err != nil {
  1420. logger.Errorf("%v", err)
  1421. }
  1422. if assert.Nil(t.Test, err) {
  1423. assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
  1424. }
  1425. }
  1426. func (t *BasicTests) Aggr() {
  1427. var err error
  1428. var rtn []map[string]interface{}
  1429. _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'hhhhhh', 1, 1534567890123456789, 1.3, 2.1234567890123456, 1.223456, true )`)
  1430. rtn, _, err = t.g.Query(`select count(*) from /test/basic group by v_varchar`)
  1431. if err != nil {
  1432. logger.Errorf("%v", err)
  1433. }
  1434. if assert.Nil(t.Test, err) {
  1435. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("count group by %v", "varchar"))
  1436. }
  1437. rtn, _, err = t.g.Query(`select sum(v_float), min(v_int), max(v_double) , avg(v_int) as avgint, v_varchar from /test/basic group by v_varchar`)
  1438. if err != nil {
  1439. logger.Errorf("%v", err)
  1440. }
  1441. if assert.Nil(t.Test, err) {
  1442. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("agr group by %v", "varchar"))
  1443. }
  1444. }
  1445. func (t *BasicTests) Aggr2() {
  1446. var err error
  1447. var rtn []map[string]interface{}
  1448. _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'hhhhhh', 1, 1534567890123456789, 1.3, 2.1234567890123456, 1.223456, true )`)
  1449. rtn, _, err = t.g.Query(`select count(*) from /test/basic2 group by v_varchar`)
  1450. if err != nil {
  1451. logger.Errorf("%v", err)
  1452. }
  1453. if assert.Nil(t.Test, err) {
  1454. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("count group by %v", "varchar"))
  1455. }
  1456. rtn, _, err = t.g.Query(`select sum(v_float), min(v_int), max(v_double) , avg(v_int) as avgint, v_varchar from /test/basic2 group by v_varchar`)
  1457. if err != nil {
  1458. logger.Errorf("%v", err)
  1459. }
  1460. if assert.Nil(t.Test, err) {
  1461. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("agr group by %v", "varchar"))
  1462. }
  1463. }
  1464. func (t *BasicTests) PrivateField() {
  1465. //rtn, _, err := t.g.Query(`select class from /system/field where name='basic:target'`)
  1466. _, _, err := t.g.Query(`select class from /system/field where namespace='test' and name='basic:target'`)
  1467. if err != nil {
  1468. logger.Errorf("%v", err)
  1469. }
  1470. if assert.Nil(t.Test, err) {
  1471. //assert.Equal(t.Test, 2, len(rtn[0]["class"].([]int)), fmt.Sprintf("private field should 2"))
  1472. }
  1473. }