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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Generation of a 8 digit key with number then letter

Hi there,

 

In a tmap component, I need to generate a key for a column in my output, and I want the key like this

 

00000001

00000002

[...............]

00000009

0000000A

0000000B

[...............]

0000000Z

00000010

00000011

[...............]

0000001A

0000001B

[...............]

0000001Z

00000020

[...............]

 

 

Someone can help me please ?

 

Thanks, Sam

Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi,

 

    You will have to ad your custom code in the Talend routine and you can call the function from tMap.

 

    You can refer the below example article to verify how the routine is being called from a tMap.

 

https://community.talend.com/t5/Design-and-Development/Talend-and-Amazon-Translate-Integration/ta-p/...

 

    Please double check the index range and for any out of bound error since your function rules are based on it.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

View solution in original post

5 Replies
Anonymous
Not applicable
Author

Hi,

 

    While we can do this use case by adding certain logic of mixing running numbers and alphabets, what is the rational to use this method for a key column instead of normal running numbers? 

 

    Did you or your Data Architect evaluated the pros and cons of performance difference between a normal integer value and the exotic combination of numbers and alphabets for data extraction and matching process. Ideally all major relational databases go for numeric method for data extraction except in specific cases like vehicle number plate scenario. So I would advise to evaluate both methods for your use case. If you are still confident that your current method is the best approach, then we can think about merging numeric values and alphabets using custom functions.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

 

Anonymous
Not applicable
Author

Hi,

 

Thansk for helping me, actually I'm an intern in my company, so I asked my tutor the piece of code to do that, and he gave me something in vb.net, I'll try to turn it into expression for my tMap, I hope it's going to work, otherwise I'll be back here later.

 

Thanks

Anonymous
Not applicable
Author

@samsamarzr 

 

No worries. You try to recreate the flow through the Talend jobs and if you are facing any issue, please feel free to come back with job flow screenshots and the output or error you are getting.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

Anonymous
Not applicable
Author

Hi again, 

 

So I have my code in Java to generate the key with the old one again and again. And I want the key update in each new row in my tMap.

Like, if I have 527 rows in a file, in the tmap i want to link this rows to 527 different key generated by this code.

So actually I have my tFileInput, a tMap and my tFileOutput, which component should I add to my job to make it work ?

 

Hope you'll understand everything. Piece of code to generate the new key in Java below

 

Thanks, Sam

 

public static String getNextCode(String code) {
		String pst_code = code;
		int i;
		boolean done ;
		int value;
		String newCode;
		char ret;
		char in;

		i=0;
		done = false;



		while(done == false) {
			ret = pst_code.charAt(7-i);
			value = (int)ret;
			if(value>=48 && value<57) {
				done = true;
				in = (char) (value+1);

				if(i ==0) {
					newCode = pst_code.substring(0,7) + in;
				}
				else {
					newCode = pst_code.substring(0, 7-i)+in+pst_code.substring(7-i+1);
				}
				pst_code = newCode.toString();
			}
			else if(value == 57){
				done = true;
				in = (char) 65;

				if(i ==0) {
					newCode = pst_code.substring(0,7) + in;
				}
				else {
					newCode = pst_code.substring(0, 7-i)+in+pst_code.substring(7-i+1);
				}
				pst_code = newCode.toString();

			}
			else if(value>=65 && value < 90) {
				done = true;
				in = (char) (value+1);

				if(i ==0) {
					newCode = pst_code.substring(0,7) + in;
				}
				else {
					newCode = pst_code.substring(0, 7-i)+in+pst_code.substring(7-i+1);
				}
				pst_code = newCode.toString();

			}
			else if(value==90) {
				done = false;
				in= (char) 48;
				if(i ==0) {
					newCode = pst_code.substring(0,7) + in;
				}
				else {
					newCode = pst_code.substring(0, 7-i)+in+pst_code.substring(7-i+1);
				}
				pst_code = newCode.toString();
				i++;
			}
		}

		return pst_code;
	}
Anonymous
Not applicable
Author

Hi,

 

    You will have to ad your custom code in the Talend routine and you can call the function from tMap.

 

    You can refer the below example article to verify how the routine is being called from a tMap.

 

https://community.talend.com/t5/Design-and-Development/Talend-and-Amazon-Translate-Integration/ta-p/...

 

    Please double check the index range and for any out of bound error since your function rules are based on it.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂