-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
executor/join : use shallow copy for join. #7433
Changes from 7 commits
a576cc0
79b74e7
d9fe98b
8fa2ad8
33ae5a0
255c64b
0973373
055a41a
c5eeff9
e7c6c64
ce8eb4f
499b6f9
2a295a1
9d82447
ef85948
45b4631
5bf279f
9690506
8db639f
7a55ff5
05c1273
66a133c
dadb047
b4192e4
4096997
b802941
c5cfdf1
947f9d4
24ab90e
2b8d896
3f82d2b
604e49d
e5f4cbe
abbc2c9
e1dd31d
593b31c
3a6fbb7
600fdc3
f4fbd70
23eaf1e
e9ef7dd
21b5417
0aadbf6
0de2063
c681658
f8ccdf2
c7b2301
1e8a9f0
b939b3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,6 +160,77 @@ func (c *Chunk) AppendPartialRow(colIdx int, row Row) { | |
} | ||
} | ||
|
||
func (c *Chunk) AppendPartialRows(colIdx int, rowIt Iterator, maxLen int) int { | ||
oldRowLen := c.columns[colIdx+0].length | ||
columns := rowIt.Current().c.columns | ||
for i, rowCol := range columns { | ||
chkCol := c.columns[colIdx+i] | ||
rower := rowIt | ||
if i != 0 { | ||
rower.PreRows(c.columns[colIdx+0].length - oldRowLen) | ||
} | ||
|
||
if rowCol.isFixed() { | ||
elemLen := len(rowCol.elemBuf) | ||
for row, j := rower.Current(), 0; j < maxLen && row != rower.End(); row, j = rower.Next(), j+1 { | ||
chkCol.appendNullBitmap(!rowCol.isNull(row.idx)) | ||
offset := row.idx * elemLen | ||
chkCol.data = append(chkCol.data, rowCol.data[offset:offset+elemLen]...) | ||
chkCol.length++ | ||
} | ||
} else { | ||
for row, j := rower.Current(), 0; j < maxLen && row != rower.End(); row, j = rower.Next(), j+1 { | ||
chkCol.appendNullBitmap(!rowCol.isNull(row.idx)) | ||
start, end := rowCol.offsets[row.idx], rowCol.offsets[row.idx+1] | ||
chkCol.data = append(chkCol.data, rowCol.data[start:end]...) | ||
chkCol.offsets = append(chkCol.offsets, int32(len(chkCol.data))) | ||
chkCol.length++ | ||
} | ||
} | ||
} | ||
return c.columns[colIdx+0].length - oldRowLen | ||
} | ||
|
||
func (c *Chunk) AppendPartialSameRows(colIdx int, row Row, rowsLen int) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same reason. |
||
for i, rowCol := range row.c.columns { | ||
chkCol := c.columns[colIdx+i] | ||
for j := 0; j < rowsLen; j++ { | ||
chkCol.appendNullBitmap(!rowCol.isNull(row.idx)) | ||
chkCol.length++ | ||
} | ||
if rowCol.isFixed() { | ||
elemLen := len(rowCol.elemBuf) | ||
start := row.idx * elemLen | ||
end := start + elemLen | ||
for j := 0; j < rowsLen; j++ { | ||
chkCol.data = append(chkCol.data, rowCol.data[start:start+end]...) | ||
} | ||
} else { | ||
start, end := rowCol.offsets[row.idx], rowCol.offsets[row.idx+1] | ||
for j := 0; j < rowsLen; j++ { | ||
chkCol.data = append(chkCol.data, rowCol.data[start:end]...) | ||
chkCol.offsets = append(chkCol.offsets, int32(len(chkCol.data))) | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
func (c *Chunk) AppendRightMultiRows(lhser Iterator, rhs Row, maxLen int) int { | ||
c.numVirtualRows += maxLen | ||
lhsLen := lhser.Current().Len() | ||
rowsLen := c.AppendPartialRows(0, lhser, maxLen) | ||
c.AppendPartialSameRows(lhsLen, rhs, rowsLen) | ||
return rowsLen | ||
} | ||
|
||
func (c *Chunk) AppendMultiRows(lhs Row, rhser Iterator, maxLen int) int { | ||
c.numVirtualRows += maxLen | ||
rowsLen := c.AppendPartialRows(lhs.Len(), rhser, maxLen) | ||
c.AppendPartialSameRows(0, lhs, rowsLen) | ||
return rowsLen | ||
} | ||
|
||
// Append appends rows in [begin, end) in another Chunk to a Chunk. | ||
func (c *Chunk) Append(other *Chunk, begin, end int) { | ||
for colID, src := range other.columns { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package chunk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
import ( | ||
"testing" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this line to line5 |
||
) | ||
|
||
var ( | ||
numRows = 1024 | ||
) | ||
|
||
func newChunkWithInitCap(cap int, elemLen ...int) *Chunk { | ||
chk := &Chunk{} | ||
for _, l := range elemLen { | ||
if l > 0 { | ||
chk.addFixedLenColumn(l, cap) | ||
} else { | ||
chk.addVarLenColumn(cap) | ||
} | ||
} | ||
return chk | ||
} | ||
|
||
func getChunk() *Chunk { | ||
chk := newChunkWithInitCap(numRows, 8, 8, 0, 0) | ||
for i := 0; i < numRows; i++ { | ||
//chk.AppendNull(0) | ||
chk.AppendInt64(0, int64(i)) | ||
chk.AppendInt64(1, 1) | ||
chk.AppendString(2, "abcd") | ||
chk.AppendBytes(3, []byte("01234567890zxcvbnmqwer")) | ||
} | ||
return chk | ||
} | ||
|
||
func prepareChks() (it1 Iterator, row Row, dst *Chunk) { | ||
chk1 := getChunk() | ||
row = chk1.GetRow(0) | ||
it1 = NewIterator4Chunk(chk1) | ||
it1.Begin() | ||
dst = newChunkWithInitCap(numRows, 8, 8, 0, 0, 8, 8, 0, 0) | ||
return it1, row, dst | ||
} | ||
|
||
func checkDstChk(t *testing.T, dst *Chunk) { | ||
for i := 0; i < 8; i++ { | ||
if dst.columns[i].length != numRows { | ||
t.Fail() | ||
} | ||
} | ||
for j := 0; j < numRows; j++ { | ||
row := dst.GetRow(j) | ||
if row.GetInt64(0) != int64(j) { | ||
t.Fail() | ||
} | ||
if row.GetInt64(1) != 1 { | ||
t.Fail() | ||
} | ||
if row.GetString(2) != "abcd" { | ||
t.Fail() | ||
} | ||
if string(row.GetBytes(3)) != "01234567890zxcvbnmqwer" { | ||
t.Fail() | ||
} | ||
|
||
if row.GetInt64(4) != 0 { | ||
t.Fail() | ||
} | ||
if row.GetInt64(5) != 1 { | ||
t.Fail() | ||
} | ||
if row.GetString(6) != "abcd" { | ||
t.Fail() | ||
} | ||
if string(row.GetBytes(7)) != "01234567890zxcvbnmqwer" { | ||
t.Fail() | ||
} | ||
} | ||
} | ||
|
||
func TestCopyFieldByField(t *testing.T) { | ||
it1, row, dst := prepareChks() | ||
|
||
dst.Reset() | ||
for lhs := it1.Begin(); lhs != it1.End(); lhs = it1.Next() { | ||
dst.AppendRow(lhs) | ||
dst.AppendPartialRow(lhs.Len(), row) | ||
} | ||
checkDstChk(t, dst) | ||
} | ||
|
||
func TestCopyColumnByColumn(t *testing.T) { | ||
it1, row, dst := prepareChks() | ||
|
||
dst.Reset() | ||
for it1.Begin(); it1.Current() != it1.End(); { | ||
dst.AppendRightMultiRows(it1, row, 128) | ||
} | ||
checkDstChk(t, dst) | ||
} | ||
|
||
func BenchmarkCopyFieldByField(b *testing.B) { | ||
b.ReportAllocs() | ||
it1, row, dst := prepareChks() | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
dst.Reset() | ||
for lhs := it1.Begin(); lhs != it1.End(); lhs = it1.Next() { | ||
dst.AppendRow(lhs) | ||
dst.AppendPartialRow(lhs.Len(), row) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkCopyColumnByColumn(b *testing.B) { | ||
b.ReportAllocs() | ||
it1, row, dst := prepareChks() | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
dst.Reset() | ||
for it1.Begin(); it1.Current() != it1.End(); { | ||
dst.AppendRightMultiRows(it1, row, 128) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,8 @@ type Iterator interface { | |
// Next returns the next Row. | ||
Next() Row | ||
|
||
PreRows(i int) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the use case for this method? |
||
|
||
// End returns the invalid end Row. | ||
End() Row | ||
|
||
|
@@ -75,6 +77,11 @@ func (it *iterator4Slice) Next() Row { | |
return row | ||
} | ||
|
||
// PreRows implements the Iterator interface. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment basically says nothing. You have to be more explicitly. |
||
func (it *iterator4Slice) PreRows(i int) { | ||
|
||
} | ||
|
||
// Current implements the Iterator interface. | ||
func (it *iterator4Slice) Current() Row { | ||
if it.cursor == 0 || it.cursor > it.Len() { | ||
|
@@ -129,6 +136,14 @@ func (it *Iterator4Chunk) Next() Row { | |
return row | ||
} | ||
|
||
// PreRows implements the Iterator interface. | ||
func (it *Iterator4Chunk) PreRows(i int) { | ||
if it.cursor < i { | ||
it.Begin() | ||
} | ||
it.cursor = it.cursor - i | ||
} | ||
|
||
// Current implements the Iterator interface. | ||
func (it *Iterator4Chunk) Current() Row { | ||
if it.cursor == 0 || it.cursor > it.Len() { | ||
|
@@ -196,6 +211,11 @@ func (it *iterator4List) Next() Row { | |
return row | ||
} | ||
|
||
// PreRows implements the Iterator interface. | ||
func (it *iterator4List) PreRows(i int) { | ||
|
||
} | ||
|
||
// Current implements the Iterator interface. | ||
func (it *iterator4List) Current() Row { | ||
if (it.chkCursor == 0 && it.rowCursor == 0) || it.chkCursor > it.li.NumChunks() { | ||
|
@@ -255,6 +275,11 @@ func (it *iterator4RowPtr) Next() Row { | |
return row | ||
} | ||
|
||
// PreRows implements the Iterator interface. | ||
func (it *iterator4RowPtr) PreRows(i int) { | ||
|
||
} | ||
|
||
// Current implements the Iterator interface. | ||
func (it *iterator4RowPtr) Current() Row { | ||
if it.cursor == 0 || it.cursor > it.Len() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the exported method, you must comment. It is not optional.