basic.go 21 KB

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