Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
dwhdeveloper
Contributor
Contributor

How to use hash in talend

I am inserting data in a table from another.
I would like to add a column hash which has hash of all the columns of each row being inserted. 
How would I do that in Talend? 
 
Labels (2)
3 Replies
Anonymous
Not applicable

Can you please explain better what do you want to produce?
TRF
Champion II
Champion II

Hi,
1st, define a routine for conversion (here, mine is called GetHashCode and convert to MD5):
package routines;
import java.security.*;
public class GetHashCode {
public static String getMD5(String strCode) {
java.security.MessageDigest msg;
String digest1 = "";
try {
msg = java.security.MessageDigest.getInstance("MD5");
msg.update(strCode.getBytes(), 0, strCode.length());
digest1 = new java.math.BigInteger(1, msg.digest()).toString(32);
}
catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return digest1.toUpperCase();
}
}

In tMap, add the desired field to your schema, then call the routine passing the input fields concateneted, and push the result to the new field (here is an example):
GetHashCode.getMD5(row1.col1 + row1.col2 + row1.col3)

Hope this helps,
TRF
offcourse2
Contributor
Contributor

Hi

 

I used this code and it worked perfectly. Is it possible to fix the number of character of the hash?

Currently it ranges between 23 and 26 characters, and I'd like to fix that, ensuring I have no duplicates.

 

Thanks