Skip to content

Commit

Permalink
rename and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx committed Jan 14, 2019
1 parent c655de1 commit 7db14b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion executor/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ func (e *WindowExec) copyChk(chk *chunk.Chunk) {
e.remainingRowsInChunk = childResult.NumRows()
columns := e.Schema().Columns[:len(e.Schema().Columns)-1]
for i, col := range columns {
chk.CopyColumns(childResult, i, col.Index)
chk.MakeRefTo(i, childResult, col.Index)
}
}
10 changes: 5 additions & 5 deletions util/chunk/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (c *Chunk) MakeRef(srcColIdx, dstColIdx int) {
c.columns[dstColIdx] = c.columns[srcColIdx]
}

// MakeRefTo copies columns `src.columns[srcColIdx]` to `c.columns[dstColIdx]`.
func (c *Chunk) MakeRefTo(dstColIdx int, src *Chunk, srcColIdx int) {
c.columns[dstColIdx] = src.columns[srcColIdx]
}

// SwapColumn swaps column "c.columns[colIdx]" with column
// "other.columns[otherIdx]". If there exists columns refer to the column to be
// swapped, we need to re-build the reference.
Expand Down Expand Up @@ -187,11 +192,6 @@ func (c *Chunk) SwapColumns(other *Chunk) {
c.numVirtualRows, other.numVirtualRows = other.numVirtualRows, c.numVirtualRows
}

// CopyColumns copies columns `other.columns[from]` to `c.columns[dst]`.
func (c *Chunk) CopyColumns(other *Chunk, dst, from int) {
c.columns[dst] = other.columns[from]
}

// SetNumVirtualRows sets the virtual row number for a Chunk.
// It should only be used when there exists no column in the Chunk.
func (c *Chunk) SetNumVirtualRows(numVirtualRows int) {
Expand Down
17 changes: 17 additions & 0 deletions util/chunk/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,23 @@ func (s *testChunkSuite) TestPreAlloc4RowAndInsert(c *check.C) {
}
}

func (s *testChunkSuite) TestMakeRefTo(c *check.C) {
fieldTypes := make([]*types.FieldType, 0, 2)
fieldTypes = append(fieldTypes, &types.FieldType{Tp: mysql.TypeFloat})
fieldTypes = append(fieldTypes, &types.FieldType{Tp: mysql.TypeFloat})

chk1 := NewChunkWithCapacity(fieldTypes, 1)
chk1.AppendFloat64(0, 1)
chk1.AppendFloat64(1, 3)

chk2 := NewChunkWithCapacity(fieldTypes, 1)
chk2.MakeRefTo(0, chk1, 1)
chk2.MakeRefTo(1, chk1, 0)

c.Assert(chk2.columns[0] == chk1.columns[1], check.IsTrue)
c.Assert(chk2.columns[1] == chk1.columns[0], check.IsTrue)
}

func BenchmarkAppendInt(b *testing.B) {
b.ReportAllocs()
chk := newChunk(8)
Expand Down

0 comments on commit 7db14b1

Please sign in to comment.