Github user ueshin commented on a diff in the pull request: https://github.com/apache/spark/pull/21912#discussion_r210533651 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala --- @@ -385,53 +385,81 @@ 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 = ctx.createArrayData(arrayData, childDataType.keyType, numElements, + s" $prettyName failed.", elementSize = elementSize) + val setFunc = ctx.setArrayElementFunc(childDataType.keyType) --- End diff -- We can delay this into `genCodeForPrimitiveElements`?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org