concatkey.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package ckeys
  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 ConcatKeyTests struct {
  13. Test *testing.T
  14. g *Gutil
  15. }
  16. func ConcatKeyTest(t *testing.T) {
  17. g := test.TestG()
  18. t.Run("InitG", func(t *testing.T) {
  19. test := &ConcatKeyTests{Test: t, g: g}
  20. test.InitG()
  21. })
  22. t.Run("Class", func(t *testing.T) {
  23. test := &ConcatKeyTests{Test: t, g: g}
  24. test.Class()
  25. })
  26. t.Run("Data", func(t *testing.T) {
  27. test := &ConcatKeyTests{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 := &ConcatKeyTests{Test: t, g: g}
  33. test.Valid()
  34. })
  35. }
  36. func (t *ConcatKeyTests) InitG() {
  37. require.NotNil(t.Test, t.g)
  38. }
  39. func (t *ConcatKeyTests) Class() {
  40. _, _, err := t.g.Query(`
  41. create class if not exists /test/concat (
  42. v_varchar varchar,
  43. v_text text,
  44. v_int int,
  45. v_bigint bigint,
  46. v_smalldouble double,
  47. v_double double,
  48. v_float float,
  49. v_bool bool,
  50. indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
  51. keys(v_varchar , v_text)
  52. ) with ckeys=v_bool`)
  53. if err != nil {
  54. logger.Errorf("%v", err)
  55. }
  56. require.Nil(t.Test, err, fmt.Sprint(err))
  57. }
  58. func (t *ConcatKeyTests) Data() {
  59. var err error
  60. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('4006', 'hello word 2003', 4006, 4006, 1.1, 1.1234567890123456, 1.123456, true )`)
  61. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('40', 'hello word 2003', 40, 40, 1.1, 1.1234567890123456, 1.123456, false )`)
  62. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('400', 'hello word 2003', 400, 400, 1.1, 1.1234567890123456, 1.123456, true )`)
  63. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('74006', 'hello word 2003', -4006, 4006, 1.1, 1.1234567890123456, 1.123456, false )`)
  64. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('409', 'hello word 2003', -40, 40, 1.1, 1.1234567890123456, 1.123456, true )`)
  65. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('500', 'hello word 2003', -400, 400, 1.1, 1.1234567890123456, 1.123456, false )`)
  66. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('600', 'hello word 2003', 370, 370, 1.1, 1.1234567890123456, 1.123456, true )`)
  67. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('700', 'hello word 2003', 580, 580, 1.1, 1.1234567890123456, 1.123456, true )`)
  68. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('602', 'hello word 2003', -370, -370, 1.1, 1.1234567890123456, 1.123456, true )`)
  69. _, _, err = t.g.Query(`insert into /test/concat (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('708', 'hello word 2003', -580, -580, 1.1, 1.1234567890123456, 1.123456, true )`)
  70. if err != nil {
  71. logger.Errorf("%v", err)
  72. }
  73. require.Nil(t.Test, err, fmt.Sprint(err))
  74. }
  75. func (t *ConcatKeyTests) Valid() {
  76. rtn, _, err := t.g.Query(`select * from /test/concat`)
  77. if err != nil {
  78. logger.Errorf("%v", err)
  79. }
  80. if assert.Nil(t.Test, err) {
  81. if assert.NotNil(t.Test, rtn) {
  82. assert.Equal(t.Test, 10, len(rtn), "they should be equal")
  83. }
  84. }
  85. }