Split a file

Six Stars

Split a file

Hi!

I have a delimited flat file of 1000 lines, I want to divide it into 3 files, depending on the value of column 0, how do I do this? If the value of column 0 is == 1, go to a file; if the value is == 2 it goes to another file.

Thanks!


Accepted Solutions
Employee

Re: Split a file

Hi,

 

    It seems your Column0 is having null values. Could you please modify the code as below to handle the null scenario?

 

Relational.ISNULL(row1.Column0)? null : ((row1.Column0==1) ? row1.Column0 : null)

Warm Regards,
Nikhil Thampi

Please appreciate our members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Employee

Re: Split a file

Hi,

 

     Either you can add an null check expression in your output area so that it will not write the empty data. Or you can avoid them by filtering later using a tfilterrow component.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)


All Replies
Fifteen Stars TRF
Fifteen Stars

Re: Split a file

First solution, 1 tMap with 3 output flow and the appropriate filter expression for each.

Second solution, 1 tFilterRow to separate records for file 1, then a second one to separate records for file 2 and 3.


TRF
Six Stars

Re: Split a file

something I forgot to mention is that those that are type 1 and type 3 have fewer fields than type 2, does this affect?

Six Stars

Re: Split a file

Screenshot_20181218_122720.png

when I execute it, a Null Pointer error is generated

 

 

Employee

Re: Split a file

Hi,

 

    It seems your Column0 is having null values. Could you please modify the code as below to handle the null scenario?

 

Relational.ISNULL(row1.Column0)? null : ((row1.Column0==1) ? row1.Column0 : null)

Warm Regards,
Nikhil Thampi

Please appreciate our members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Six Stars

Re: Split a file

 

I already managed to write different files, but now I want those who do not fulfill the condition, NOT to occupy unnecessary lines.
Thanks!

 

Highlighted
Employee

Re: Split a file

Hi,

 

    The tmap says that your Column0 is not nullable. I hope you have checked the input data is not having any null value for Column0. Also I hope you are not picking any null rows.

 

    If you have checked both these conditions, then you will have to check the functions. Somewhere you are passing the value as  null.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Six Stars

Re: Split a file

I already managed to write different files, but now I want those who do not fulfill the condition, NOT to occupy unnecessary lines.
Thanks!

Screenshot_20181218_130610.png

Employee

Re: Split a file

Hi,

 

     Either you can add an null check expression in your output area so that it will not write the empty data. Or you can avoid them by filtering later using a tfilterrow component.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Six Stars

Re: Split a file

I already managed to write different files, but now I want those who do not fulfill the condition, NOT to occupy unnecessary lines.
Thanks!
Employee

Re: Split a file

Hi,

 

    Are you saying that you are still facing the issue? I hope my previous post solves your query.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

 

Six Stars

Re: Split a file

Thanks!

This is the solution to my problem

Screenshot_20181218_160213.png

 

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download