Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ED0D02004A0 for ; Wed, 16 Aug 2017 19:28:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id EB1E7169281; Wed, 16 Aug 2017 17:28:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E236A169280 for ; Wed, 16 Aug 2017 19:28:05 +0200 (CEST) Received: (qmail 68994 invoked by uid 500); 16 Aug 2017 17:27:59 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 68982 invoked by uid 99); 16 Aug 2017 17:27:58 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Aug 2017 17:27:58 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 626DAC0042 for ; Wed, 16 Aug 2017 17:27:58 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.599 X-Spam-Level: X-Spam-Status: No, score=0.599 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-2.8, RCVD_IN_SORBS_SPAM=0.5, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 7YuUrNIm-zKW for ; Wed, 16 Aug 2017 17:27:55 +0000 (UTC) Received: from mail-io0-f169.google.com (mail-io0-f169.google.com [209.85.223.169]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id D97A05FD06 for ; Wed, 16 Aug 2017 17:27:54 +0000 (UTC) Received: by mail-io0-f169.google.com with SMTP id o9so15432067iod.1 for ; Wed, 16 Aug 2017 10:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=V+st1mIAvOmUaUfdc5fEig97NiqQ1+enLQcyx0sAeDI=; b=AbxEtTg50XFBTjhW6oCcA5x0sdGP8j2X0i0F44Y8H5roOQ0P6yX3MbKBAnublBXKV8 yXRgW5VWbOtxG4cBJwdkkYNSZA8oVyDRQ/UqY4lOTcGVzuAoDgUmF4FtEeK3ZTJ2jW98 qx43N4sWbOCqFCGcLJd7zXPodU86ffLJlrMs64B0kTMEtjZXzlSUZo+TQNX7MJJlA7qh KFBt6hFgzq3UOReaY+/pu/AJgVWq7R1ofyZFpRHYHaBRXTYgSU4mk0e3znQoZWEmzTCT IpRD5EswrCMvWg/8sVW/CM3cgHzEAMQHaaVX2CLay/XoeOu5y0GrLpvxYKxIhjmjQDDc 6Myw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=V+st1mIAvOmUaUfdc5fEig97NiqQ1+enLQcyx0sAeDI=; b=MMBySloCPTQtYwdZYTbFCyKPj+pa1c4ANkHdXe96Kb2+9IdjrGryUb2tUfE07yadEV Wis6S+j+joYeD6qGUrsq+tCxYHh5FmlshrRFFGw2liMeoH66mpzOjfeF4W348SReBbof XLi1c91ZOFR/5ue4iwzqYCuwCoGH0oxOtFx90MPY/pVgF+EDyvL/Amjg1UeAyqMoHUBV FJtkyfYgo8c4FJa9bzDc37a2cSs0JvligoL/08r4e9y9rKyoMbYsU/UzLXKQgfrgom7b jie3mbY7fveCoJvEXeSdW75T25YwzrAJUSpvB79t7ubkcs1/QjgOyHFpzzshUoI5NgeM VLWQ== X-Gm-Message-State: AHYfb5inCf4ldIXYyq7uMgHYMqj/XjyH2blbaDPVRqZ4yr/VmKT5jg9Q B9OCn5I4KcVMLkhp2YwX5NIs7LvZu5dGRgw= X-Received: by 10.107.173.104 with SMTP id w101mr2016599ioe.99.1502904473776; Wed, 16 Aug 2017 10:27:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.92.19 with HTTP; Wed, 16 Aug 2017 10:27:53 -0700 (PDT) In-Reply-To: <85ab38acd62ad1cc2ebf3aedf11a97a0@scarlet.be> References: <0f45296071845faf757344a56b7e2ef0@scarlet.be> <6d3f648f999cd9ff726040b5ce84dc64@scarlet.be> <372b12c62d332dbbd71f1889d79855a1@scarlet.be> <6d54922767856921282813460cbfc106@scarlet.be> <85ab38acd62ad1cc2ebf3aedf11a97a0@scarlet.be> From: Gary Gregory Date: Wed, 16 Aug 2017 11:27:53 -0600 Message-ID: Subject: Re: [CSV] CSVMutableRecord To: Commons Developers List Content-Type: multipart/alternative; boundary="001a11449a844a741a0556e23747" archived-at: Wed, 16 Aug 2017 17:28:07 -0000 --001a11449a844a741a0556e23747 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Let's summarize the options: 0) do nothing 1) Add two put methods to CVSRecord making the class mutable 2) Add a "mutableRecord" boolean option to CVSRecord and CSVFormat such that a new boolean in CVSRecord allow method from 1) above to either work or throw an exception. 3) Add a "mutableRecord" boolean option to CVSRecord and CSVFormat such that subclass of CVSRecord called CVSMutableRecord is created which contains two new put methods What else? I like the simplest option: 1. Gary On Tue, Aug 15, 2017 at 6:01 PM, Gilles wrote: > On Tue, 15 Aug 2017 17:43:26 -0600, Gary Gregory wrote: > >> On Tue, Aug 15, 2017 at 5:32 PM, Gilles >> wrote: >> >> On Tue, 15 Aug 2017 22:52:32 +0000, nitin mahendru wrote: >>> >>> On Tue, 15 Aug 2017 12:02:20 -0600, Gary Gregory wrote: >>>> >>>> On Tue, Aug 15, 2017 at 10:38 AM, nitin mahendru >>>>> >>>> >>>>> wrote: >>>>>> >>>>>> >>>>> How about having a state in the class itself which says that it's >>>>> >>>>>> mutable >>>>>> or not. >>>>>> If we call a setter on an immutable then it throws an exception. >>>>>> By default the records are immutable and you need to make them >>>>>> mutable >>>>>> using a new API. >>>>>> >>>>>> >>>>> A code example would be useful... >>>> >>>> >>>> >>>> >>>> Below is the pull request I added. >>>> https://github.com/apache/commons-csv/pull/21 >>>> >>>> >>> As I indicated in the previous message, this is functionally >>> breaking. [I'm diverting this discussion over to the "dev" >>> mailing list.] >>> >>> >> Saying that making record mutable is "breaking" is a bit unfair when we = do >> NOT document the mutability of the class in the first place. >> > > I'm stating a fact: class is currently immutable, change > would make it mutable; it is functionally breaking. > I didn't say that you are forbidden to do it; just that > it would be unwise, particularly if it would be to save > a few bytes. > > Gilles > > > >> Gary >> >> >> >>> The following should be an interesting read: >>> http://markmail.org/message/6ytvmxvy2ndsfp7h >>> >>> >>> Regards, >>> Gilles >>> >>> >>> >>> >>> On Tue, Aug 15, 2017 at 11:17 AM Gilles >>>> wrote: >>>> >>>> On Tue, 15 Aug 2017 12:02:20 -0600, Gary Gregory wrote: >>>> >>>>> > On Tue, Aug 15, 2017 at 10:38 AM, nitin mahendru >>>>> > >>>> >> wrote: >>>>> > >>>>> >> How about having a state in the class itself which says that it's >>>>> >> mutable >>>>> >> or not. >>>>> >> If we call a setter on an immutable then it throws an exception. >>>>> >> By default the records are immutable and you need to make them >>>>> >> mutable >>>>> >> using a new API. >>>>> >>>>> A code example would be useful... >>>>> >>>>> >> pros: Saves memory, Keeps the immutability benefits >>>>> >>>>> What kind of usage are you considering that a single transient >>>>> record matters (as compared to the ~300 MB of the JVM itself...)? >>>>> >>>>> >> cons: people using "mutable" records need to be careful.(While >>>>> >> threading >>>>> >> maybe) >>>>> >> >>>>> > >>>>> > Interesting idea! >>>>> > >>>>> > But I think I like the idea of a subclass better if we are going to >>>>> > split >>>>> > the behavior b/w mutable and immutable. >>>>> >>>>> Once you have a subclass that is able to modify the state of >>>>> its parent, it's a mutable object. Period. >>>>> There is no such thing as a "split". >>>>> >>>>> > >>>>> > For my money and the KISS principle, I would just add the put metho= d >>>>> > in >>>>> > CSVRecord. >>>>> >>>>> Then, any use that assumes immutability will be broken. >>>>> >>>>> >>>>> Gilles >>>>> >>>>> >>>>> > Gary >>>>> > >>>>> >> >>>>> >> -Nitin >>>>> >> >>>>> >> >>>>> >> >>>>> >> >>>>> >> On Tue, Aug 15, 2017 at 9:01 AM Gilles >>>>> >> >>>>> >> wrote: >>>>> >> >>>>> >> > On Tue, 15 Aug 2017 09:49:04 -0600, Gary Gregory wrote: >>>>> >> > > That looks odd to me. What comes up for me is the use case whe= re >>>>> >> I >>>>> >> > > want to >>>>> >> > > ETL a file of 10,000,000 records and update, say, one column. = If >>>>> >> am >>>>> >> > > forced >>>>> >> > > to create a brand new record for every record read, that would >>>>> >> be a >>>>> >> > > shame. >>>>> >> > >>>>> >> > Why? >>>>> >> > >>>>> >> > > If I had a mutable record, I could just keep on updating it an= d >>>>> >> using >>>>> >> > > it to >>>>> >> > > write each row. Read record, update it, write record. No extra >>>>> >> memory >>>>> >> > > needed. >>>>> >> > >>>>> >> > How is the size of 1 additional record going to matter compared = to >>>>> >> the >>>>> >> > size of the whole program? >>>>> >> > >>>>> >> > > Either we can make the current record mutable (what's the harm= ?) >>>>> >> or >>>>> >> > > we can >>>>> >> > > make the parser serve out mutable records based on a config >>>>> >> setting. >>>>> >> > > This >>>>> >> > > could be a subclass of CSVRecord with the extra method I >>>>> >> proposed. >>>>> >> > >>>>> >> > The harm is that you loose all the promises of immutability. >>>>> >> > >>>>> >> > Regards, >>>>> >> > Gilles >>>>> >> > >>>>> >> > > >>>>> >> > > Thoughts? >>>>> >> > > >>>>> >> > > Gary >>>>> >> > > >>>>> >> > > On Tue, Aug 15, 2017 at 8:33 AM, Gilles >>>>> >> > > >>>>> >> > > wrote: >>>>> >> > > >>>>> >> > >> On Tue, 15 Aug 2017 08:01:53 -0600, Gary Gregory wrote: >>>>> >> > >> >>>>> >> > >>> How does that work when you want to change more than one >>>>> >> value? >>>>> >> > >>> >>>>> >> > >> >>>>> >> > >> How about a "vararg" argument: >>>>> >> > >> >>>>> >> > >> /** >>>>> >> > >> * @param orig Original to be copied. >>>>> >> > >> * @param replace Fields to be replaced. >>>>> >> > >> */ >>>>> >> > >> public static CSVRecord createRecord(CSVRecord orig, >>>>> >> > >> Pair ..= . >>>>> >> > >> replace) { >>>>> >> > >> // ... >>>>> >> > >> } >>>>> >> > >> >>>>> >> > >> >>>>> >> > >> Gilles >>>>> >> > >> >>>>> >> > >> >>>>> >> > >> >>>>> >> > >>> Gary >>>>> >> > >>> >>>>> >> > >>> On Aug 15, 2017 00:17, "Benedikt Ritter" >>>>> >> > >>> wrote: >>>>> >> > >>> >>>>> >> > >>> Hi, >>>>> >> > >>>> >>>>> >> > >>>> I very much like that CSVRecord is unmodifiable. So I=E2=80= =99d >>>>> >> suggest an >>>>> >> > >>>> API, >>>>> >> > >>>> that creates a new record instead of mutating the existing >>>>> >> one: >>>>> >> > >>>> >>>>> >> > >>>> CSVRecord newRecord =3D myRecord.put(1, =E2=80=9Evalue") >>>>> >> > >>>> >>>>> >> > >>>> I=E2=80=99m not sure about =E2=80=9Eput=E2=80=9C as a metho= d name since it clashes >>>>> >> with >>>>> >> > >>>> java.util.Map#put, which is mutation based... >>>>> >> > >>>> >>>>> >> > >>>> Regards, >>>>> >> > >>>> Benedikt >>>>> >> > >>>> >>>>> >> > >>>> > Am 15.08.2017 um 02:54 schrieb Gary Gregory >>>>> >> > >>>> : >>>>> >> > >>>> > >>>>> >> > >>>> > Feel free to provide a PR on GitHub :-) >>>>> >> > >>>> > >>>>> >> > >>>> > Gary >>>>> >> > >>>> > >>>>> >> > >>>> > On Aug 14, 2017 15:29, "Gary Gregory" >>>>> >> >>>>> >> > >>>> wrote: >>>>> >> > >>>> > >>>>> >> > >>>> >> I think we've kept the design as YAGNI as possible... :-= ) >>>>> >> > >>>> >> >>>>> >> > >>>> >> Gary >>>>> >> > >>>> >> >>>>> >> > >>>> >> On Mon, Aug 14, 2017 at 3:25 PM, nitin mahendru < >>>>> >> > >>>> >> nitin.mahendru88@gmail.com> wrote: >>>>> >> > >>>> >> >>>>> >> > >>>> >>> Yeah that also is OK. I though there is a reason to kee= p >>>>> >> the >>>>> >> > >>>> CSVRecord >>>>> >> > >>>> >>> without setters. But maybe not! >>>>> >> > >>>> >>> >>>>> >> > >>>> >>> Nitin >>>>> >> > >>>> >>> >>>>> >> > >>>> >>> >>>>> >> > >>>> >>> >>>>> >> > >>>> >>> >>>>> >> > >>>> >>> On Mon, Aug 14, 2017 at 2:22 PM Gary Gregory >>>>> >> > >>>> >>>> >> > >>>> > >>>>> >> > >>>> >>> wrote: >>>>> >> > >>>> >>> >>>>> >> > >>>> >>>> Hi All: >>>>> >> > >>>> >>>> >>>>> >> > >>>> >>>> Should we consider adding put(int,Object) and >>>>> >> put(String, >>>>> >> > >>>> Object) to >>>>> >> > >>>> the >>>>> >> > >>>> >>>> current CSVRecord class? >>>>> >> > >>>> >>>> >>>>> >> > >>>> >>>> Gary >>>>> >> > >>>> >>>> >>>>> >> > >>>> >>>> On Mon, Aug 14, 2017 at 2:54 PM, nitin mahendru < >>>>> >> > >>>> >>>> nitin.mahendru88@gmail.com> >>>>> >> > >>>> >>>> wrote: >>>>> >> > >>>> >>>> >>>>> >> > >>>> >>>>> Hi Everyone, >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> I recently pushed a change(pull request 20) to get th= e >>>>> >> line >>>>> >> > >>>> ending >>>>> >> > >>>> >>> from >>>>> >> > >>>> >>>> the >>>>> >> > >>>> >>>>> parser. >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> Now I want to push another change which I feel will >>>>> >> also be >>>>> >> > >>>> useful >>>>> >> > >>>> for >>>>> >> > >>>> >>>> the >>>>> >> > >>>> >>>>> community. I want to add a CSVRecordMutable class whi= ch >>>>> >> had >>>>> >> > >>>> a >>>>> >> > >>>> >>> constructor >>>>> >> > >>>> >>>>> which accepts a CSVRecord object. So when we have a >>>>> >> > >>>> CSVRecordMutable >>>>> >> > >>>> >>>> object >>>>> >> > >>>> >>>>> from it then we can edit individual columns using it. >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> I would be using this to write back my edited CSV fil= e. >>>>> >> My >>>>> >> > >>>> use case >>>>> >> > >>>> >>> is to >>>>> >> > >>>> >>>>> read a csv, mangle some columns, write back a new csv= . >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> I could have directly raised a pull request but I jus= t >>>>> >> > >>>> wanted to >>>>> >> > >>>> float >>>>> >> > >>>> >>>> the >>>>> >> > >>>> >>>>> idea before and see the reaction. >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> Thanks >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>>> Nitin >>>>> >> > >>>> >>>>> >>>>> >> > >>>> >>>> >>>>> >> > >>>> >>> >>>>> >> > >>>> >> >>>>> >> > >>>> >> >>>>> >> > >>>> >>>>> >> > >>>> >>>>> >> > >>>> >>>>> >> > >> >>>>> >>>>> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --001a11449a844a741a0556e23747--