Skip to content

Commit b504b6a

Browse files
robbinspgdavies
authored andcommitted
[SPARK-12470] [SQL] Fix size reduction calculation
also only allocate required buffer size Author: Pete Robbins <robbinspg@gmail.com> Closes apache#10421 from robbinspg/master.
1 parent 6c83d93 commit b504b6a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeRowJoiner.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
6161
val outputBitsetWords = (schema1.size + schema2.size + 63) / 64
6262
val bitset1Remainder = schema1.size % 64
6363

64-
// The number of words we can reduce when we concat two rows together.
64+
// The number of bytes we can reduce when we concat two rows together.
6565
// The only reduction comes from merging the bitset portion of the two rows, saving 1 word.
66-
val sizeReduction = bitset1Words + bitset2Words - outputBitsetWords
66+
val sizeReduction = (bitset1Words + bitset2Words - outputBitsetWords) * 8
6767

6868
// --------------------- copy bitset from row 1 and row 2 --------------------------- //
6969
val copyBitset = Seq.tabulate(outputBitsetWords) { i =>
@@ -171,7 +171,7 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
171171
| // row1: ${schema1.size} fields, $bitset1Words words in bitset
172172
| // row2: ${schema2.size}, $bitset2Words words in bitset
173173
| // output: ${schema1.size + schema2.size} fields, $outputBitsetWords words in bitset
174-
| final int sizeInBytes = row1.getSizeInBytes() + row2.getSizeInBytes();
174+
| final int sizeInBytes = row1.getSizeInBytes() + row2.getSizeInBytes() - $sizeReduction;
175175
| if (sizeInBytes > buf.length) {
176176
| buf = new byte[sizeInBytes];
177177
| }
@@ -188,7 +188,7 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
188188
| $copyVariableLengthRow2
189189
| $updateOffset
190190
|
191-
| out.pointTo(buf, sizeInBytes - $sizeReduction);
191+
| out.pointTo(buf, sizeInBytes);
192192
|
193193
| return out;
194194
| }

0 commit comments

Comments
 (0)