Reset Sequence in Components

Four Stars

Reset Sequence in Components

Hi All

I want to reset the sequence based on the Column ID .here is the eg Input

Numer,sequence("S1",1,1) this wont give my result

Numeric.resetSequence("S1",1) this is not giving a result what i want.

Let me know what should i do or any solutions

ID,Amount

100,1000

100,2000

200,3000

200,4000,

200,5000

300,6000

Output i need

ID,Amount,ResetSeq

100,1000,1

100,2000,2

200,3000,1

200,4000,2

200,5000,3

300,6000,1


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: Reset Sequence in Components

Hi,

The sequence name must be based on the id value.

This can be done by a tJavaRow with the following code:

 

if (input_row.id != ((Integer)globalMap.get("id")) && ((Integer)globalMap.get("id")) != null) {
	// Id change, remove previous sequence and memorize current id
	Numeric.removeSequence(Integer.toString((Integer)globalMap.get("id")));
	globalMap.put("id", input_row.id);
}

output_row.id = input_row.id;
output_row.amount = input_row.amount;
// Initialize or get next value from current sequence 
output_row.sequence = Numeric.sequence(Integer.toString(input_row.id), 1, 1);

Each time the id change, the current sequence is removed and a new one is created.

 

According to your data sample, here is the result:

Starting job test at 22:34 03/09/2017.

[statistics] connecting to socket on port 3683
[statistics] connected
100|1000|1
100|2000|2
200|3000|1
200|4000|2
200|5000|3
300|6000|1
[statistics] disconnected
Job test ended at 22:34 03/09/2017. [exit code=0]

Note that all fields are defined as integers.

Hope this helps.


TRF

All Replies
Seven Stars

Re: Reset Sequence in Components

Use below, it will solve your problem.

Numer,sequence(input_row.ID,1,1) 

 

Please accept solution if it works

Fifteen Stars TRF
Fifteen Stars

Re: Reset Sequence in Components

Hi,

The sequence name must be based on the id value.

This can be done by a tJavaRow with the following code:

 

if (input_row.id != ((Integer)globalMap.get("id")) && ((Integer)globalMap.get("id")) != null) {
	// Id change, remove previous sequence and memorize current id
	Numeric.removeSequence(Integer.toString((Integer)globalMap.get("id")));
	globalMap.put("id", input_row.id);
}

output_row.id = input_row.id;
output_row.amount = input_row.amount;
// Initialize or get next value from current sequence 
output_row.sequence = Numeric.sequence(Integer.toString(input_row.id), 1, 1);

Each time the id change, the current sequence is removed and a new one is created.

 

According to your data sample, here is the result:

Starting job test at 22:34 03/09/2017.

[statistics] connecting to socket on port 3683
[statistics] connected
100|1000|1
100|2000|2
200|3000|1
200|4000|2
200|5000|3
300|6000|1
[statistics] disconnected
Job test ended at 22:34 03/09/2017. [exit code=0]

Note that all fields are defined as integers.

Hope this helps.


TRF
Fifteen Stars TRF
Fifteen Stars

Re: Reset Sequence in Components

Did it help you?

TRF
Four Stars

Re: Reset Sequence in Components

Hi
Do we have any other options other than tJavaRow
Fifteen Stars TRF
Fifteen Stars

Re: Reset Sequence in Components

Probably you can do it using tMap but it may be a little confusing. tJavaRow is the best solution from my point of view. Any problem with this idea?

TRF
Four Stars

Re: Reset Sequence in Components

Problem is not with the solution ..I read it some where like dont use tJavarow .until unless if its a last option..it will slow down the job like that...
Fifteen Stars TRF
Fifteen Stars

Re: Reset Sequence in Components

Maybe if you are looking for microseconds, else you can go on.

TRF

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download