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 379E72004F3 for ; Tue, 15 Aug 2017 18:39:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3621F166943; Tue, 15 Aug 2017 16:39: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 53B80166897 for ; Tue, 15 Aug 2017 18:39:05 +0200 (CEST) Received: (qmail 20365 invoked by uid 500); 15 Aug 2017 16:38:57 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 20352 invoked by uid 99); 15 Aug 2017 16:38:56 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Aug 2017 16:38:56 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 74CF0180652 for ; Tue, 15 Aug 2017 16:38:56 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.129 X-Spam-Level: *** X-Spam-Status: No, score=3.129 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_REPLY=1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id zWvDSSu8B1cZ for ; Tue, 15 Aug 2017 16:38:54 +0000 (UTC) Received: from mail-ua0-f178.google.com (mail-ua0-f178.google.com [209.85.217.178]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id A89B25F3D0 for ; Tue, 15 Aug 2017 16:38:53 +0000 (UTC) Received: by mail-ua0-f178.google.com with SMTP id q25so4873215uah.1 for ; Tue, 15 Aug 2017 09:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Wl7vCpKcd0LHypxfxHgyRWd1eitRaIr1DDs8PxtA2jM=; b=ZS8Yb39axeifTl5GnuxCsD+4OYvpdtgMCMsdPgT5f62jGZqCWtZ9A2d3PbZkXz/pEi Ue+JeYur0JvJXHQYCpqX2C4hv/fLHi8X9aGgJOJOw3QoZK/AoGqUqmEURnoOY5PBkpkO tL8dtULL3R3LeHoxCQJgKeMz3LAFc//jSSKmsXTFp0z4CEeJPhuAII2yx/76mvCpMhmZ +3Zoo0xHNWHc9n3m8P3AQIBZrGDAuG8O3H5JDWsnyBGonF0r7g/79bwAcbWn+vkyJzql rTj4HiLmBLzmEhjye8H3yXPV9d3PpcnhI2w3aksZKl9iRpyye0A5JECH8eEKWJurSfc/ tQFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Wl7vCpKcd0LHypxfxHgyRWd1eitRaIr1DDs8PxtA2jM=; b=BIksg0dv/w2je2D5wRmJCsymH5plFSKrMeI4iaW5lP//3kP27CmXFiwyL0yvzUOl99 hS+/BFEyS+i7VUs6SOp5K7QfpIw1Fqbq4vBflUiow9pUkDP1MYi+WH/okL+z5+Pv0Pbm 814+jA7ZXyGNGwreXqVe+IKmvTqIqL1Weo17cWg6kSWbXU0UXbQFc35JXIUfmTonRRtY xqpVrwjMYr3EhfZxQvQl2N9AfQhtIV6ByCUJzh8xnXg9tdMqNMKqge5ndB7gABnW4TiD rvautSu3Vi3IdfCukt6JxcjFiVsSwHnk989TfSkpzk7y3mtDQMy9Enjxzub55ZivLG2M vAiw== X-Gm-Message-State: AHYfb5iMHnMmfe41SfBu4ndjOFdlm+1z8z2CWGHBGS2Ew3JgLy3iiX1t T5JdWPrCDKMz+2wkhl6WKqYJm1ETpw== X-Received: by 10.159.60.75 with SMTP id w11mr16678944uah.20.1502815132367; Tue, 15 Aug 2017 09:38:52 -0700 (PDT) MIME-Version: 1.0 References: <0f45296071845faf757344a56b7e2ef0@scarlet.be> <6d3f648f999cd9ff726040b5ce84dc64@scarlet.be> In-Reply-To: <6d3f648f999cd9ff726040b5ce84dc64@scarlet.be> From: nitin mahendru Date: Tue, 15 Aug 2017 16:38:41 +0000 Message-ID: Subject: Re: [CSV] CSVMutableRecord To: Commons Users List Content-Type: multipart/alternative; boundary="f40304363f3820bfb40556cd6ac9" archived-at: Tue, 15 Aug 2017 16:39:06 -0000 --f40304363f3820bfb40556cd6ac9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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. pros: Saves memory, Keeps the immutability benefits cons: people using "mutable" records need to be careful.(While threading maybe) -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 where 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 and 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 sugg= est 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 method name si= nce 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 keep 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 the 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 which 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 file. 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 just > >>>> wanted to > >>>> float > >>>> >>>> the > >>>> >>>>> idea before and see the reaction. > >>>> >>>>> > >>>> >>>>> Thanks > >>>> >>>>> > >>>> >>>>> Nitin > >>>> >>>>> > >>>> >>>> > >>>> >>> > >>>> >> > >>>> >> > >>>> > >>>> > >>>> > >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --f40304363f3820bfb40556cd6ac9--