Skip to content

Commit

Permalink
support update searchIndex schema
Browse files Browse the repository at this point in the history
  • Loading branch information
zikuang.lt committed Apr 21, 2022
1 parent 8267538 commit dcfa011
Show file tree
Hide file tree
Showing 25 changed files with 2,094 additions and 977 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/smartystreets/goconvey v1.6.4
github.com/stretchr/testify v1.7.0
go.uber.org/atomic v1.9.0
go.uber.org/zap v1.19.1
go.uber.org/zap v1.19.0
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)
35 changes: 8 additions & 27 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,41 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK
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/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723 h1:sHOAIxRGBp443oHZIPB+HsUGaksVCXVQENPxwTfQdH4=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.10 h1:z+mqJhf6ss6BSfSM671tgKyZBFPTTJM+HLxnhPC3wu0=
go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI=
go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/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/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
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-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5 h1:ouewzE6p+/VEB31YYnTbEJdi8pFqKp4P4n85vwo3DHA=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11 h1:Yq9t9jnGoR+dBuitxdo9l6Q7xh/zOyNnYUtDKaQ3x0E=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/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-20180628173108-788fd7840127/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/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/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
3 changes: 3 additions & 0 deletions sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func main() {
sample.ParallelScanSingleConcurrency(client, "scan_sample_table", "scan_sample_index")
sample.ParallelScanMultiConcurrency(client, "scan_sample_table", "scan_sample_index")

// update searchIndex schema
sample.UpdateSearchIndexSchema(client, "go_sdk_test_table", "go_sdk_test_index", "go_sdk_test_index_reindex")

// SQL sample
sample.SQLQuerySample(client)
}
203 changes: 203 additions & 0 deletions sample/SearchIndexOperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1481,4 +1481,207 @@ func ParallelScanMultiConcurrency(client *tablestore.TableStoreClient, tableName
}()
}
wg.Wait()
}

/**
* 动态修改schema
* 修改schema的索引必须以_reindex结尾
*/
func UpdateSearchIndexSchema(client *tablestore.TableStoreClient, tableName string, indexName string, indexReindexName string) {
{
// step 1.创建索引
fmt.Println("Begin to create table:", tableName)
createtableRequest := new(tablestore.CreateTableRequest)
tableMeta := new(tablestore.TableMeta)
tableMeta.TableName = tableName
tableMeta.AddPrimaryKeyColumn("pk1", tablestore.PrimaryKeyType_STRING)
tableOption := new(tablestore.TableOption)
tableOption.TimeToAlive = -1
tableOption.MaxVersion = 1
reservedThroughput := new(tablestore.ReservedThroughput)
reservedThroughput.Readcap = 0
reservedThroughput.Writecap = 0
createtableRequest.TableMeta = tableMeta
createtableRequest.TableOption = tableOption
createtableRequest.ReservedThroughput = reservedThroughput

_, err := client.CreateTable(createtableRequest)
if err != nil {
fmt.Println("Failed to create table with error:", err)
} else {
fmt.Println("Create table finished")
}

fmt.Println("Begin to create index:", indexName)
request := &tablestore.CreateSearchIndexRequest{}
request.TableName = tableName // 设置表名
request.IndexName = indexName // 设置索引名

schemas := []*tablestore.FieldSchema{}
field1 := &tablestore.FieldSchema{
FieldName: proto.String("Col_Keyword"), // 设置字段名,使用proto.String用于获取字符串指针
FieldType: tablestore.FieldType_KEYWORD, // 设置字段类型
Index: proto.Bool(true), // 设置开启索引
EnableSortAndAgg: proto.Bool(true), // 设置开启排序与统计功能
}
field2 := &tablestore.FieldSchema{
FieldName: proto.String("Col_Long"),
FieldType: tablestore.FieldType_LONG,
Index: proto.Bool(true),
EnableSortAndAgg: proto.Bool(true),
}
schemas = append(schemas, field1, field2)

request.IndexSchema = &tablestore.IndexSchema{
FieldSchemas: schemas, // 设置SearchIndex包含的字段
}
resp, err := client.CreateSearchIndex(request) // 调用client创建SearchIndex
if err != nil {
fmt.Println("error :", err)
return
}
fmt.Println("CreateSearchIndex finished, requestId:", resp.ResponseInfo.RequestId)
}
{
// step 2.创建修改schema后的索引,将field2删除
fmt.Println("Begin to create index:", indexReindexName)
request := &tablestore.CreateSearchIndexRequest{}
request.TableName = tableName // 设置表名
request.IndexName = indexReindexName // 设置索引名
request.SourceIndexName = &indexName // 设置源索引:被修改schema的索引

schemas := []*tablestore.FieldSchema{}
field1 := &tablestore.FieldSchema{
FieldName: proto.String("Col_Keyword"), // 设置字段名,使用proto.String用于获取字符串指针
FieldType: tablestore.FieldType_KEYWORD, // 设置字段类型
Index: proto.Bool(true), // 设置开启索引
EnableSortAndAgg: proto.Bool(true), // 设置开启排序与统计功能
}
schemas = append(schemas, field1)

request.IndexSchema = &tablestore.IndexSchema{
FieldSchemas: schemas, // 设置SearchIndex包含的字段
}
resp, err := client.CreateSearchIndex(request) // 调用client创建SearchIndex
if err != nil {
fmt.Println("error :", err)
return
}
fmt.Println("CreateSearchIndex finished, requestId:", resp.ResponseInfo.RequestId)
}
{
// step 3.设置AB索引权重,权重在0-100
// 做此步前需要等待"重建索引"数据同步。先后经历"全量同步"和"增量同步"两个阶段
fmt.Println("wait schema reload")
time.Sleep(60 * time.Second)
{
// 此处原索引权重为50 新索引权重为50
req := new(tablestore.UpdateSearchIndexRequest)
req.TableName = tableName
req.IndexName = indexName
var queryFlowWeightArray []*tablestore.QueryFlowWeight
queryFlowWeightArray = append(queryFlowWeightArray, &tablestore.QueryFlowWeight{
IndexName: indexName,
Weight: 50,
})
queryFlowWeightArray = append(queryFlowWeightArray, &tablestore.QueryFlowWeight{
IndexName: indexReindexName,
Weight: 50,
})
req.QueryFlowWeights = queryFlowWeightArray
respU, err := client.UpdateSearchIndex(req)
if err != nil {
fmt.Println("update searchIndex failed with error:", err)
}
fmt.Println("UpdateSearchIndex finished, requestId:", respU.ResponseInfo.RequestId)
// 检查权重设置是否成功
requestD := &tablestore.DescribeSearchIndexRequest{}
requestD.TableName = tableName
requestD.IndexName = indexName
respD, err := client.DescribeSearchIndex(requestD)
if err != nil {
fmt.Println("error: ", err)
return
}
if respD.QueryFlowWeights != nil {
fmt.Printf("QueryFlowWeight:\n")
for _, queryFlowWeight := range respD.QueryFlowWeights {
fmt.Printf("%s\n", queryFlowWeight)
}
}
}
{
// 此处原索引权重为0 新索引权重为100
req := new(tablestore.UpdateSearchIndexRequest)
req.TableName = tableName
req.IndexName = indexName
var queryFlowWeightArray []*tablestore.QueryFlowWeight
queryFlowWeightArray = append(queryFlowWeightArray, &tablestore.QueryFlowWeight{
IndexName: indexName,
Weight: 0,
})
queryFlowWeightArray = append(queryFlowWeightArray, &tablestore.QueryFlowWeight{
IndexName: indexReindexName,
Weight: 100,
})
req.QueryFlowWeights = queryFlowWeightArray
respU, err := client.UpdateSearchIndex(req)
if err != nil {
fmt.Println("update searchIndex failed with error:", err)
}
fmt.Println("UpdateSearchIndex finished, requestId:", respU.ResponseInfo.RequestId)
// 检查权重设置是否成功
requestD := &tablestore.DescribeSearchIndexRequest{}
requestD.TableName = tableName
requestD.IndexName = indexName
respD, err := client.DescribeSearchIndex(requestD)
if err != nil {
fmt.Println("error: ", err)
return
}
if respD.QueryFlowWeights != nil {
fmt.Printf("QueryFlowWeight:\n")
for _, queryFlowWeight := range respD.QueryFlowWeights {
fmt.Printf("%s\n", queryFlowWeight)
}
}
}
}

{
// step 4.切换索引, 此时索引schema变为新索引的schema
switchReq := new(tablestore.UpdateSearchIndexRequest)
switchReq.TableName = tableName
switchReq.IndexName = indexName
switchReq.SwitchIndexName = &indexReindexName
resp, err := client.UpdateSearchIndex(switchReq)
if err != nil {
fmt.Println("update search index failed with error:", err)
}
fmt.Println("UpdateSearchIndex finished, requestId:", resp.ResponseInfo.RequestId)
// 检查索引切换完后,schema变为新的schema
requestD := &tablestore.DescribeSearchIndexRequest{}
requestD.TableName = tableName
requestD.IndexName = indexName
respD, err := client.DescribeSearchIndex(requestD)
if err != nil {
fmt.Println("error: ", err)
return
}
fmt.Println("FieldSchemas:")
for _, schema := range respD.Schema.FieldSchemas {
fmt.Printf("%s\n", schema)
}

// 如果发现问题,还有机会切回
//switchReq := new(tablestore.UpdateSearchIndexRequest)
//switchReq.TableName = tableName
//switchReq.IndexName = indexName
//switchReq.SwitchIndexName = indexReindexName
//resp, err := client.UpdateSearchIndex(switchReq)
}
{
// step 5.经过一段静默时间后,可以删除修改前的索引
DeleteSearchIndex(client, tableName, indexReindexName)
}
}
46 changes: 43 additions & 3 deletions tablestore/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
computeSplitPointsBySizeRequestUri = "/ComputeSplitPointsBySize"
searchUri = "/Search"
createSearchIndexUri = "/CreateSearchIndex"
updateSearchIndexUri = "/UpdateSearchIndex"
listSearchIndexUri = "/ListSearchIndex"
deleteSearchIndexUri = "/DeleteSearchIndex"
describeSearchIndexUri = "/DescribeSearchIndex"
Expand Down Expand Up @@ -78,6 +79,9 @@ const (
deleteTimeseriesMeta = "/DeleteTimeseriesMeta"
)

// RowsSerializeType is used for tests only.
var RowsSerializeType = otsprotocol.RowsSerializeType_RST_FLAT_BUFFER

// Constructor: to create the client of TableStore service.
// 构造函数:创建表格存储服务的客户端。
//
Expand Down Expand Up @@ -542,8 +546,15 @@ func (timeseriesClient *TimeseriesClient) PutTimeseriesData(request *PutTimeseri

req.RowsData = new(otsprotocol.TimeseriesRows)
req.RowsData.Type = new(otsprotocol.RowsSerializeType)
req.RowsData.Type = otsprotocol.RowsSerializeType_RST_FLAT_BUFFER.Enum()
req.RowsData.RowsData, err = BuildFlatbufferRows(request.rows, request.timeseriesTableName, timeseriesClient.timeseriesMetaCache)
req.RowsData.Type = RowsSerializeType.Enum()
switch RowsSerializeType {
case otsprotocol.RowsSerializeType_RST_FLAT_BUFFER:
req.RowsData.RowsData, err = BuildFlatbufferRows(request.rows, request.timeseriesTableName, timeseriesClient.timeseriesMetaCache)
case otsprotocol.RowsSerializeType_RST_PROTO_BUFFER:
req.RowsData.RowsData, err = buildProtocolBufferRows(request.rows, request.timeseriesTableName, timeseriesClient.timeseriesMetaCache)
default:
err = fmt.Errorf("Invalid rows serialize type")
}
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1608,7 +1619,7 @@ func (client *TableStoreClient) SQLQuery(req *SQLQueryRequest) (*SQLQueryRespons

// do request
pbResp := otsprotocol.SQLQueryResponse{}
response := &SQLQueryResponse{ConsumedCapacityUnit: &ConsumedCapacityUnit{}}
response := &SQLQueryResponse{SQLQueryConsumed: &SQLQueryConsumed{}}
if err := client.doRequestWithRetry(sqlQueryUri, pbReq, &pbResp, &response.ResponseInfo); err != nil {
return nil, err
}
Expand All @@ -1630,6 +1641,35 @@ func (client *TableStoreClient) SQLQuery(req *SQLQueryRequest) (*SQLQueryRespons
response.PayloadVersion = SQLPAYLOAD_FLAT_BUFFERS
}

tableConsumes := make([]*TableConsumedCU, 0, len(pbResp.Consumes))
for _, consume := range pbResp.Consumes {
tableConsume := new(TableConsumedCU)
tableConsume.TableName = consume.GetTableName()
if consume.Consumed != nil && consume.Consumed.CapacityUnit != nil {
tableConsume.ConsumedCapacityUnit = new(ConsumedCapacityUnit)
tableConsume.ConsumedCapacityUnit.Read = consume.Consumed.CapacityUnit.GetRead()
tableConsume.ConsumedCapacityUnit.Write = consume.Consumed.CapacityUnit.GetWrite()
}

tableConsumes = append(tableConsumes, tableConsume)
}
response.SQLQueryConsumed.TableConsumes = tableConsumes

searchConsumes := make([]*SearchConsumedCU, 0, len(pbResp.SearchConsumes))
for _, consume := range pbResp.SearchConsumes {
searchConsume := new(SearchConsumedCU)
searchConsume.TableName = consume.GetTableName()
searchConsume.IndexName = consume.GetIndexName()
if consume.Consumed != nil && consume.Consumed.CapacityUnit != nil {
searchConsume.ConsumedCapacityUnit = new(ConsumedCapacityUnit)
searchConsume.ConsumedCapacityUnit.Read = consume.Consumed.CapacityUnit.GetRead()
searchConsume.ConsumedCapacityUnit.Write = consume.Consumed.CapacityUnit.GetWrite()
}

searchConsumes = append(searchConsumes, searchConsume)
}
response.SQLQueryConsumed.SearchConsumes = searchConsumes

return response, nil
}

Expand Down
Loading

0 comments on commit dcfa011

Please sign in to comment.