How to achieve the below scenario in abinitio

Input file has below contents:
Ball Run
1 1
2 1
3 1
4 1
5 1
6 1
1 0
2 1
3 1
4 1
5 1
6 1
1 1
2 1
3 1
4 1
5 1
6 0
Required Output :
1 6
2 5
3 5

Showing Answers 1 - 53 of 53 Answers

vinoth

  • Jan 26th, 2015
 

I can solve this with use of a SCAN followed with rollup.

to just get the over details scan component with NULL as key and below transform.

Code
  1. type temporary_type=record

  2.   decimal(1000) count;

  3. end; /*Temporary variable*/

  4. temp :: initialize(in) =

  5. begin

  6.   temp.count :: 0;

  7. end;

  8.  

  9. temp :: scan(temp, in) =

  10. begin

  11.   temp.count :: if(in.ball==1) temp.count+1 else temp.count;

  12. end;

  13.  

  14. out :: finalize(temp, in) =

  15. begin

  16.   out.over :: temp.count;

  17.   out.run :: in.run;

  18. end;

  19.  

  20. then "over" as key in rollup

  21. type temporary_type=record

  22.   decimal(100) sumup;

  23. end; /*Temporary variable*/

  24. temp :: initialize(in) =

  25. begin

  26.   temp.sumup :: 0;

  27. end;

  28.  

  29. temp :: rollup(temp, in) =

  30. begin

  31.   temp.sumup :: temp.sumup+in.run;

  32. end;

  33.  

  34. out :: finalize(temp, in) =

  35. begin

  36.   out.run :: temp.sumup;

  37.   out.over :: in.over;

  38. end;

  39.  



There may be a simple solution but this is what I can think of :)

  Was this answer useful?  Yes

SHUBHADIP DASGUPTA

  • Feb 2nd, 2015
 

Use Key change Function in Rollup . Key change function allows us t create group in different ways if we dont have a grouping key. The rule is as long as the function returns 0 all records are considered in the same group. A new group starts when the function returns 1.
out :: key_change(in1,in2)=
begin
out :: if (in.ball == 1) 1 else 0;
end;
Global Variable
------------------
let decimal("x01") count = 0;
Temporary Variable
------------------------
decimal("x01") total_runs;
INITIALIZE
--------------
temp.total_runs :: 0;
Rollup Function
-------------------
temp.total_runs :: temp.total_runs + in.runs;
Finalize
---------
count= count+1;
out.overs :: count;
out.runs_per_over :: temp.total_runs;

  Was this answer useful?  Yes

naman gupta

  • Feb 16th, 2015
 

Hi SHUBHADIP DASGUPTA/VINOTH,
What if this scenario is as follows:
ball run
1 1
2 1
3 2
4 2
5 1
6 3
7 2
8 1
9 0
10 1
11 0
12 3
and required output is
over run
1 10
2 7

  Was this answer useful?  Yes

Gaurav

  • Mar 18th, 2015
 

In such case, it is much easier if you devide the first field with 6 and get quotient value as key for rollup.

  Was this answer useful?  Yes

AbInitio Beginner

  • Mar 14th, 2017
 

Can you explain how does the scan work here! u have given the condition as " if (in.ball==1) temp.count+1 else temp.count" and when the count is increased to 2 how does it work inside the "if" condition. Here what would be the answer after this scan function? Please help me to understand this logic!

  Was this answer useful?  Yes

Aravind Anilkumar

  • May 23rd, 2017
 

Use Rollup in expanded mode. Key Idea is the key change function in rollup.

  Was this answer useful?  Yes

Viswajit Nayak

  • Jun 17th, 2017
 

Use the code below in rollup component.
Solution:
Input File --->Rollup---->Output file

  Was this answer useful?  Yes

Srivani

  • Jul 10th, 2017
 

By using Rollup key change function we can achieve this

  Was this answer useful?  Yes

input-->rollup(key change)-->op
Rollup
type temporary_type=
record
decimal("
")run_per_over;
end;
out :: key_change(in1, in2) =
begin
out :: if((decimal("|"))in2.ball % 6==1)1 else 0;
end;
temp :: initialize(in) =
begin
temp.run_per_over ::0;
end;
temp ::rollup(temp,in)=
begin
temp.run_per_over :: temp.run_per_over +(decimal("|"))in.run;
end;
out :: finalize(temp, in) =
begin
out.ball ::(decimal("|"))next_in_sequence();
out.run ::temp.run_per_over;
end;

  Was this answer useful?  Yes

Abinitio Expert

  • Sep 7th, 2017
 

Yes roll up key change is the correct answer

  Was this answer useful?  Yes

pranau

  • Jan 22nd, 2018
 

using single rool-up:
key change=> in.ball%6==1
out::temporary_type(in)
let decimal (5) sum;
out::initialize(temp)
temp.sum=0;
out::rollup(in,temp)
temp.sum=temp.sum+in.run;
finalize
out.over::next_in_sequence();
out.Total_run::temp.sum;

  Was this answer useful?  Yes

PJ

  • Apr 17th, 2018
 

We can do this Single Rollup and also with very minimal coding as below.
out :: rollup(in) =
begin
out.over :: next_in_sequence();
out.runs :: sum(in.runs);
end;
out :: key_change(in1, in2) =
begin
out :: if(in2.ball % 6 == 1) 1 else 0;
end;

  Was this answer useful?  Yes

Jatin

  • Apr 30th, 2018
 

The Simplest approach with use of component and no coding.
considering ball as first column and runs as second columns
1. Use Reformat and create variable seq_no and store value of next_in_sequence().
2. In the same reformat calculate one column seq = (seq_no-ball)+1
3. Connect Rollup with input must be sorted and key seq and calculate sum(runs) as Total_runs
and use next_in_sequence as Overs.

  Was this answer useful?  Yes

Shubham

  • Sep 28th, 2018
 

Hi,
A beginner level approach would be as described below:
step1- We can use a reformat after input file component and in that we can use a variable to give sequence to all the records using next_in_sequence() function. By doing this we will have a sequence generated from1-18 in this case
step2. then in the transformations tab we can directly map run field to the output and we can create an overs field there where we will use if else condition based on sequence(eg. if(seq is from 1-6)1 else if(seq is from 7-12)2 else 3. So we will have 3 sets of overs(6 1s,6 2s and 6 3s).
step3. We can use a rollup with key(overs) and do a sum(runs) and map overs and runs to the output.
That is it. We will get the required output.
Thanks!
There are number of ways to approach a given problem. The above case is what I could think of immediately after reading the scenario

  Was this answer useful?  Yes

Ashu

  • Nov 5th, 2018
 

Use Reformat then Use Rollup
Refortmat Transformation :
let decimal("|") Gover=1;
let string("|") OverChange="N";
out :: reformat(in) =
begin
Gover = if (OverChange == "Y") Gover+1 else Gover;
OverChange=if (next_in_sequence()%6 == 0) "Y" else "N";
out.* :: in.*;
out.Over :: Gover;
end;
Then Roll up on Over and sum(run)

  Was this answer useful?  Yes

MJ

  • Sep 12th, 2019
 

It will give wrong result. You should use "in2.ball%6==0"

  Was this answer useful?  Yes

Nishad

  • Nov 1st, 2023
 

input -> rollup -> output
rollup transformation:
out :: rollup(in) =
begin
out.over :: next_in_sequence();
out.run :: sum(in.run);
end;
out :: key_change(in1, in2) =
begin
out :: in1.ball==6;
end;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions