diff --git a/go.mod b/go.mod index deb087c..7ac0d9b 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,15 @@ -module github.com/aliyun/aliyun-tablestore-go-sdk +module github.com/aliyun/aliyun-tablestore-go-sdk/v5 go 1.13 require ( - github.com/BurntSushi/toml v0.3.1 // indirect github.com/cenkalti/backoff v2.2.1+incompatible github.com/golang/mock v1.3.1 github.com/golang/protobuf v1.3.2 - github.com/kr/pretty v0.1.0 // indirect github.com/satori/go.uuid v1.2.0 github.com/smartystreets/goconvey v1.6.4 github.com/stretchr/testify v1.4.0 - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 + go.uber.org/zap v1.13.0 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 gopkg.in/natefinch/lumberjack.v2 v2.0.0 ) diff --git a/go.sum b/go.sum index ef28cbc..f11816a 100644 --- a/go.sum +++ b/go.sum @@ -2,23 +2,29 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= @@ -26,19 +32,44 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +go.uber.org/atomic v1.5.0 h1:OI5t8sDa1Or+q8AeE+yKeB/SDYioSHAgcVljj9JIETY= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.3.0 h1:sFPn2GLc3poCkfrpIXGhBD2X0CMIo4Q/zSULXrj/+uc= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.13.0 h1:nR6NoDBgAf67s68NhaXbsojM+2gxp3S1hWkHDl27pVU= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5 h1:hKsoRgsbwY1NafxrwTs+k64bikrLBkAgPir1TNCj3Zs= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= diff --git a/sample.go b/sample.go index 87ace13..7dffa60 100644 --- a/sample.go +++ b/sample.go @@ -3,8 +3,8 @@ package main import ( "os" - "github.com/aliyun/aliyun-tablestore-go-sdk/sample" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/sample" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" ) func main() { diff --git a/sample/GlobalTableOperation.go b/sample/GlobalTableOperation.go index 09b0e51..7a4bae3 100644 --- a/sample/GlobalTableOperation.go +++ b/sample/GlobalTableOperation.go @@ -1,7 +1,7 @@ package sample import ( - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" "fmt" ) diff --git a/sample/LocalIndexTableOperation.go b/sample/LocalIndexTableOperation.go index b0348f8..c608070 100644 --- a/sample/LocalIndexTableOperation.go +++ b/sample/LocalIndexTableOperation.go @@ -4,7 +4,7 @@ import ( "fmt" "strconv" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" ) func CreateTableWithLocalIndexSample(client *tablestore.TableStoreClient, tableName string) { diff --git a/sample/LocalTransactionOperation.go b/sample/LocalTransactionOperation.go index 8ad177c..1e665f5 100644 --- a/sample/LocalTransactionOperation.go +++ b/sample/LocalTransactionOperation.go @@ -1,7 +1,7 @@ package sample import ( - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" "fmt" "time" ) diff --git a/sample/MultipleRowOperation.go b/sample/MultipleRowOperation.go index 8dcc6fc..d2dfec5 100644 --- a/sample/MultipleRowOperation.go +++ b/sample/MultipleRowOperation.go @@ -2,7 +2,7 @@ package sample import ( "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" "math/rand" "time" ) diff --git a/sample/SearchIndexOperation.go b/sample/SearchIndexOperation.go index 0ff099c..ad70f7c 100644 --- a/sample/SearchIndexOperation.go +++ b/sample/SearchIndexOperation.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/search" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore/search" "github.com/golang/protobuf/proto" "time" ) diff --git a/sample/SingleRowOperation.go b/sample/SingleRowOperation.go index d21d494..b4242f8 100644 --- a/sample/SingleRowOperation.go +++ b/sample/SingleRowOperation.go @@ -2,7 +2,7 @@ package sample import ( "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" ) func PutRowSample(client *tablestore.TableStoreClient, tableName string) { diff --git a/sample/StreamOperation.go b/sample/StreamOperation.go index 60e3979..9374941 100644 --- a/sample/StreamOperation.go +++ b/sample/StreamOperation.go @@ -2,10 +2,10 @@ package sample import ( "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" + "github.com/golang/protobuf/proto" "strconv" "time" - "github.com/golang/protobuf/proto" ) func GetStreamRecordWithTimestampSample(client *tablestore.TableStoreClient, tableName string) { diff --git a/sample/TableOperation.go b/sample/TableOperation.go index 929abff..18cd7cf 100644 --- a/sample/TableOperation.go +++ b/sample/TableOperation.go @@ -2,7 +2,7 @@ package sample import ( "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore" ) func CreateTableSample(client *tablestore.TableStoreClient, tableName string) { diff --git a/tablestore/api.go b/tablestore/api.go index 76452a1..d6e7292 100644 --- a/tablestore/api.go +++ b/tablestore/api.go @@ -5,7 +5,7 @@ import ( "crypto/md5" "encoding/base64" "fmt" - "github.com/aliyun/aliyun-tablestore-go-sdk/tablestore/otsprotocol" + "github.com/aliyun/aliyun-tablestore-go-sdk/v5/tablestore/otsprotocol" "github.com/golang/protobuf/proto" "io" "math/rand" @@ -1001,6 +1001,12 @@ func (tableStoreClient *TableStoreClient) GetRange(request *GetRangeRequest) (*G req.EndColumn = request.RangeRowQueryCriteria.EndColumn } + req.DataBlockTypeHint = toPBDataBlockType(request.RangeRowQueryCriteria.DataBlockType) + req.CompressTypeHint = toPBCompressType(request.RangeRowQueryCriteria.CompressType) + if request.RangeRowQueryCriteria.ReturnSpecifiedPkOnly { + req.ReturnEntirePrimaryKeys = proto.Bool(false) + } + req.InclusiveStartPrimaryKey = request.RangeRowQueryCriteria.StartPrimaryKey.Build(false) req.ExclusiveEndPrimaryKey = request.RangeRowQueryCriteria.EndPrimaryKey.Build(false) @@ -1012,6 +1018,11 @@ func (tableStoreClient *TableStoreClient) GetRange(request *GetRangeRequest) (*G response.ConsumedCapacityUnit.Read = *resp.Consumed.CapacityUnit.Read response.ConsumedCapacityUnit.Write = *resp.Consumed.CapacityUnit.Write + compressType, err := parseProtocolCompressType(resp.GetCompressType()) + if err != nil { + return nil, err + } + response.CompressType = compressType if len(resp.NextStartPrimaryKey) != 0 { currentRows, err := readRowsWithHeader(bytes.NewReader(resp.NextStartPrimaryKey)) if err != nil { @@ -1029,13 +1040,58 @@ func (tableStoreClient *TableStoreClient) GetRange(request *GetRangeRequest) (*G return response, nil } - rows, err := readRowsWithHeader(bytes.NewReader(resp.Rows)) + switch resp.GetDataBlockType() { + case otsprotocol.DataBlockType_DBT_PLAIN_BUFFER: + rows, err := parsePlainBufferRows(resp.Rows) + if err != nil { + return nil, err + } + response.Rows = rows + response.DataBlockType = PlainBuffer + case otsprotocol.DataBlockType_DBT_SIMPLE_ROW_MATRIX: + rows, err := parseMatrixRows(resp.Rows) + if err != nil { + return nil, err + } + response.Rows = rows + response.DataBlockType = SimpleRowMatrix + default: + return nil, fmt.Errorf("unknow data block type %d", resp.GetDataBlockType()) + } + return response, nil +} + +func toPBCompressType(compressType CompressType) *otsprotocol.CompressType { + switch compressType { + case None: + return otsprotocol.CompressType_CPT_NONE.Enum() + default: + // return CompressType_CPT_NONE + return otsprotocol.CompressType_CPT_NONE.Enum() + } +} + +func toPBDataBlockType(blockType DataBlockType) *otsprotocol.DataBlockType { + switch blockType { + case PlainBuffer: + return otsprotocol.DataBlockType_DBT_PLAIN_BUFFER.Enum() + case SimpleRowMatrix: + return otsprotocol.DataBlockType_DBT_SIMPLE_ROW_MATRIX.Enum() + default: + // return DataBlockType_DBT_PLAIN_BUFFER + return otsprotocol.DataBlockType_DBT_PLAIN_BUFFER.Enum() + } +} + +func parsePlainBufferRows(rowBytes []byte) ([]*Row, error) { + pbRows, err := readRowsWithHeader(bytes.NewReader(rowBytes)) if err != nil { - return response, err + return nil, err } - for _, row := range rows { - currentRow := &Row{} + rows := make([]*Row, len(pbRows)) + for i, row := range pbRows { + currentRow := new(Row) currentpk := new(PrimaryKey) for _, pk := range row.primaryKey { pkColumn := &PrimaryKeyColumn{ColumnName: string(pk.cellName), Value: pk.cellValue.Value} @@ -1049,11 +1105,9 @@ func (tableStoreClient *TableStoreClient) GetRange(request *GetRangeRequest) (*G currentRow.Columns = append(currentRow.Columns, dataColumn) } - response.Rows = append(response.Rows, currentRow) + rows[i] = currentRow } - - return response, nil - + return rows, nil } func (client *TableStoreClient) ListStream(req *ListStreamRequest) (*ListStreamResponse, error) { diff --git a/tablestore/api_test.go b/tablestore/api_test.go index 113a672..4dfde9d 100644 --- a/tablestore/api_test.go +++ b/tablestore/api_test.go @@ -1,20 +1,25 @@ package tablestore import ( + "encoding/base64" "fmt" . "gopkg.in/check.v1" + "io" "math/rand" "net/http" "os" "runtime" "strconv" "strings" + "syscall" "testing" "time" - "io" - "syscall" ) +func init() { + rand.Seed(time.Now().UnixNano()) +} + // Hook up gocheck into the "go test" runner. func Test(t *testing.T) { TestingT(t) @@ -26,8 +31,16 @@ var tableNamePrefix string var _ = Suite(&TableStoreSuite{}) -var defaultTableName = "defaulttable" -var rangeQueryTableName = "rangetable" +var ( + defaultTableName = "defaulttable" + rangeQueryTableName = "rangetable" + fuzzyTableName = "fuzzytable" + + fuzzyMetaPk1 = "pkStr" + fuzzyMetaPk2 = "pkBlob" + fuzzyMetaPk3 = "pkInt" + fuzzyMetaAttr = []string{"string", "integer", "boolean", "double", "blob"} +) // Todo: use config var client TableStoreApi @@ -46,9 +59,33 @@ func (s *TableStoreSuite) SetUpSuite(c *C) { rangeQueryTableName = tableNamePrefix + rangeQueryTableName PrepareTable(defaultTableName) PrepareTable2(rangeQueryTableName) + err := PrepareFuzzyTable(fuzzyTableName) + c.Assert(err, IsNil) invalidClient = NewClient(endpoint, instanceName, accessKeyId, "invalidsecret") } +func PrepareFuzzyTable(tableName string) error { + client.DeleteTable(&DeleteTableRequest{TableName: tableName}) + time.Sleep(time.Second) + meta := &TableMeta{ + TableName: tableName, + } + meta.AddPrimaryKeyColumn(fuzzyMetaPk1, PrimaryKeyType_STRING) + meta.AddPrimaryKeyColumn(fuzzyMetaPk2, PrimaryKeyType_BINARY) + meta.AddPrimaryKeyColumn(fuzzyMetaPk3, PrimaryKeyType_INTEGER) + req := &CreateTableRequest{ + TableMeta: meta, + TableOption: &TableOption{ + TimeToAlive: -1, + MaxVersion: 1, + }, + ReservedThroughput: &ReservedThroughput{0,0}, + } + _, err := client.CreateTable(req) + time.Sleep(time.Second) + return err +} + func PrepareTable(tableName string) error { createtableRequest := new(CreateTableRequest) tableMeta := new(TableMeta) @@ -937,6 +974,116 @@ func (s *TableStoreSuite) TestBatchWriteRow(c *C) { fmt.Println("TestBatchWriteRow finished") } +func (s *TableStoreSuite) TestFuzzyGetRangeMatrix(c *C) { + fmt.Println("FuzzyGetRangeMatrix") + expect, err := PrepareFuzzyTableData(fuzzyTableName, 1024, 10240, 10000) + c.Assert(err, IsNil) + startPk := new(PrimaryKey) + startPk.AddPrimaryKeyColumnWithMinValue(fuzzyMetaPk1) + startPk.AddPrimaryKeyColumnWithMinValue(fuzzyMetaPk2) + startPk.AddPrimaryKeyColumnWithMinValue(fuzzyMetaPk3) + endPk := new(PrimaryKey) + endPk.AddPrimaryKeyColumnWithMaxValue(fuzzyMetaPk1) + endPk.AddPrimaryKeyColumnWithMaxValue(fuzzyMetaPk2) + endPk.AddPrimaryKeyColumnWithMaxValue(fuzzyMetaPk3) + criteria := &RangeRowQueryCriteria{ + TableName: fuzzyTableName, + StartPrimaryKey: startPk, + EndPrimaryKey: endPk, + ColumnsToGet: fuzzyMetaAttr, + MaxVersion: 1, + Limit: 2000, + DataBlockType: SimpleRowMatrix, + } + for { + resp, err := client.GetRange(&GetRangeRequest{criteria}) + c.Assert(err, IsNil) + c.Assert(resp.DataBlockType, Equals, SimpleRowMatrix) + for _, row := range resp.Rows { + pks := row.PrimaryKey.PrimaryKeys + cpKey := pks[0].Value.(string)+ "-" + base64.StdEncoding.EncodeToString(pks[1].Value.([]byte)) + + "-" +fmt.Sprintf("%d", pks[2].Value.(int64)) + attrs, ok := expect[cpKey] + if !ok { + c.Errorf("got %s", cpKey) + } + for _, column := range row.Columns { + //fmt.Printf("%s %v\n", column.ColumnName, column.Value) + switch column.ColumnName { + case "string": + c.Assert(column.Value, DeepEquals, attrs[column.ColumnName]) + case "blob": + c.Assert(column.Value.([]byte), DeepEquals, attrs[column.ColumnName].([]byte)) + case "boolean": + c.Assert(column.Value, DeepEquals, attrs[column.ColumnName]) + case "integer": + c.Assert(column.Value, DeepEquals, attrs[column.ColumnName]) + case "double": + c.Assert(column.Value, DeepEquals, attrs[column.ColumnName]) + } + } + c.Assert(len(row.Columns), Equals, len(attrs)) + delete(expect, cpKey) + } + if resp.NextStartPrimaryKey != nil { + criteria.StartPrimaryKey = resp.NextStartPrimaryKey + } else { + break + } + } + c.Assert(len(expect), Equals, 0) +} + +func PrepareFuzzyTableData(tableName string, maxStringLen, maxBlobLen int, rowCount int) (map[string]map[string]interface{}, error) { + retMap := make(map[string]map[string]interface{}) + for i:=0;i