In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "aggregator how to help java deal with structured text to achieve alignment connection", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "aggregator how to help java deal with structured text to achieve alignment connection" bar!
The text file emp.txt stores employee information, and employees with EId equal to 1 are not in the file. The text file sOrder.txt stores the order information, and its SellerId field corresponds to the EId field in emp. Orders with SellerId equal to 2 are not in the table. Some of the source data are as follows:
Emp.txt:
SOrder.txt:
Now you need to align the Name, Dept, and Gender fields of emp into sOrder, and output the calculation results to a new file. The expected results are as follows:
Aggregator code:
Grid A1 and grid A2 read data from the text file and store the two variables emp and sOrder, respectively. The function import is used here, and its default column separator is tab, and the function option @ t means to read the * line as the field name. Because only some of the fields in emp.txt are needed in the example, A1 needs to take the field name as a parameter. After the calculation is completed, the values of emp and sOrder are shown below:
A3:=join@1 (sOrder:s,SellerId;emp:e,EId). The function join performs the join operation and renames the two tables to s and e. The function option @ 1 indicates the left concatenation, which is the requirement in the example: align the emp into the sOrder. The calculated results are as follows:
Click the blue link to see the specific records, as follows:
The right connection is just to swap the alignment, which can also be achieved with an aggregator. For example, to align sOrder according to emp, you only need to exchange the order of the two in the code, that is, = join@1 (emp:e,EId;sOrder:s,SellerId). The result is as follows:
Full connection is also easy to implement, just use the function option @ f, the code is: join@f (sOrder:s,SellerId;emp:e,EId), and the result is as follows:
There are four join operations, in addition to the left connection, right connection, full connection and inner connection mentioned above. The function join performs inline connection by default, and the code is = join (sOrder:s,SellerId;emp:e,EId). The calculation result is as follows:
Back to the example, A4:=A3.new (s.OrderID, s.Client, s.SellerId, s.Amount, s.OrderDate, e.Name, e.Dept, e.Gender). This code takes the required fields from the joined table to form a new structured two-dimensional table. The result is as follows:
Now that the alignment is done, output the data to a new file with the code = file ("E:\\ result.txt") .export @ t (A4).
By default, the function export uses tab as the column separator, and the function option @ t means to output the field name on the * * line. Open result.txt and you can see the following:
The above script has done all the work on its output, and then all you have to do is call it in the JAVA code.
/ / establish an esProc jdbc connection
Class.forName ("com.esproc.jdbc.InternalDriver")
Con= DriverManager.getConnection ("jdbc:esproc:local://")
/ / call esProc, where test is the script file name
St = (com.esproc.jdbc.InternalCStatement) con.prepareCall ("call test ()")
/ / execute esProc stored procedures
St.execute ()
As long as the above JAVA code is executed, the emp will be aligned into sOrder and the result of the calculation will be output to the result.txt file.
The following example is slightly changed: query the data in sOrder by dynamic time period, and perform the same alignment operation, and * return the result directly to JAVA. To implement this example, the aggregator needs to define two parameters, begin and end, which represent the start and end time. The aggregator code is as follows:
The red part is the changed code.
A2: sOrder is further filtered through the function select. The filter condition is the start and end time sent by JAVA, that is, @ begin and @ end.
A5: output the calculation results in A4 to the JDBC interface.
The JAVA code also needs to be changed to pass in parameters and get the results of the calculation. The code is as follows:
Class.forName ("com.esproc.jdbc.InternalDriver")
Con= DriverManager.getConnection ("jdbc:esproc:local://")
St = (com.esproc.jdbc.InternalCStatement) con.prepareCall ("call test (?)")
St.setObject (1Jing startTime)
St.setObject (2jinendtime)
St.execute ()
ResultSet set = st.getResultSet ()
Thank you for your reading, the above is the content of "how the aggregator helps java deal with structured text to achieve alignment connection". After the study of this article, I believe you have a deeper understanding of how the collector helps java deal with structured text to achieve alignment connection, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.