Text Data Query in SPL

 

Question

I have a text file which has more than five hundreds of rows in the form of a table. I would like to implement a DAO design pattern to get the selected data from the file. Can somebody give me an idea to achieve this?

Here’s a sample of the txt file:

s.no,name,designation,years 

1,John,QA,4 

2,pieter,developer,5 

3,sharon,web-designer,7 

and so-on......!  

 

Thanks,
Sasi

 

Answer

It’s a simple value assignment operation to store text data in DAO. But you need a computing engine, such as SPL (Structured Process Language) to process the structured data for Java. The professional computing engine can achieve many complicated computing goals for the advanced language. You can use SPL select() function to perform the record query. I’ll illustrate this for you using the following text file:

The text data:

undefined

SPL script:

A

1

=file("D:/note.txt").import()

2

=A1.groups(_1,_2; sum(_6))

3

=A2.select(_1==1   &&date(  _2,"yyyy/MM/dd")>=date("2014/10/01","yyyy/MM/dd"))

4

=A1.sort(_1,_2)

A1: Import the text data.

A2: Group data by the 1st column and the 2nd column and then sum the 6th column.

A3: Get records where value of the 1st column is 1 and value in the 2nd column is later than 2014/10/01.

A4: Sort the selected records by the 1st column and the 2nd column.

esProc SPL is a computing engine designed to process structured data. An SPL script can integrate with a Java application through esProc JDBC. See How to Call an SPL Script in Java to learn more.