A Data Science Central Community

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:

The esProc script is as follows:

A1：=file("E:\\ formula.txt"). *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:

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:

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

A3：=file("E:\\ result.txt")[email protected](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:

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

© 2020 AnalyticBridge.com is a subsidiary and dedicated channel of Data Science Central LLC Powered by

Badges | Report an Issue | Privacy Policy | Terms of Service

**Most Popular Content on DSC**

To not miss this type of content in the future, subscribe to our newsletter.

- Book: Applied Stochastic Processes
- Long-range Correlations in Time Series: Modeling, Testing, Case Study
- How to Automatically Determine the Number of Clusters in your Data
- New Machine Learning Cheat Sheet | Old one
- Confidence Intervals Without Pain - With Resampling
- Advanced Machine Learning with Basic Excel
- New Perspectives on Statistical Distributions and Deep Learning
- Fascinating New Results in the Theory of Randomness
- Fast Combinatorial Feature Selection

**Other popular resources**

- Comprehensive Repository of Data Science and ML Resources
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- 100 Data Science Interview Questions and Answers
- Cheat Sheets | Curated Articles | Search | Jobs | Courses
- Post a Blog | Forum Questions | Books | Salaries | News

**Archives:** 2008-2014 |
2015-2016 |
2017-2019 |
Book 1 |
Book 2 |
More

**Most popular articles**

- Free Book and Resources for DSC Members
- New Perspectives on Statistical Distributions and Deep Learning
- Time series, Growth Modeling and Data Science Wizardy
- Statistical Concepts Explained in Simple English
- Machine Learning Concepts Explained in One Picture
- Comprehensive Repository of Data Science and ML Resources
- Advanced Machine Learning with Basic Excel
- Difference between ML, Data Science, AI, Deep Learning, and Statistics
- Selected Business Analytics, Data Science and ML articles
- How to Automatically Determine the Number of Clusters in your Data
- Fascinating New Results in the Theory of Randomness
- Hire a Data Scientist | Search DSC | Find a Job
- Post a Blog | Forum Questions

## You need to be a member of AnalyticBridge to add comments!

Join AnalyticBridge