MyPage is a personalized page based on your interests.The page is customized to help you to find content that matters you the most.


I'm not curious

esProc Helps Process Structured Texts in Java –Expression Computing

Published on 12 November 14
265
0
0

As Java doesnât directly support dynamically parsing expressions in the text files, the computation can only be realized by splitting strings manually and then writing a recursive program. The whole process requires writing a great amount of code, is complicated and the code is difficult to maintain. With the assistance of esProc, we can develop program for the computation in Java without writing code manually. Letâs look at how esProc works through an example.

Here is a text file formula.txt with tab being the separator and the first row being the column names. It has three columns: No, type and exp. Column exp consists of formulas. It is required to parse the formulas in column exp dynamically, append the results to the column and rename it as value. The first rows of data of formula.txt are as follows:
esProc Helps Process Structured Texts in Java âExpression Computing - Image 1
The esProc script is as follows:
esProc Helps Process Structured Texts in Java âExpression Computing - Image 2
A1ï¼=file("E:\\ formula.txt").import@t(). import function is used to import the text file. Function option @t means importing the first row as the column names. The imported data will be stored in cell A1 as follows:
esProc Helps Process Structured Texts in Java âExpression Computing - Image 3
A2ï¼=A1.derive(eval(exp):value).derive function is used to add a new column - value - to A1. The value of the column is eval(exp). eval function is to parse the strings dynamically. For example, the computed result of eval(â1+1â) is 2. Since column exp consists of multiple strings, the computed result of eval (exp) will be multiple too, as shown below:
esProc Helps Process Structured Texts in Java âExpression Computing - Image 4

Now that the dynamic expression has been parsed, A2 will be written to a text file. The code is:

A3ï¼=file("E:\\ result.txt").export@t(A2)

In the above script, export function is used to write the data in A2 to the file result.txt. Function option @t means writing the column names to the first row. The following content will be shown when the file is opened:
esProc Helps Process Structured Texts in Java âExpression Computing - Image 5

A4ï¼result A2. This line of script is to return the data in A2 to Java. To get the result, Java will only call the esProc script through JDBC. The code for this last step is as follows:

//create a connection using esProcjdbc

Class.forName("com.esproc.jdbc.InternalDriver");

con= DriverManager.getConnection("jdbc:esproc:local://");

//call esProc file script, whose name is test

st =(com.esproc.jdbc.InternalCStatement)con.prepareCall("call test()");

st.execute();//execute esProc stored procedure

ResultSet set = st.getResultSet(); // get the result set
As Java doesnât directly support dynamically parsing expressions in the text files, the computation can only be realized by splitting strings manually and then writing a recursive program. The whole process requires writing a great amount of code, is complicated and the code is difficult to maintain. With the assistance of esProc, we can develop program for the computation in Java without writing code manually. Letâs look at how esProc works through an example.

Here is a text file formula.txt with tab being the separator and the first row being the column names. It has three columns: No, type and exp. Column exp consists of formulas. It is required to parse the formulas in column exp dynamically, append the results to the column and rename it as value. The first rows of data of formula.txt are as follows:

esProc Helps Process Structured Texts in Java â

The esProc script is as follows:

esProc Helps Process Structured Texts in Java â

A1ï¼=file("E:\\ formula.txt").import@t(). import function is used to import the text file. Function option @t means importing the first row as the column names. The imported data will be stored in cell A1 as follows:

esProc Helps Process Structured Texts in Java â

A2ï¼=A1.derive(eval(exp):value).derive function is used to add a new column - value - to A1. The value of the column is eval(exp). eval function is to parse the strings dynamically. For example, the computed result of eval(â1+1â) is 2. Since column exp consists of multiple strings, the computed result of eval (exp) will be multiple too, as shown below:

esProc Helps Process Structured Texts in Java â

Now that the dynamic expression has been parsed, A2 will be written to a text file. The code is:

A3ï¼=file("E:\\ result.txt").export@t(A2)

In the above script, export function is used to write the data in A2 to the file result.txt. Function option @t means writing the column names to the first row. The following content will be shown when the file is opened:

esProc Helps Process Structured Texts in Java â

A4ï¼result A2. This line of script is to return the data in A2 to Java. To get the result, Java will only call the esProc script through JDBC. The code for this last step is as follows:

//create a connection using esProcjdbc

Class.forName("com.esproc.jdbc.InternalDriver");

con= DriverManager.getConnection("jdbc:esproc:local://");

//call esProc file script, whose name is test

st =(com.esproc.jdbc.InternalCStatement)con.prepareCall("call test()");

st.execute();//execute esProc stored procedure

ResultSet set = st.getResultSet(); // get the result set

This blog is listed under Development & Implementations and Data & Information Management Community

Related Posts:
Post a Comment

Please notify me the replies via email.

Important:
  • We hope the conversations that take place on MyTechLogy.com will be constructive and thought-provoking.
  • To ensure the quality of the discussion, our moderators may review/edit the comments for clarity and relevance.
  • Comments that are promotional, mean-spirited, or off-topic may be deleted per the moderators' judgment.
You may also be interested in
Awards & Accolades for MyTechLogy
Winner of
REDHERRING
Top 100 Asia
Finalist at SiTF Awards 2014 under the category Best Social & Community Product
Finalist at HR Vendor of the Year 2015 Awards under the category Best Learning Management System
Finalist at HR Vendor of the Year 2015 Awards under the category Best Talent Management Software
Hidden Image Url

Back to Top