Skip to content

Commit

Permalink
[SPARK-12470] [SQL] Fix size reduction calculation
Browse files Browse the repository at this point in the history
also only allocate required buffer size

Author: Pete Robbins <[email protected]>

Closes #10421 from robbinspg/master.

(cherry picked from commit b504b6a)
Signed-off-by: Davies Liu <[email protected]>

Conflicts:
	sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeRowJoiner.scala
  • Loading branch information
robbinspg authored and davies committed Jan 4, 2016
1 parent cd02038 commit b5a1f56
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
val outputBitsetWords = (schema1.size + schema2.size + 63) / 64
val bitset1Remainder = schema1.size % 64

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

// --------------------- copy bitset from row 1 and row 2 --------------------------- //
val copyBitset = Seq.tabulate(outputBitsetWords) { i =>
Expand Down Expand Up @@ -171,7 +171,7 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
| // row1: ${schema1.size} fields, $bitset1Words words in bitset
| // row2: ${schema2.size}, $bitset2Words words in bitset
| // output: ${schema1.size + schema2.size} fields, $outputBitsetWords words in bitset
| final int sizeInBytes = row1.getSizeInBytes() + row2.getSizeInBytes();
| final int sizeInBytes = row1.getSizeInBytes() + row2.getSizeInBytes() - $sizeReduction;
| if (sizeInBytes > buf.length) {
| buf = new byte[sizeInBytes];
| }
Expand All @@ -188,7 +188,7 @@ object GenerateUnsafeRowJoiner extends CodeGenerator[(StructType, StructType), U
| $copyVariableLengthRow2
| $updateOffset
|
| out.pointTo(buf, ${schema1.size + schema2.size}, sizeInBytes - $sizeReduction);
| out.pointTo(buf, ${schema1.size + schema2.size}, sizeInBytes);
|
| return out;
| }
Expand Down

0 comments on commit b5a1f56

Please sign in to comment.