Scenario:
Put a row into TableStore, expect to get the primary keys back since CommentId (2nd PK) is auto incremental int64
Bug: failed to get non-nullable "PrimaryKeys" from PUTRow
Exception: put response: {"ConsumedCapacityUnit":{"Read":0,"Write":1},"PrimaryKey":{"PrimaryKeys":null},"RequestId":"0005a22b-94b8-67ca-8ac0-dc0b38e2f4bc"}
Justification:
according to the api at line 649, https://github.com/aliyun/aliyun-tablestore-go-sdk/blob/master/tablestore/api.go; PrimaryKeys should be returned.
according to doc, https://www.alibabacloud.com/help/doc-detail/27306.htm, The data type after the row is successfully written. Currently, only the primary key can be returned, which is used for the auto-increment function of the primary key column.
Coding Language: GOLANG
type Comment struct {
ProdId string // prodid as partition key
CommentId int64 //row key for each comment
Content string //comments text
}
CreatTable PK meta
meta := new(tablestore.TableMeta)
meta.TableName = "commentTest"
meta.AddPrimaryKeyColumn("ProdId", tablestore.PrimaryKeyType_STRING) // prodid as partition key
meta.AddPrimaryKeyColumnOption("CommentId", tablestore.PrimaryKeyType_INTEGER, tablestore.AUTO_INCREMENT) //row key for each comment
meta.AddDefinedColumn("Content", tablestore.DefinedColumn_STRING) //comments text
method
putRowChange := new(tablestore.PutRowChange)
putRowChange.TableName = "commentTest"
meta := new(tablestore.PrimaryKey)
meta.AddPrimaryKeyColumn("ProdId", c.ProdId)
if c.CommentId > 0 {
meta.AddPrimaryKeyColumn("CommentId", c.CommentId)
} else {
meta.AddPrimaryKeyColumnWithAutoIncrement("CommentId")
}
putRowChange.PrimaryKey = meta
putRowChange.SetCondition(tablestore.RowExistenceExpectation_IGNORE)
putRowChange.AddColumn("Content", c.Content)
request := new(tablestore.PutRowRequest)
request.PutRowChange =putRowChange
client := CreateClient()
resp, err := client.PutRow(request)
data, _ := json.Marshal(resp)
fmt.Println("put response: ", string(data))