Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/21912#discussion_r213542353
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
@@ -385,107 +385,120 @@ case class MapEntries(child: Expression) extends
UnaryExpression with ExpectsInp
override protected def doGenCode(ctx: CodegenContext, ev: ExprCode):
ExprCode = {
nullSafeCodeGen(ctx, ev, c => {
+ val arrayData = ctx.freshName("arrayData")
val numElements = ctx.freshName("numElements")
val keys = ctx.freshName("keys")
val values = ctx.freshName("values")
val isKeyPrimitive =
CodeGenerator.isPrimitiveType(childDataType.keyType)
val isValuePrimitive =
CodeGenerator.isPrimitiveType(childDataType.valueType)
+
+ val wordSize = UnsafeRow.WORD_SIZE
+ val structSize = UnsafeRow.calculateBitSetWidthInBytes(2) + wordSize
* 2
+ val elementSize = if (isKeyPrimitive && isValuePrimitive) {
+ Some(structSize + wordSize)
+ } else {
+ None
+ }
+
+ val allocation = CodeGenerator.createArrayData(arrayData,
childDataType.keyType, numElements,
--- End diff --
this is hacky. Actually we want to create an array of struct, but here we
lied and say we want to create an array of key type.
I think we should call `ArrayData.allocateArrayData` here directly.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]