In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Structured text is a very common file format, and the calculation of structured text is also a very common requirement. When implementing this kind of calculation, one easy way to think of is to import the file into the database and then calculate it, but this will consume a lot of time and expensive database resources, and in some cases there is no suitable database available. In this way, we will have a natural idea, if we can calculate directly, it will be much more convenient. Unfortunately, most high-level languages do not provide a basic operation class library for structured text, and it is very tedious to complete these operations by hard coding, which is not only complex code, but also poor maintainability.
As a professional structured data computing class library, aggregator SPL encapsulates rich structured computing functions and supports set operation, association operation and ordered operation, so it can easily realize the operation of structured text. In addition, SPL can also provide calculation results to Java applications through the JDBC call interface (see [how Java calls SPL scripts]), which greatly facilitates the integration work.
Let's take a look at common cases of structured text computing and the corresponding solutions to SPL.
Maintain additional records
Insert a record in line 2 of sales.txt. The source file is as follows:
OrderIDClientSellerIdAmountOrderDate26TAS12142.42009-08-0533DSGC1613.22009-08-1484GC188.52009-10-16133HU11419.82010-12-1232JFS34682009-08-1339NR330162010-08-2143KT321692009-08-27
Code
A1=file ("D:\\ sales.txt"). Import@t () 2=A1.insert (2Magne200, "MS", 20Power2000 ("2015-02-02") 3=file ("D:\\ sales.txt") .export @ t (A1)
Result
OrderIDClientSellerIdAmountOrderDate26TAS12142.42009-08-05200MS2020002015-02-0233DSGC1613.22009-08-1484GC188.52009-10-16133HU11419.82010-12-1232JFS34682009-08-1339NR330162010-08-2143KT321692009-08-27
The function insert inserts the record, and the first argument is the insertion position. When the parameter is 0, the record is appended.
If you just append records to the file, you don't have to read the file, just use the function export@a, as shown in the following code:
A1=create (OrderID,Client,SellerId,Amount,OrderDate) .record ([200,2000 MS date ("2015-02-02")]) 2=file ("D:\\ sales.txt") .export @ a (A1)
Function create creates a new two-dimensional table, and function record appends records to the two-dimensional table.
In addition, you can insert records in batch via insert@r, as follows:
A1=file ("D:\\ sales.txt") .import@t () 2=create (OrderID,Client,SellerId,Amount,OrderDate) 3
= A2.record ([200,200, "MS", 2052000 female date ("2015-02-02")
("2015-03-03")])
4=A1.insert@r (2:A2)
To save space, the code for exporting the file will be omitted below.
Delete record
Delete the second record in sales.txt. The code is as follows:
A1=file ("D:\\ sales.txt") .import@t () 2=A1.delete (2)
The function delete supports batch deletion, such as deletion of 2, 3, 5, 6, 7 records: A1.delete ([2, 5, 3] | to (5, 7))
You can also delete records with Amount less than 1000 according to conditions, such as A1.delete (A1.select (Amount=startDate & & OrderDate).
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.