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 D27412004F3 for ; Tue, 15 Aug 2017 20:17:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D1014167224; Tue, 15 Aug 2017 18:17:11 +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 F0C3C167222 for ; Tue, 15 Aug 2017 20:17:10 +0200 (CEST) Received: (qmail 94637 invoked by uid 500); 15 Aug 2017 18:17:09 -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 94552 invoked by uid 99); 15 Aug 2017 18:17:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Aug 2017 18:17:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id DBD191A05F1 for ; Tue, 15 Aug 2017 18:17:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=scarlet.be Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id BMstTJ5UZzGd for ; Tue, 15 Aug 2017 18:17:06 +0000 (UTC) Received: from sif.is.scarlet.be (sif.is.scarlet.be [193.74.71.28]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 23CFF5F239 for ; Tue, 15 Aug 2017 18:17:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=scarlet.be; s=scarlet; t=1502821020; bh=eo+RTndxCMgzfA3oC5dxi6XxPAjxs29cs6uUmwX6pRI=; h=MIME-Version:Content-Type:Content-Transfer-Encoding:Date:From:To: Subject:In-Reply-To:References:Message-ID; b=nNlC8sZjXe4DqjDlGG43R49mmpEkZrLVnHZcbJdC9yuwVPpwaSgtDlUOh2XEBbrpf A5OIzx3oEoC1FDzTObsBIGV46JP+lKrFJtCCznLCwmsCdxG6mvpAvOHweah4Sz1ll9 eNaECQFKUrkx9hrZSLqrvgVpNCCytbXC5gXhda9g= Received: from webmail.scarlet.be (gresham.is.scarlet.be [193.74.71.215]) by sif.is.scarlet.be (8.14.9/8.14.9) with ESMTP id v7FIH0Yp030304 for ; Tue, 15 Aug 2017 20:17:00 +0200 X-Scarlet: d=1502821020 c=193.74.71.215 Received: from ip-213-49-203-234.dsl.scarlet.be ([213.49.203.234]) via ip-213-49-203-234.dsl.scarlet.be ([213.49.203.234]) by webmail.scarlet.be with HTTP (HTTP/1.1 POST); Tue, 15 Aug 2017 20:17:00 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Tue, 15 Aug 2017 20:17:00 +0200 From: Gilles To: Subject: Re: [CSV] CSVMutableRecord In-Reply-To: References: <0f45296071845faf757344a56b7e2ef0@scarlet.be> <6d3f648f999cd9ff726040b5ce84dc64@scarlet.be> Message-ID: <372b12c62d332dbbd71f1889d79855a1@scarlet.be> X-Sender: gilles@harfang.homelinux.org User-Agent: Scarlet Webmail X-DCC-scarlet.be-Metrics: sif; whitelist X-Virus-Scanned: clamav-milter 0.98.1-exp at sif X-Virus-Status: Clean archived-at: Tue, 15 Aug 2017 18:17:12 -0000 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 method > 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 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’d >> suggest an >> > >>>> API, >> > >>>> that creates a new record instead of mutating the existing >> one: >> > >>>> >> > >>>> CSVRecord newRecord = myRecord.put(1, „value") >> > >>>> >> > >>>> I’m not sure about „put“ as a method 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 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