Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/spark/pull/19827#discussion_r153453043
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/GenerateUnsafeProjection.scala
---
@@ -258,31 +264,28 @@ object GenerateUnsafeProjection extends
CodeGenerator[Seq[Expression], UnsafePro
keyType: DataType,
valueType: DataType,
bufferHolder: String): String = {
- val keys = ctx.freshName("keys")
- val values = ctx.freshName("values")
+ // Puts `input` in a local variable to avoid to re-evaluate it if it's
a statement.
+ val tmpInput = ctx.freshName("tmpInput")
val tmpCursor = ctx.freshName("tmpCursor")
-
// Writes out unsafe map according to the format described in
`UnsafeMapData`.
s"""
- if ($input instanceof UnsafeMapData) {
- ${writeUnsafeData(ctx, s"((UnsafeMapData) $input)", bufferHolder)}
+ final MapData $tmpInput = $input;
+ if ($tmpInput instanceof UnsafeMapData) {
+ ${writeUnsafeData(ctx, s"((UnsafeMapData) $tmpInput)",
bufferHolder)}
} else {
- final ArrayData $keys = $input.keyArray();
- final ArrayData $values = $input.valueArray();
-
// preserve 8 bytes to write the key array numBytes later.
$bufferHolder.grow(8);
$bufferHolder.cursor += 8;
// Remember the current cursor so that we can write numBytes of
key array later.
final int $tmpCursor = $bufferHolder.cursor;
- ${writeArrayToBuffer(ctx, keys, keyType, bufferHolder)}
+ ${writeArrayToBuffer(ctx, s"$tmpInput.keyArray()", keyType,
bufferHolder)}
// Write the numBytes of key array into the first 8 bytes.
Platform.putLong($bufferHolder.buffer, $tmpCursor - 8,
$bufferHolder.cursor - $tmpCursor);
- ${writeArrayToBuffer(ctx, values, valueType, bufferHolder)}
+ ${writeArrayToBuffer(ctx, s"$tmpInput.valueArray()", valueType,
bufferHolder)}
}
"""
--- End diff --
also here we can use `stripMargin`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]