seqkey.go 20 KB

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