inspectkv: address comments
This commit is contained in:
@ -64,14 +64,15 @@ func GetDDLInfo(txn kv.Transaction) (*DDLInfo, error) {
|
||||
}
|
||||
|
||||
// GetIndexData returns index handles and index values.
|
||||
func GetIndexData(table table.Table, txn kv.Transaction, idx *column.IndexedCol) ([]int64, []interface{}, error) {
|
||||
func GetIndexData(table table.Table, txn kv.Transaction, idx *column.IndexedCol) ([]int64, [][]interface{}, error) {
|
||||
var handles []int64
|
||||
var vals []interface{}
|
||||
var vals [][]interface{}
|
||||
kvIndex := kv.NewKVIndex(table.IndexPrefix(), idx.Name.L, idx.ID, idx.Unique)
|
||||
it, err := kvIndex.SeekFirst(txn)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Trace(err)
|
||||
}
|
||||
defer it.Close()
|
||||
|
||||
for {
|
||||
val, h, err := it.Next()
|
||||
@ -89,9 +90,9 @@ func GetIndexData(table table.Table, txn kv.Transaction, idx *column.IndexedCol)
|
||||
}
|
||||
|
||||
// GetTableData gets table row handles and column values.
|
||||
func GetTableData(table table.Table, retriever kv.Retriever) ([]int64, []interface{}, error) {
|
||||
func GetTableData(table table.Table, retriever kv.Retriever) ([]int64, [][]interface{}, error) {
|
||||
var handles []int64
|
||||
var data []interface{}
|
||||
var data [][]interface{}
|
||||
|
||||
err := table.IterRecords(retriever, table.FirstKey(), table.Cols(),
|
||||
func(h int64, d []interface{}, cols []*column.Col) (bool, error) {
|
||||
@ -107,7 +108,7 @@ func GetTableData(table table.Table, retriever kv.Retriever) ([]int64, []interfa
|
||||
}
|
||||
|
||||
// GetTableSnapshot gets the ver version of the table data.
|
||||
func GetTableSnapshot(store kv.Storage, ver kv.Version, table table.Table) ([]interface{}, error) {
|
||||
func GetTableSnapshot(store kv.Storage, ver kv.Version, table table.Table) ([][]interface{}, error) {
|
||||
snap, err := store.GetSnapshot(ver)
|
||||
if err != nil {
|
||||
return nil, errors.Trace(err)
|
||||
|
||||
@ -119,9 +119,7 @@ func (s *testInspectSuite) TestInspect(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
data, err := GetTableSnapshot(store, ver, tb)
|
||||
c.Assert(err, IsNil)
|
||||
for _, d := range data[0].([]interface{}) {
|
||||
c.Assert(d.(int64), Equals, int64(10))
|
||||
}
|
||||
c.Assert(data[0][0].(int64), Equals, int64(10))
|
||||
|
||||
_, err = tb.AddRecord(ctx, []interface{}{20}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
@ -129,26 +127,20 @@ func (s *testInspectSuite) TestInspect(c *C) {
|
||||
txn, err = store.Begin()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
handles, data, err := GetTableData(tb, txn)
|
||||
handles, vals, err := GetTableData(tb, txn)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(handles, HasLen, 2)
|
||||
c.Assert(data, HasLen, 2)
|
||||
for _, d := range data[1].([]interface{}) {
|
||||
c.Assert(d.(int64), Equals, int64(20))
|
||||
}
|
||||
c.Assert(vals, HasLen, 2)
|
||||
c.Assert(vals[1][0].(int64), Equals, int64(20))
|
||||
|
||||
handles, vals, err := GetIndexData(tb, txn, indices[0])
|
||||
handles, vals, err = GetIndexData(tb, txn, indices[0])
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(handles, HasLen, 2)
|
||||
c.Assert(handles[0], Equals, int64(1))
|
||||
c.Assert(handles[1], Equals, int64(2))
|
||||
c.Assert(vals, HasLen, 2)
|
||||
for _, d := range data[0].([]interface{}) {
|
||||
c.Assert(d.(int64), Equals, int64(10))
|
||||
}
|
||||
for _, d := range data[1].([]interface{}) {
|
||||
c.Assert(d.(int64), Equals, int64(20))
|
||||
}
|
||||
c.Assert(vals[0][0].(int64), Equals, int64(10))
|
||||
c.Assert(vals[1][0].(int64), Equals, int64(20))
|
||||
}
|
||||
|
||||
// mockContext represents mocked context.Context.
|
||||
|
||||
Reference in New Issue
Block a user