Use case for marital status

Six Stars

Use case for marital status

Hello,

 

I have one column for marital status having value:

 

Marital_status

M

S

D

 

and now i want,

 

Marital_status

married                           for M

single                              for S

Divorce                           for D 


Accepted Solutions
Eight Stars

Re: Use case for marital status

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"


All Replies
Eight Stars

Re: Use case for marital status

Use ternary operator.. Below is logic like: (Add null check , if the Marital status column is nullable )

 

Note: I assumed the datatype for the column MaritalStatus is character so i used equality operator, if the MaritalStatus is string use equals method(String handling ).. 

 

row1.MaritalStatus=='M'?
"Married":
row1.MaritalStatus=='S'?
"Single":
row1.MaritalStatus=='D'?
"Divorced":
"NA"

Six Stars

Re: Use case for marital status

Hello ,

 

 

It is "String" 

 

 

Thanks

Eight Stars

Re: Use case for marital status

row1.MaritalStatus.equals("M")?
"Married":
row1.MaritalStatus.equals("S")?
"Single":
row1.MaritalStatus.equals("D")?
"Divorced":
"NA"

Six Stars

Re: Use case for marital status

Hello ashifa,

 

i tried that but its not workin, i have attached the screenshot of the function and the output of that.

Eight Stars sgv
Eight Stars

Re: Use case for marital status

Are you sure about your Source Data ?

it's "M" or "M   " or "m"

you have to trim your data before, and i think there is a function like equalsIgnoreCase, or something like that.

 

Edit : Other thing : i see that your data is entoured by this character : '

Take Care ! You have to define in your tFileInputDelimited (Check CSV option), the entourage of your text. I think your String value must be like : "'M'" instead of "M"


Good luck,

 

SGV

Six Stars

Re: Use case for marital status

Thank you so much ...it's working 

Eight Stars

Re: Use case for marital status

Looks like you're happy using Java code for this, but the tReplace component is often a much better choice for such things:

 

 

tReplace.png

 

By default you don't need to worry about case sensitivity, but can enable it for each search/replace line if required, and it keeps the logic for your job visible, rather than hidden within more general components. It also has an advanced mode which allows the use of Regular Expressions, which are incredibly powerful should you need them.

 

Whenever possible, you should use components with specific functionality like this, rather than adding complex expressions in a tMap or code in a tJava component, as doing so means your job is largely self documenting, or at least much easier for someone new picking it up to read and understand the process you're automating. Good, well laid out and labelled jobs can also be useful when discussing things with non-technical people.

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 Integration

Practical steps to developing your data integration strategy.

Download