Github user hvanhovell commented on a diff in the pull request: https://github.com/apache/spark/pull/21840#discussion_r204476440 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala --- @@ -3858,3 +3858,29 @@ object ArrayUnion { new GenericArrayData(arrayBuffer) } } + +case class StructCopy( + struct: Expression, + fieldName: String, + fieldValue: Expression) extends Expression with CodegenFallback { + + override def children: Seq[Expression] = Seq(struct, fieldValue) + override def nullable: Boolean = struct.nullable + + lazy val fieldIndex = struct.dataType.asInstanceOf[StructType].fieldIndex(fieldName) + + override def dataType: DataType = { + val structType = struct.dataType.asInstanceOf[StructType] + val field = structType.fields(fieldIndex).copy(dataType = fieldValue.dataType) + + structType.copy(fields = structType.fields.updated(fieldIndex, field)) + } + + override def eval(input: InternalRow): Any = { + val newFieldValue = fieldValue.eval(input) + val structValue = struct.eval(input).asInstanceOf[GenericInternalRow] --- End diff -- You cannot assume this and you also cannot update the row in-place. You will need to copy the row I am affraid.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org