RaqForum 28 No.
237 View •
Get Information of Top N from a CSV File
Problem description & analysis
In the following CSV file, the first column is id, the second column is roomname, the third column is date, the fourth column is time, the fifth column is LOB (length of booking), and the sixth column is PB (person booking), as shown below:
5,Pen y Fan,2000-01-01,0:00:00,292,Jack
We are trying to find n rooms that will be reserved for the longest time, and their specific lengths of booking. Suppose n is 5, we have the following desired result:
1: Taff 296
2: Cadair Idris 292
3: Pen y Fan 292
4: Usk 291
5: Llangorse 290
We write the following script p1.dfx in esProc:
=if(n==1,output("RoomName :"/A2.roomname/""/A2.LOB),output(A2.(#/": "/roomname/" "/LOB).concat@n()))
Set cellset parameter n.
A1 Import roomname column and LOB column from the CSV file.
A2 Get records containing the first n maximum LOBs (length of booking). n is the script parameter.
A3 If n is 1, output the room name with the longest LOB and the specific length; otherwise output the n room names with the longest LOB and their specific lengths.
Read How to Call an SPL Script in Java to learn about the integration of an SPL script with a Java program.