数字のグループが大きいテキスト ファイル (137 MB テキスト ファイル) があり、groovy を使用してテキスト ファイルを開き、行ごとに読み取り、数字を変更してからデータベースに配置しようとしています (次のように)。文字列)。関連する別々のデータベース列に書き込む必要がある 1 行あたり 2 つの項目があります。
私のテキストファイルは次のようになります。
A.12345
A.14553
A.26343
B.23524
C.43633
C.23525
したがって、フローは次のようになります。
Step 1.The file is opened
Step 2.Line 1 is red
Step 3.Line 1 is split into letter/number pair [:]
Step 4.The number is divided by 10
Step 5.Letter is written to letter data base (as string)
Step 6.Number is written to number database (as string)
Step 7.Letter:number pair is also written to a separate comma separated text file.
Step 8.Proceed to next line (line 2)
出力テキスト ファイルは次のようになります。
A,1234.5
A,1455.3
A,2634.3
B,2352.4
C,4363.3
C,2352.5
数値のデータベースは次のようになります。
1:1234.5
2:1455.3
3:2634.3
4:2352.4
5:4363.3
6:2352.5
*リード番号はデータベース インデックスの場所であり、リレーショナル目的で使用されます
文字のデータベースは次のようになります。
1:A
2:A
3:A
4:B
5:C
6:C
*リード番号はデータベース インデックスの場所であり、リレーショナル目的で使用されます
私はこれのほとんどを行うことができました。私が直面している問題は、 .eachLine( line -> ) 関数を正しく使用できないことです...そして値をデータベースに出力する方法の手がかりがありません。
もう 1 つ重要なことがあります。それは、スクリプトでエラーが発生した場合です。テキスト ファイルには多数のエントリ (約 9000000) が含まれているため、スクリプトが失敗した場合や何かが発生した場合に、最後に変更した行からスクリプトを再開できるようにする方法があるかどうか疑問に思っています。
つまり、スクリプトにエラーが発生し (コンピューターが何らかの理由でシャットダウンされ)、テキスト ファイルの 125122 行目 (125122 行目の変更が完了する) で実行が停止します。 125123 行のスクリプト。
これまでのサンプルコードは次のとおりです。
//openfile
myFile = new File("C:\\file.txt")
//set fileline to target
printFileLine = { it }
//set target to argument
numArg = myFile.eachLine( printFileLine )
//set argument to array split at "."
numArray = numArg.split(".")
//set int array for numbers after the first char, which is a letter
def intArray = numArray[2] { it as int } as int
//set string array for numbers after the first char, which is a letter
def letArray = numArray[1] { it as string }
//No clue how to write to a database or file... or do the persistence thing.
どんな助けでも大歓迎です。