Return-Path: X-Original-To: apmail-kafka-dev-archive@www.apache.org Delivered-To: apmail-kafka-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E918217CD1 for ; Thu, 2 Oct 2014 19:10:34 +0000 (UTC) Received: (qmail 7792 invoked by uid 500); 2 Oct 2014 19:10:34 -0000 Delivered-To: apmail-kafka-dev-archive@kafka.apache.org Received: (qmail 7702 invoked by uid 500); 2 Oct 2014 19:10:34 -0000 Mailing-List: contact dev-help@kafka.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@kafka.apache.org Delivered-To: mailing list dev@kafka.apache.org Received: (qmail 7419 invoked by uid 99); 2 Oct 2014 19:10:34 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Oct 2014 19:10:34 +0000 Date: Thu, 2 Oct 2014 19:10:34 +0000 (UTC) From: "Mayuresh Gharat (JIRA)" To: dev@kafka.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (KAFKA-1610) Local modifications to collections generated from mapValues will be lost MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/KAFKA-1610?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Mayuresh Gharat updated KAFKA-1610: ----------------------------------- Attachment: KAFKA-1610_2014-10-02_12:09:46.patch > Local modifications to collections generated from mapValues will be lost > ------------------------------------------------------------------------ > > Key: KAFKA-1610 > URL: https://issues.apache.org/jira/browse/KAFKA-1610 > Project: Kafka > Issue Type: Bug > Reporter: Guozhang Wang > Assignee: Mayuresh Gharat > Labels: newbie > Fix For: 0.9.0 > > Attachments: KAFKA-1610.patch, KAFKA-1610_2014-08-29_09:51:51.patch, KAFKA-1610_2014-08-29_10:03:55.patch, KAFKA-1610_2014-09-03_11:27:50.patch, KAFKA-1610_2014-09-16_13:08:17.patch, KAFKA-1610_2014-09-16_15:23:27.patch, KAFKA-1610_2014-09-30_23:21:46.patch, KAFKA-1610_2014-10-02_12:07:01.patch, KAFKA-1610_2014-10-02_12:09:46.patch > > > In our current Scala code base we have 40+ usages of mapValues, however it has an important semantic difference with map, which is that "map" creates a new map collection instance, while "mapValues" just create a map view of the original map, and hence any further value changes to the view will be effectively lost. > Example code: > {code} > scala> case class Test(i: Int, var j: Int) {} > defined class Test > scala> val a = collection.mutable.Map(1 -> 1) > a: scala.collection.mutable.Map[Int,Int] = Map(1 -> 1) > scala> val b = a.mapValues(v => Test(v, v)) > b: scala.collection.Map[Int,Test] = Map(1 -> Test(1,1)) > scala> val c = a.map(v => v._1 -> Test(v._2, v._2)) > c: scala.collection.mutable.Map[Int,Test] = Map(1 -> Test(1,1)) > scala> b.foreach(kv => kv._2.j = kv._2.j + 1) > scala> b > res1: scala.collection.Map[Int,Test] = Map(1 -> Test(1,1)) > scala> c.foreach(kv => kv._2.j = kv._2.j + 1) > scala> c > res3: scala.collection.mutable.Map[Int,Test] = Map(1 -> Test(1,2)) > scala> a.put(1,3) > res4: Option[Int] = Some(1) > scala> b > res5: scala.collection.Map[Int,Test] = Map(1 -> Test(3,3)) > scala> c > res6: scala.collection.mutable.Map[Int,Test] = Map(1 -> Test(1,2)) > {code} > We need to go through all these mapValue to see if they should be changed to map -- This message was sent by Atlassian JIRA (v6.3.4#6332)