Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7892#discussion_r36061654
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeRowJoiner.scala
---
@@ -56,76 +52,45 @@ object GenerateUnsafeRowJoiner extends
CodeGenerator[(StructType, StructType), U
}
def create(schema1: StructType, schema2: StructType): UnsafeRowJoiner = {
- val ctx = newCodeGenContext()
val offset = PlatformDependent.BYTE_ARRAY_OFFSET
+ val getLong = "PlatformDependent.UNSAFE.getLong"
+ val putLong = "PlatformDependent.UNSAFE.putLong"
val bitset1Words = (schema1.size + 63) / 64
val bitset2Words = (schema2.size + 63) / 64
val outputBitsetWords = (schema1.size + schema2.size + 63) / 64
val bitset1Remainder = schema1.size % 64
- val bitset2Remainder = schema2.size % 64
// The number of words 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
- // --------------------- copy bitset from row 1
----------------------- //
- val copyBitset1 = Seq.tabulate(bitset1Words) { i =>
- s"""
- |PlatformDependent.UNSAFE.putLong(buf, ${offset + i * 8},
- | PlatformDependent.UNSAFE.getLong(obj1, ${offset + i * 8}));
- """.stripMargin
- }.mkString
-
-
- // --------------------- copy bitset from row 2
----------------------- //
- var copyBitset2 = ""
- if (bitset1Remainder == 0) {
- copyBitset2 += Seq.tabulate(bitset2Words) { i =>
- s"""
- |PlatformDependent.UNSAFE.putLong(buf, ${offset + (bitset1Words
+ i) * 8},
- | PlatformDependent.UNSAFE.getLong(obj2, ${offset + i * 8}));
- """.stripMargin
- }.mkString
- } else {
- copyBitset2 = Seq.tabulate(bitset2Words) { i =>
- s"""
- |long bs2w$i = PlatformDependent.UNSAFE.getLong(obj2, ${offset
+ i * 8});
- |long bs2w${i}p1 = (bs2w$i << $bitset1Remainder) & ~((1L <<
$bitset1Remainder) - 1);
- |long bs2w${i}p2 = (bs2w$i >>> ${64 - bitset1Remainder});
- """.stripMargin
- }.mkString
-
- copyBitset2 += Seq.tabulate(bitset2Words) { i =>
- val currentOffset = offset + (bitset1Words + i - 1) * 8
- if (i == 0) {
- if (bitset1Words > 0) {
- s"""
- |PlatformDependent.UNSAFE.putLong(buf, $currentOffset,
- | bs2w${i}p1 | PlatformDependent.UNSAFE.getLong(obj1,
$currentOffset));
- """.stripMargin
- } else {
- s"""
- |PlatformDependent.UNSAFE.putLong(buf, $currentOffset + 8,
bs2w${i}p1);
- """.stripMargin
- }
+ // --------------------- copy bitset from row 1 and row 2
--------------------------- //
+ val copyBitset = Seq.tabulate(outputBitsetWords) { i =>
+ val bits = if (bitset1Remainder > 0) {
+ if (i < bitset1Words - 1) {
+ s"$getLong(obj1, offset1 + ${i * 8})"
+ } else if (i == bitset1Words - 1) {
+ // combine last work of bitset1 and first word of bitset2
+ s"$getLong(obj1, offset1 + ${i * 8}) | ($getLong(obj2, offset2)
<< $bitset1Remainder)"
+ } else if (i - bitset1Words < bitset2Words - 1) {
+ // combine next two words of bitset2
+ s"($getLong(obj2, offset2 + ${(i - bitset1Words) * 8}) >>> (64 -
$bitset1Remainder))" +
+ s"| ($getLong(obj2, offset2 + ${(i - bitset1Words + 1) * 8})
<< $bitset1Remainder)"
--- End diff --
add a space before the bitwise or.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]