Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a CRM field as a source which I need to split into two. Output is sql server.
Anything before : should load to crmDesc and anything after : should load to crmID
ABCDEFG:1
What is a java syntax that I can use?
Can you please give me a syntax how to do this in Java.
To use the String.split() method in a tJavaRow, first create your output columns. I have assumed you will use "crmDesc" and "crmID". Then (assuming your input data column is "myField") your code would look like below...
//Code generated according to input schema and output schema
String[] fields = input_row.myField!=null ? input_row.myField.split(":") : new String[0];
if(fields.length==2){
output_row.crmDesc = fields[0];
output_row.crmID = fields[1];
}else if(fields.length==1){
output_row.crmDesc = fields[0];
output_row.crmID = "";
}else{
output_row.crmDesc = "";
output_row.crmID = "";
}
I've covered scenarios where your input data is null, doesn't contain a ":" (I've assumed the data should go to the "crmDesc" column in that scenario), is as you expect and if more than 1 ":" character appears (it outputs blank fields for that). You can obviously adjust to your requirements.