Reading CSV as Map not List

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Reading CSV as Map not List

Tim Dudgeon
Is it possible to use the CSV component to read a CSV file and return a
List<Map<String,String>>?
The keys being the values in the first line of the file.
I can only see a way to get it to generate a List<List<String>>.

Thanks
Tim
Reply | Threaded
Open this post in threaded view
|

Re: Reading CSV as Map not List

Claus Ibsen-2
On Tue, Oct 2, 2012 at 5:04 PM, Tim Dudgeon <[hidden email]> wrote:
> Is it possible to use the CSV component to read a CSV file and return a
> List<Map<String,String>>?
> The keys being the values in the first line of the file.
> I can only see a way to get it to generate a List<List<String>>.
>

No.


> Thanks
> Tim



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: Reading CSV as Map not List

Christian Mueller
Administrator
In reply to this post by Tim Dudgeon
That would be a incompatible change. And what if the user don't want to
specify the keys?

Do you have an issue with the current implementation?

Best,
Christian

Sent from a mobile device
Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <[hidden email]>:

> Is it possible to use the CSV component to read a CSV file and return a
> List<Map<String,String>>?
> The keys being the values in the first line of the file.
> I can only see a way to get it to generate a List<List<String>>.
>
> Thanks
> Tim
>
Reply | Threaded
Open this post in threaded view
|

Re: Reading CSV as Map not List

Tim Dudgeon
On 02/10/2012 19:07, Christian Müller wrote:
> That would be a incompatible change. And what if the user don't want to
> specify the keys?
I was more asking if there was an option to allow this, not asking for a
change in behaviour.
Would be useful e.g. if the data was to be inserted into a database
using SQL, where the keys were the column names.
I think it could somehow be done with a custom Aggregator, but hoping
there was already a solution.

>
> Do you have an issue with the current implementation?
Not at all. Just doesn't support my use case ;-)

Tim

>
> Best,
> Christian
>
> Sent from a mobile device
> Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <[hidden email]>:
>
>> Is it possible to use the CSV component to read a CSV file and return a
>> List<Map<String,String>>?
>> The keys being the values in the first line of the file.
>> I can only see a way to get it to generate a List<List<String>>.
>>
>> Thanks
>> Tim
>>

Reply | Threaded
Open this post in threaded view
|

Re: Reading CSV as Map not List

Claus Ibsen-2
On Tue, Oct 2, 2012 at 8:20 PM, Tim Dudgeon <[hidden email]> wrote:

> On 02/10/2012 19:07, Christian Müller wrote:
>>
>> That would be a incompatible change. And what if the user don't want to
>> specify the keys?
>
> I was more asking if there was an option to allow this, not asking for a
> change in behaviour.
> Would be useful e.g. if the data was to be inserted into a database using
> SQL, where the keys were the column names.
> I think it could somehow be done with a custom Aggregator, but hoping there
> was already a solution.
>

Maybe an option could be added, to enrich the message with a header
that has the header columns as a List<String>.
Then you can use that to mimic a map, as you got the headers and the data.

That said, another option could be added to use List<Map> structure
instead. A LinkedHashMap should be used to ensure the ordering of the
map would be as a List.

We love contributions. So patches with unit tests is welcome.
http://camel.apache.org/contributing.html


>
>>
>> Do you have an issue with the current implementation?
>
> Not at all. Just doesn't support my use case ;-)
>
> Tim
>
>>
>> Best,
>> Christian
>>
>> Sent from a mobile device
>> Am 02.10.2012 17:05 schrieb "Tim Dudgeon" <[hidden email]>:
>>
>>> Is it possible to use the CSV component to read a CSV file and return a
>>> List<Map<String,String>>?
>>> The keys being the values in the first line of the file.
>>> I can only see a way to get it to generate a List<List<String>>.
>>>
>>> Thanks
>>> Tim
>>>
>



--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen