Java programmers are always working with questions. Similarly some days earlier, I came up with an issue about Data process (here refers to Data query, Select result set from data source after processing). Whenever DATA is involved in our java application, what comes to our mind immediately is Database, because it’s easy, powerful, but costly. So here I would like to discuss how does java process Data without database?
In my application, my data-source is an Excel sheet downloaded from a finance website; I have to figure out the Shares rising for N consecutive days in a certain period. For the computation on structured data, programmers usually embed the SQL statements in the Java code, and access the database server via JDBC.
This is what we did conventionally when Database is employed.
Without Database, I tried many ways to work this out. Initially I tried to process Excel Sheet Data with java coding, but I failed because it became very complex for java to complete simply data computation. One issue is how to store these data imported from Excel Sheet. No more options except List. How about aggregating, filter, sorting and grouping, we can not imagine how complicated this is. How to figure out the Shares rising for N consecutive days in a certain period from an Excel Sheet downloaded from finance web? I consulted many people and they shared their similar experience with me. One of the solutions they shared with me is called esProc which I never heard of before, At first look, it is similar with Excel cell style, it is a little bit new for me, but it is not difficulty to use. In my case, the code for this issue is given below:
A1: =file(“E:\\targetData.xlsx”).import@t() //import data
A2=A1.select(Date>=paramStart&&Date<=paramEnd) //filter by data
A3=A2.group(Code) //group by Code
A4=A3.(~.sort(Date)) //sort by Date in each group
A5=A4.(~.dup@t()) //change to Tseq(structured data)
A6=A5.(~.derive((Close-Close[-1]):INC)) //add a colum, increased price
A7=A6.(~derive(if(INC>0,CID=CID[-1]+1,0):CID)) // add a column, continuous increased days
A8=A7.select(~.max(CID)>=ParamNDays) //stock max CID is bigger than N days
A9=A8.(~.Code) //finally, stock code
My difficult issue is solved, but it is with the help of a data process middleware esProc, and I failed to work out this purely with java or other tools. Here I would like to see what would you do if you are having similar case? Please share with me and put you idea or code in your reply, thanks.