tLdapInput能否设置两种分隔符?多值字段拆分null问题求解
First off, the straightforward answer: tLdapInput doesn’t support setting multiple distinct delimiters directly in its "Multi-value field separator" property—it only accepts a single character or string. But don’t worry, there are easy workarounds to fix the whitespace-related null values you’re seeing.
Here are three practical solutions tailored to your scenario:
1. Normalize Delimiters Before Processing with tReplace
This is the simplest fix—standardize all your delimiters to be identical before tLdapInput splits them:
- Add a
tReplacecomponent right before your tLdapInput. - In the tReplace settings:
- Set "Search" to the regex
;\s+(this matches a semicolon followed by one or more spaces). - Set "Replace with" to just
;.
- Set "Search" to the regex
- This will convert all instances of
;into;, making your delimiters consistent. Now tLdapInput can split correctly using;as the separator, and you won’t get leading spaces in your values that break OU name extraction and cause nulls.
2. Clean Up Values After Splitting
If preprocessing isn’t feasible, you can fix the whitespace after the split:
- After tLdapInput splits the values, use a
tMapcomponent to process each element in the split array. - For each value, apply the
trim()method to remove leading/trailing whitespace. For example, if your split field isroles, you can loop through it and userow1.roles[i].trim()in the tMap expression. - This ensures every role string starts with
ou=instead of a space, so your name extraction logic works as expected.
3. Custom Split with Regex in tJavaRow
For full control, handle the splitting yourself using a regex that matches both delimiter variants:
- Add a
tJavaRowcomponent after retrieving the raw LDAP attribute value. - Use the regex
;\\s*to split the string—it matches a semicolon followed by zero or more spaces, so it works for both;and;. - Example code snippet:
String rawRoles = row1.rawRoles; if (rawRoles != null) { String[] cleanedRoles = rawRoles.split(";\\s*"); output_row.roles = cleanedRoles; } else { output_row.roles = new String[0]; } - This splits the string correctly regardless of spacing, and each role will be free of leading whitespace that caused nulls.
The root cause of your null values is that splitting on ; leaves some elements starting with a space (like ou=ROLE_COM_SOUSCRIPTION...). Your OU name extraction logic likely expects the string to start with ou=, so the leading space breaks that parsing. Any of the above fixes will resolve this issue.
内容的提问来源于stack exchange,提问作者Steve Diarrassouba

