Kettle using JavaScript steps to filter special characters

Source: Internet
Author: User

Kettle using JavaScript steps to filter special characters

Using kettle when extracting large amounts of Excel data, always encountering some special characters in Excel, causing the ExecuteSQL script step to fail, this article records some methods to filter out some special characters. Peers have a better way to achieve, welcome guidance, learn together.

The complete implementation transformation is as follows

1. Use JavaScript steps to filter the characters of all string fields

The JavaScript steps can be implemented in code to avoid adding too many steps and filtering all the fields at once; The code is as follows:

for (vari=0;i<Getinputrowmeta(). Size (); i++) {/

var valuemeta=Getinputrowmeta(). Getvaluemeta (i);

if (Valuemeta.gettypedesc (). Equals ("String")) {

var fstr= Row[i];

fstr=Replace(Row[i],' \ n ',');

fstr=Replace(fstr,' \ R ',');

fstr=Replace(fstr,' \ t ',');

fstr=Replace(fstr,'; ',';');

fstr=Replace(fstr,' •',');

fstr=Replace(fstr,"'","" ");

ROW[I]=FSTR;

}

}

2. Use regular expressions to filter repeating characters

The actual project encountered in the Excel file has several-number, the number is indeterminate, the above way is not, the Replace in string step can be resolved. Useregex is a switch that determines whether a regular expression is used, the search fills in an expression, and replacewith uses a string to replace it.

3. Intercept length

If the content of the data source exceeds the length of the database field, insert an error, using the string cut step can be implemented;

Kettle using JavaScript steps to filter special characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.