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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

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.

View solution in original post

8 Replies
Anonymous
Not applicable
Author

Use below, it will solve your problem.

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

 

Please accept solution if it works

TRF
Champion II
Champion II

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
Champion II
Champion II

Did it help you?
Anonymous
Not applicable
Author

Hi
Do we have any other options other than tJavaRow
TRF
Champion II
Champion II

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?
Anonymous
Not applicable
Author

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...
TRF
Champion II
Champion II

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

Hello TRF,

please can you tell me where you initialize the id global variable? 

cause by my side, i got a null pointer exception, and i think it is related to this variable.