Set calculation is used as a Java structured document libraries

By Amy Snyder,2015-06-22 05:29
15 views 0
Set calculation is used as a Java structured document libraries

    A data analysis of the machine!

    Sometimes we can't use database and USES the file system to store data, then you need to complete data calculation based on the file itself.But JAVA itself lack the corresponding class library, need to hard code to achieve a structured file calculation, complex and unreadable code.

    Use the free collection device can make up for the shortage.Set to calculate encapsulates the rich structured file calculation function, and provides the JDBC interface.JAVA applications can be set to calculate script file as a database stored procedure execution, incoming parameters using JDBC for returns as a result, the details refer to the set of calculation is used as a JAVA class library application structure.

    Below illustrates in JAVA common structural calculation, and set to calculate the corresponding solutions.

    Text query

    SOrder. TXT is TAB text segmentation, and now want to use JAVA query out orders within a specified time period.

    Source data is as follows:

    Set numerical code:

    Read the file, the default delimiter is the TAB, @ t say will be the first line read for the column head.After the query execution conditions.StartDate and endDate as input parameters,

such as the 2010-01-01-2010-01-01.Results:

    Text sorting

    For sOrder. TXT, please according to the customer in the JAVA code descending order, according to the year, month, ascending order.

    Set numerical code: = A1. Sort (- Client, year (OrderDate), month (OrderDate))

    Explanation: use "-" descending order, year, month need to compute.

    B: if you want to in the query on the basis of sorting, can write = A2. Sort (...).Or = A1. Select (...).Sort (...).


    Group summary: calculate every salesman annual sales and orders

    Code: = A1. Groups (SellerId, year (OrderDate); the sum (Amount), count (~))

    Explanation: the function group in the group at the same time to carry on the summary, ~ each group or the current group, said the count (~) is equal to the count (OrderID).


Get the only value:

    Create a list of customers in the sOlder.

    Code: = A1. Id (the Client)


Remove duplicate

    Keep each customer the first line of each sales record in the sOlder. Code: = A1. Group @ 1 (Client, SellerId)

    Explanation: the function group is used to group (can not summary), @ 1 said in article

    1 of the records in each group.



    Find each salesman's three largest sales orders.

    Code: = A1. Group (SellerId; ~. The top (- Amount; (3) : t). The conj (t)

    Explanation: filter the TopN function top, "said -" reverse, conj function is used to merge.

    B: if only one of the biggest order, maxp function can be used.

    The results:

    Correlation calculation

    Emp. TXT is TAB text segmentation, the EId SellerId field in the corresponding sOrder fields, please emp in JAVA. TXT Name, Dept, Gender, the three field aligned to sOrder. TXT.

    Source data is as follows:

    Set numerical code:

    Function connection on the join operation, and the name of two tables to s and e, @ 1 left connection.From the connection table after the need for field, the formation of new structured two-dimensional table.Results:

    B: @ 1 link on the left, @ f all connections, inner connection options.

    The previous example assumes that the file smaller, if the file cannot be larger in the memory, implement the cursor is set up by calculation are available, and details refer to the relevant documents.

Report this document

For any questions or suggestions please email