mpartition.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. package partition
  2. import (
  3. "fmt"
  4. "testing"
  5. "time"
  6. . "git.wecise.com/wecise/odbserver/odb"
  7. "git.wecise.com/wecise/odbserver/odb/test"
  8. "gitee.com/wecisecode/util/logger"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/stretchr/testify/require"
  11. )
  12. type MPartitionTests struct {
  13. Test *testing.T
  14. g *Gutil
  15. }
  16. func MPartitionTest(t *testing.T) {
  17. g := test.TestG()
  18. t.Run("InitG", func(t *testing.T) {
  19. test := &MPartitionTests{Test: t, g: g}
  20. test.InitG()
  21. })
  22. t.Run("Class", func(t *testing.T) {
  23. test := &MPartitionTests{Test: t, g: g}
  24. test.Class()
  25. })
  26. t.Run("Data", func(t *testing.T) {
  27. test := &MPartitionTests{Test: t, g: g}
  28. test.Data()
  29. })
  30. time.Sleep(time.Duration(1) * time.Second)
  31. t.Run("Valid", func(t *testing.T) {
  32. test := &MPartitionTests{Test: t, g: g}
  33. test.Valid()
  34. })
  35. t.Run("Int", func(t *testing.T) {
  36. test := &MPartitionTests{Test: t, g: g}
  37. test.Int()
  38. })
  39. t.Run("Bool", func(t *testing.T) {
  40. test := &MPartitionTests{Test: t, g: g}
  41. test.Bool()
  42. })
  43. t.Run("FullSearch", func(t *testing.T) {
  44. test := &MPartitionTests{Test: t, g: g}
  45. test.FullSearch()
  46. })
  47. t.Run("Prefix", func(t *testing.T) {
  48. test := &MPartitionTests{Test: t, g: g}
  49. test.Prefix()
  50. })
  51. t.Run("Float", func(t *testing.T) {
  52. test := &MPartitionTests{Test: t, g: g}
  53. test.Float()
  54. })
  55. t.Run("Double", func(t *testing.T) {
  56. test := &MPartitionTests{Test: t, g: g}
  57. test.Double()
  58. })
  59. t.Run("Update", func(t *testing.T) {
  60. test := &MPartitionTests{Test: t, g: g}
  61. test.Update()
  62. })
  63. }
  64. func (t *MPartitionTests) InitG() {
  65. require.NotNil(t.Test, t.g)
  66. // namespace test
  67. //t.g.Query(` create class if not exists /test() with namespace="test" `)
  68. //t.g.Query(` create edge type test.connect `)
  69. }
  70. func (t *MPartitionTests) Class() {
  71. _, _, err := t.g.Query(`
  72. create class if not exists /test/mpartition (
  73. mv_varchar varchar,
  74. v_text text,
  75. v_int int,
  76. v_bigint bigint,
  77. v_smalldouble double,
  78. v_double double,
  79. v_float float,
  80. v_bool bool,
  81. indexes(mv_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
  82. keys(mv_varchar, v_text, v_int)
  83. ) with partition=(mv_varchar,v_int), onconflict=(v_bigint incr), cache=6000
  84. ;
  85. delete from /test/mpartition with version
  86. ;
  87. `)
  88. if err != nil {
  89. logger.Errorf("%v", err)
  90. }
  91. require.Nil(t.Test, err, fmt.Sprint(err))
  92. }
  93. func (t *MPartitionTests) Data() {
  94. var err error
  95. _, _, err = t.g.Query(`insert into /test/mpartition (mv_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('1', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  96. if err != nil {
  97. logger.Errorf("%v", err)
  98. }
  99. require.Nil(t.Test, err, fmt.Sprint(err))
  100. _, _, err = t.g.Query(`insert into /test/mpartition (mv_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 )`)
  101. if err != nil {
  102. logger.Errorf("%v", err)
  103. }
  104. require.Nil(t.Test, err, fmt.Sprint(err))
  105. _, _, err = t.g.Query(`insert into /test/mpartition (mv_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('3', '{
  106. "id": "omdb-query-query",
  107. "bid": "omdb-query-query",
  108. "type": "json-update",
  109. "data": {
  110. "message": [
  111. {
  112. "graph": {
  113. "nodes": [
  114. {
  115. "_icon": "app",
  116. "class": "/matrix/entity/app",
  117. "id": "app:demoapp3",
  118. "name": "app:demoapp3",
  119. "status": 5
  120. },
  121. {
  122. "class": "/matrix/entity/pod",
  123. "id": "pod:web-demo-f6dsp"
  124. },
  125. {
  126. "_icon": "mysql",
  127. "class": "/matrix/entity/mysql",
  128. "id": "mysql:demodb",
  129. "name": "mysql:demodb",
  130. "status": 0
  131. },
  132. {
  133. "_icon": "biz",
  134. "class": "/matrix/entity/biz",
  135. "id": "biz:开发测试",
  136. "name": "biz:开发测试",
  137. "status": 4
  138. },
  139. {
  140. "_icon": "linux",
  141. "class": "/matrix/entity/linux",
  142. "id": "linux:node2",
  143. "name": "linux:node2",
  144. "status": 0
  145. },
  146. {
  147. "_icon": "mysql",
  148. "class": "/matrix/entity/mysql",
  149. "id": "mysql:appdb",
  150. "name": "mysql:appdb",
  151. "status": 0
  152. },
  153. {
  154. "_icon": "app",
  155. "class": "/matrix/entity/app",
  156. "id": "app:demoapp2",
  157. "name": "app:demoapp2",
  158. "status": 0
  159. },
  160. {
  161. "_icon": "app",
  162. "class": "/matrix/entity/app",
  163. "id": "app:tomcat-app3",
  164. "name": "app:tomcat-app3",
  165. "status": 5
  166. },
  167. {
  168. "_icon": "linux",
  169. "class": "/matrix/entity/linux",
  170. "id": "linux:node1",
  171. "name": "linux:node1",
  172. "status": 0
  173. },
  174. {
  175. "_icon": "pod",
  176. "class": "/matrix/entity/pod",
  177. "id": "pod:tomcat-pod1",
  178. "name": "pod:tomcat-pod1",
  179. "status": 4
  180. },
  181. {
  182. "_icon": "linux",
  183. "class": "/matrix/entity/linux",
  184. "id": "linux:node4",
  185. "name": "linux:node4",
  186. "status": 0
  187. },
  188. {
  189. "_icon": "app",
  190. "class": "/matrix/entity/app",
  191. "id": "app:demoapp1",
  192. "name": "app:demoapp1",
  193. "status": 0
  194. },
  195. {
  196. "_icon": "pod",
  197. "class": "/matrix/entity/pod",
  198. "id": "pod:mysql-demo-pod1",
  199. "name": "pod:mysql-demo-pod1",
  200. "status": 4
  201. },
  202. {
  203. "_icon": "pod",
  204. "class": "/matrix/entity/pod",
  205. "id": "pod:tomcat-pod2",
  206. "name": "pod:tomcat-pod2",
  207. "status": 4
  208. },
  209. {
  210. "class": "/matrix/entity/pod",
  211. "id": "pod:tomcat-pod3"
  212. },
  213. {
  214. "_icon": "app",
  215. "class": "/matrix/entity/app",
  216. "id": "app:tomcat-app1",
  217. "name": "app:tomcat-app1",
  218. "status": 0
  219. },
  220. {
  221. "_icon": "app",
  222. "class": "/matrix/entity/app",
  223. "id": "app:tomcat-app2",
  224. "name": "app:tomcat-app2",
  225. "status": 0
  226. },
  227. {
  228. "class": "/matrix/entity/pod",
  229. "id": "pod:web-demo-j6qxj"
  230. },
  231. {
  232. "class": "/matrix/entity/pod",
  233. "id": "pod:web-demo-9rfxj"
  234. },
  235. {
  236. "_icon": "biz",
  237. "class": "/matrix/entity/biz",
  238. "id": "biz:数字国网",
  239. "name": "biz:数字国网",
  240. "status": 4
  241. }
  242. ],
  243. "edges": [
  244. {
  245. "attrs": {},
  246. "class": "connect",
  247. "id": "app:demoapp1-mysql:demodb",
  248. "source": "app:demoapp1",
  249. "target": "mysql:demodb"
  250. },
  251. {
  252. "attrs": {},
  253. "class": "contain",
  254. "id": "biz:开发测试-app:demoapp2",
  255. "source": "biz:开发测试",
  256. "target": "app:demoapp2"
  257. },
  258. {
  259. "attrs": {},
  260. "class": "runon",
  261. "id": "mysql:appdb-linux:node4",
  262. "source": "mysql:appdb",
  263. "target": "linux:node4"
  264. },
  265. {
  266. "attrs": {},
  267. "class": "runon",
  268. "id": "mysql:demodb-pod:mysql",
  269. "source": "mysql:demodb",
  270. "target": "pod:mysql"
  271. },
  272. {
  273. "attrs": {},
  274. "class": "runon",
  275. "id": "app:tomcat-app2",
  276. "source": "app:tomcat",
  277. "target": "app2"
  278. },
  279. {
  280. "attrs": {},
  281. "class": "runon",
  282. "id": "pod:tomcat-pod2",
  283. "source": "pod:tomcat",
  284. "target": "pod2"
  285. },
  286. {
  287. "attrs": {},
  288. "class": "runon",
  289. "id": "app:demoapp1-pod:web",
  290. "source": "app:demoapp1",
  291. "target": "pod:web"
  292. },
  293. {
  294. "attrs": {},
  295. "class": "runon",
  296. "id": "pod:mysql-demo",
  297. "source": "pod:mysql",
  298. "target": "demo"
  299. },
  300. {
  301. "attrs": {},
  302. "class": "runon",
  303. "id": "app:demoapp2-pod:web",
  304. "source": "app:demoapp2",
  305. "target": "pod:web"
  306. },
  307. {
  308. "attrs": {},
  309. "class": "connect",
  310. "id": "app:demoapp3-mysql:demodb",
  311. "source": "app:demoapp3",
  312. "target": "mysql:demodb"
  313. },
  314. {
  315. "attrs": {},
  316. "class": "runon",
  317. "id": "app:demoapp3-pod:web",
  318. "source": "app:demoapp3",
  319. "target": "pod:web"
  320. },
  321. {
  322. "attrs": {
  323. "floatp": 3.4,
  324. "intp": 1
  325. },
  326. "class": "contain",
  327. "id": "biz:数字国网-app:tomcat",
  328. "source": "biz:数字国网",
  329. "target": "app:tomcat"
  330. },
  331. {
  332. "attrs": {},
  333. "class": "connect",
  334. "id": "app:tomcat-app3",
  335. "source": "app:tomcat",
  336. "target": "app3"
  337. },
  338. {
  339. "attrs": {},
  340. "class": "contain",
  341. "id": "biz:开发测试-app:demoapp3",
  342. "source": "biz:开发测试",
  343. "target": "app:demoapp3"
  344. },
  345. {
  346. "attrs": {},
  347. "class": "contain",
  348. "id": "biz:开发测试-app:demoapp1",
  349. "source": "biz:开发测试",
  350. "target": "app:demoapp1"
  351. },
  352. {
  353. "attrs": {},
  354. "class": "runon",
  355. "id": "pod:tomcat-pod1",
  356. "source": "pod:tomcat",
  357. "target": "pod1"
  358. },
  359. {
  360. "attrs": {},
  361. "class": "connect",
  362. "id": "app:tomcat-app1",
  363. "source": "app:tomcat",
  364. "target": "app1"
  365. },
  366. {
  367. "attrs": {},
  368. "class": "connect",
  369. "id": "app:demoapp2-mysql:demodb",
  370. "source": "app:demoapp2",
  371. "target": "mysql:demodb"
  372. }
  373. ],
  374. "paths": null,
  375. "diff": null,
  376. "pathtags": null
  377. }
  378. }
  379. ],
  380. "meta": {
  381. "type": "graph"
  382. },
  383. "status": "ok"
  384. }
  385. }', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
  386. if err != nil {
  387. logger.Errorf("%v", err)
  388. }
  389. require.Nil(t.Test, err, fmt.Sprint(err))
  390. }
  391. func (t *MPartitionTests) Valid() {
  392. rtn, _, err := t.g.Query(`select * from /test/mpartition refresh`)
  393. if err != nil {
  394. logger.Errorf("%v", err)
  395. }
  396. if assert.Nil(t.Test, err) {
  397. if assert.NotNil(t.Test, rtn) {
  398. assert.Equal(t.Test, 3, len(rtn), "they should be equal")
  399. for _, row := range rtn {
  400. switch row["mv_varchar"].(string) {
  401. case "1":
  402. 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")
  403. }
  404. }
  405. }
  406. }
  407. }
  408. func (t *MPartitionTests) Int() {
  409. var err error
  410. var rtn []map[string]interface{}
  411. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int = 1`)
  412. if err != nil {
  413. logger.Errorf("%v", err)
  414. }
  415. if assert.Nil(t.Test, err) {
  416. if assert.NotNil(t.Test, rtn) {
  417. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int = %v", "1"))
  418. }
  419. }
  420. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int > 0`)
  421. if err != nil {
  422. logger.Errorf("%v", err)
  423. }
  424. if assert.Nil(t.Test, err) {
  425. if assert.NotNil(t.Test, rtn) {
  426. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int > %v", "0"))
  427. }
  428. }
  429. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int < 2`)
  430. if err != nil {
  431. logger.Errorf("%v", err)
  432. }
  433. if assert.Nil(t.Test, err) {
  434. if assert.NotNil(t.Test, rtn) {
  435. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int < %v", "2"))
  436. }
  437. }
  438. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int >= 1`)
  439. if err != nil {
  440. logger.Errorf("%v", err)
  441. }
  442. if assert.Nil(t.Test, err) {
  443. if assert.NotNil(t.Test, rtn) {
  444. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int >= %v", "1"))
  445. }
  446. }
  447. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int <= 1`)
  448. if err != nil {
  449. logger.Errorf("%v", err)
  450. }
  451. if assert.Nil(t.Test, err) {
  452. if assert.NotNil(t.Test, rtn) {
  453. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int <= %v", "1"))
  454. }
  455. }
  456. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int >= 1.1`)
  457. if err != nil {
  458. logger.Errorf("%v", err)
  459. }
  460. if assert.Nil(t.Test, err) {
  461. if assert.NotNil(t.Test, rtn) {
  462. assert.Equal(t.Test, int64(0), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int >= %v", "1.1"))
  463. }
  464. }
  465. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_int > 1`)
  466. if err != nil {
  467. logger.Errorf("%v", err)
  468. }
  469. if assert.Nil(t.Test, err) {
  470. if assert.NotNil(t.Test, rtn) {
  471. assert.Equal(t.Test, int64(0), rtn[0]["count"].(int64), fmt.Sprintf("not find v_int > %v", "1"))
  472. }
  473. }
  474. }
  475. func (t *MPartitionTests) Bool() {
  476. var err error
  477. var rtn []map[string]interface{}
  478. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_bool = true`)
  479. if err != nil {
  480. logger.Errorf("%v", err)
  481. }
  482. if assert.Nil(t.Test, err) {
  483. if assert.NotNil(t.Test, rtn) {
  484. assert.Equal(t.Test, int64(2), rtn[0]["count"].(int64), fmt.Sprintf("not find v_bool = %v", "true"))
  485. }
  486. }
  487. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_bool = false`)
  488. if err != nil {
  489. logger.Errorf("%v", err)
  490. }
  491. if assert.Nil(t.Test, err) {
  492. if assert.NotNil(t.Test, rtn) {
  493. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find v_bool = %v", "false"))
  494. }
  495. }
  496. }
  497. func (t *MPartitionTests) Float() {
  498. var err error
  499. var rtn []map[string]interface{}
  500. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_float >= 1.1`)
  501. if err != nil {
  502. logger.Errorf("%v", err)
  503. }
  504. if assert.Nil(t.Test, err) {
  505. if assert.NotNil(t.Test, rtn) {
  506. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float >= %v", "1.1"))
  507. }
  508. }
  509. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_float > 1`)
  510. if err != nil {
  511. logger.Errorf("%v", err)
  512. }
  513. if assert.Nil(t.Test, err) {
  514. if assert.NotNil(t.Test, rtn) {
  515. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float > %v", "1"))
  516. }
  517. }
  518. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_float = 1.1`)
  519. if err != nil {
  520. logger.Errorf("%v", err)
  521. }
  522. if assert.Nil(t.Test, err) {
  523. if assert.NotNil(t.Test, rtn) {
  524. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float = %v", "1.1"))
  525. }
  526. }
  527. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_float < 2`)
  528. if err != nil {
  529. logger.Errorf("%v", err)
  530. }
  531. if assert.Nil(t.Test, err) {
  532. if assert.NotNil(t.Test, rtn) {
  533. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float < %v", "2"))
  534. }
  535. }
  536. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_float <= 1.1`)
  537. if err != nil {
  538. logger.Errorf("%v", err)
  539. }
  540. if assert.Nil(t.Test, err) {
  541. if assert.NotNil(t.Test, rtn) {
  542. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_float <= %v", "1.1"))
  543. }
  544. }
  545. }
  546. func (t *MPartitionTests) Double() {
  547. var err error
  548. var rtn []map[string]interface{}
  549. rtn, _, err = t.g.Query(`select * from /test/mpartition where v_double >= 1.1234567890123456`)
  550. if err != nil {
  551. logger.Errorf("%v", err)
  552. }
  553. if assert.Nil(t.Test, err) {
  554. if assert.NotNil(t.Test, rtn) {
  555. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
  556. }
  557. }
  558. //??????
  559. rtn, _, err = t.g.Query(`select * from /test/mpartition where v_smalldouble >= 1.123456`)
  560. if err != nil {
  561. logger.Errorf("%v", err)
  562. }
  563. if assert.Nil(t.Test, err) {
  564. if assert.NotNil(t.Test, rtn) {
  565. assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
  566. }
  567. }
  568. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_double > 1`)
  569. if err != nil {
  570. logger.Errorf("%v", err)
  571. }
  572. if assert.Nil(t.Test, err) {
  573. if assert.NotNil(t.Test, rtn) {
  574. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double > %v", "1"))
  575. }
  576. }
  577. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_double = 1.1234567890123456`)
  578. if err != nil {
  579. logger.Errorf("%v", err)
  580. }
  581. if assert.Nil(t.Test, err) {
  582. if assert.NotNil(t.Test, rtn) {
  583. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
  584. }
  585. }
  586. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_double < 2`)
  587. if err != nil {
  588. logger.Errorf("%v", err)
  589. }
  590. if assert.Nil(t.Test, err) {
  591. if assert.NotNil(t.Test, rtn) {
  592. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double < %v", "2"))
  593. }
  594. }
  595. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_double <= 1.1234567890123456`)
  596. if err != nil {
  597. logger.Errorf("%v", err)
  598. }
  599. if assert.Nil(t.Test, err) {
  600. if assert.NotNil(t.Test, rtn) {
  601. assert.Equal(t.Test, int64(3), rtn[0]["count"].(int64), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
  602. }
  603. }
  604. }
  605. func (t *MPartitionTests) Prefix() {
  606. var err error
  607. var rtn []map[string]interface{}
  608. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='*hell*'`)
  609. if err != nil {
  610. logger.Errorf("%v", err)
  611. }
  612. if assert.Nil(t.Test, err) {
  613. if assert.NotNil(t.Test, rtn) {
  614. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "hello"))
  615. }
  616. }
  617. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='*20*'`)
  618. if err != nil {
  619. logger.Errorf("%v", err)
  620. }
  621. if assert.Nil(t.Test, err) {
  622. if assert.NotNil(t.Test, rtn) {
  623. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "2003"))
  624. }
  625. }
  626. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='*123-456*'`)
  627. if err != nil {
  628. logger.Errorf("%v", err)
  629. }
  630. if assert.Nil(t.Test, err) {
  631. if assert.NotNil(t.Test, rtn) {
  632. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "123-456-789"))
  633. }
  634. }
  635. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='*中*'`)
  636. if err != nil {
  637. logger.Errorf("%v", err)
  638. }
  639. if assert.Nil(t.Test, err) {
  640. if assert.NotNil(t.Test, rtn) {
  641. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "中国"))
  642. }
  643. }
  644. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='*magni*'`)
  645. if err != nil {
  646. logger.Errorf("%v", err)
  647. }
  648. if assert.Nil(t.Test, err) {
  649. if assert.NotNil(t.Test, rtn) {
  650. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "magnitude"))
  651. }
  652. }
  653. }
  654. func (t *MPartitionTests) Update() {
  655. var err error
  656. var rtn []map[string]interface{}
  657. stat, err := t.g.Prepare(`insert into /test/mpartition (mv_varchar, v_int, v_float, v_text, v_bool) values(?, ?, ?, ?, ?) on conflict update v_bool=v_bool, v_float=v_float+1`)
  658. assert.Nil(t.Test, err)
  659. _, _, err = stat.Exec("test001", 1, 1.1, "hello", true)
  660. assert.Nil(t.Test, err)
  661. time.Sleep(time.Duration(1) * time.Second)
  662. _, _, err = stat.Exec("test001", 1, 12, "hello", false)
  663. assert.Nil(t.Test, err)
  664. time.Sleep(time.Duration(1) * time.Second)
  665. rtn, _, err = t.g.Query(`select v_bool, v_float from /test/mpartition where mv_varchar='test001' and v_int=1 and v_text='hello' refresh`)
  666. if assert.Nil(t.Test, err) {
  667. if assert.NotNil(t.Test, rtn) {
  668. assert.Equal(t.Test, 1, len(rtn), "no return")
  669. assert.Equal(t.Test, float64(2.1), rtn[0]["v_float"].(float64), "v_float != 2.1")
  670. assert.Equal(t.Test, true, rtn[0]["v_bool"].(bool), "v_bool != true")
  671. }
  672. }
  673. rtn, _, err = t.g.Query(` update / set tags=tags+'hello' where mv_varchar= '1' and v_int=1`)
  674. if err != nil {
  675. logger.Errorf("%v", err)
  676. }
  677. if assert.Nil(t.Test, err) {
  678. if assert.NotNil(t.Test, rtn) {
  679. count := 0
  680. for _, row := range rtn {
  681. count = count + row["success"].(int)
  682. }
  683. assert.Equal(t.Test, 1, count, fmt.Sprintf("not find %v", "中国"))
  684. }
  685. }
  686. // /test/uuid
  687. // /test/sequence
  688. // /test/mpartition
  689. // /test/idpartition
  690. rtn, _, err = t.g.Query(` update /test/ set tags=tags+'world' where mv_varchar= '1' and v_int=1`)
  691. if err != nil {
  692. logger.Errorf("%v", err)
  693. }
  694. if assert.Nil(t.Test, err) {
  695. if assert.NotNil(t.Test, rtn) {
  696. assert.Equal(t.Test, int(1), rtn[0]["success"].(int), fmt.Sprintf("not find %v", "中国"))
  697. }
  698. }
  699. }
  700. func (t *MPartitionTests) FullSearch() {
  701. var err error
  702. var rtn []map[string]interface{}
  703. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='hello'`)
  704. if err != nil {
  705. logger.Errorf("%v", err)
  706. }
  707. if assert.Nil(t.Test, err) {
  708. if assert.NotNil(t.Test, rtn) {
  709. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "hello"))
  710. }
  711. }
  712. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='2003'`)
  713. if err != nil {
  714. logger.Errorf("%v", err)
  715. }
  716. if assert.Nil(t.Test, err) {
  717. if assert.NotNil(t.Test, rtn) {
  718. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "2003"))
  719. }
  720. }
  721. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='123-456-789'`)
  722. if err != nil {
  723. logger.Errorf("%v", err)
  724. }
  725. if assert.Nil(t.Test, err) {
  726. if assert.NotNil(t.Test, rtn) {
  727. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "123-456-789"))
  728. }
  729. }
  730. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='中国'`)
  731. if err != nil {
  732. logger.Errorf("%v", err)
  733. }
  734. if assert.Nil(t.Test, err) {
  735. if assert.NotNil(t.Test, rtn) {
  736. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "中国"))
  737. }
  738. }
  739. rtn, _, err = t.g.Query(`select count(*) as count from /test/mpartition where v_text='magnitude'`)
  740. if err != nil {
  741. logger.Errorf("%v", err)
  742. }
  743. if assert.Nil(t.Test, err) {
  744. if assert.NotNil(t.Test, rtn) {
  745. assert.Equal(t.Test, int64(1), rtn[0]["count"].(int64), fmt.Sprintf("not find %v", "magnitude"))
  746. }
  747. }
  748. }