Skip to main content
Solved

How to remove special characters from field names in streamsets data collector?


Bikram
Headliner
Forum|alt.badge.img+1

Solution.

The issue can be handled by Field mapper processor. Below the syntax for the same.

 

${str:replaceAll(f:name(), '[.\\-/()!&%^$#@]','')}

 

Attached the screen shot for the reference.

 

NB : The issue also can be handled in different ways e;g(Expression Evaluator, scripting processor etc) 

Best answer by pkandra

Thanks @Bikram.  I should be able to modify that one to meet my needs...probably just \\n so I donā€™t remove spaces.

View original
Did this topic help you find an answer to your question?

15 replies

  • Opening Band
  • 19 replies
  • January 30, 2023

I frequently use this, but ran across a few different situations.

  • Could the same logic be used for removing unwanted characters in field values?
  • How would you go about removing control characters like a tab or new line character from field names or values?

Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

@pkandra 

Kindly try the above the logic and check if it helps in fixing the issues.

If not then in the logic we need to mention which are characters are causing problem.

If i get the error details with your input data which is failing ,so i can help you on that.

Thanks & Regards

Bikram_

 


  • Opening Band
  • 19 replies
  • January 30, 2023

@Bikram your logic works perfectly for the special characters listed.  I canā€™t seem to get it to work for control characters though.  StreamSets regex indicates a \s should handle what I need but I canā€™t get it to work.

Represents a whitespace character - includes space, tab, line break and form feed.

Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

can you please try with the below code and check if it helps.

 

${str:replaceAll(f:name(), '[.\\-/()!&%^$#@ \t\n\r','')}


  • Opening Band
  • 19 replies
  • January 30, 2023

No luck.

 


Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

can i get the sample input data for which you are having issues in it, so i can try to reproduce the same and try to help you on it.


  • Opening Band
  • 19 replies
  • January 30, 2023

Sure.  Iā€™m pulling from a JDBC Multitable consumer source and one of the tables has a column that has some embedded new line characters...an example string is:

  Gas 2012 C1500 Silverado

 

 

 


Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

@pkandra 

can you please give a try the below code.

 

${str:replaceAll(f:name(), '[\\s*.\\-/()!&%^$#@]','')}

 

Thanks & Regards

Bikram_


  • Opening Band
  • 19 replies
  • Answer
  • January 30, 2023

Thanks @Bikram.  I should be able to modify that one to meet my needs...probably just \\n so I donā€™t remove spaces.


Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

@pkandra 

May i know if it helps in fixing your issues.


  • Opening Band
  • 19 replies
  • January 30, 2023

Yes, but I need to only use the regex value I need and also use a conditional expression to replace the new line character within a field value if it exists or else it will turn numeric and date fields to strings for some reason.  The below works for what I need.  Thanks for your assistance.

 

 


Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

@pkandra 

Thanks and good to know that it helps.

Kindly help me to close the issue as resolved and mark as best answer.

Thanks & Regards

Bikram_


  • Opening Band
  • 19 replies
  • January 30, 2023

@Bikram sure...how would I go about doing that?  I had appended my question to your original post.


Bikram
Headliner
Forum|alt.badge.img+1
  • Author
  • Headliner
  • 486 replies
  • January 30, 2023

@pkandra 

Just click on Best answer and publish


  • Opening Band
  • 19 replies
  • January 30, 2023

@Bikram  I believe the Best Answer link only gets displayed if I asked the initial question.


Reply