Open
Conversation
shoo
requested changes
Sep 23, 2023
Comment on lines
+157
to
+159
| mkdir("temp"); | ||
| scope (exit) rmdirRecurse("temp"); | ||
| write("temp/test.csv", "Name,Hoge,Value\nA,Fuga,10.0\nB,Foo,1.5\nC,Bar,-12.5"); |
Member
There was a problem hiding this comment.
これはただのコメントですが、一時ディレクトリを作って最後に消去するやつは、並列テストした時に競合を起こしそうなので、名前かぶりを防ぐため別途共通化した関数とかを作ったほうが良さそう。
↓みたいなやつ
struct DisposableDir
{
string path;
~this()
{
if (path.length && path.exists())
rmdirRecurse(path);
}
alias path this;
}
DisposableDir createDisposableDirectory()
{
DisposableDir dir;
dir.path = buildPath(tempDir(), randomUUID.toString());
mkdir(dir.path);
return dir.move();
}
Comment on lines
+223
to
+229
| auto records = readText("temp/test.csv").csvReader(null); | ||
|
|
||
| // バッファを用意して、1行ずつ処理します。 | ||
| import std.array : appender; | ||
|
|
||
| auto results = appender!(Record[]); | ||
| foreach (record; records) |
Member
There was a problem hiding this comment.
この部分、せっかくなら公式の例に倣って
import std.array : appender;
auto results = appender!(Record[]);
foreach (record; csvReader(File("temp/test.csv").byLine(KeepTerminator.yes), null))こうしてみるのはどうでしょうか。
csvReaderはpopFrontのたびに先頭から順に1文字ずつパースしていく仕組みみたいなので、こうすることでファイルの内容を一度に読み込まなくても済みそうです。
数十GBのCSVファイルを読み込む想定だとこのほうが便利かもしれません。
| write("temp/test.csv", "Name,Date\nA,20200101\nB,20210101\nC,20220101"); | ||
|
|
||
| // あらかじめDate型に変換する簡単な処理を用意します。異常値は考慮していません。 | ||
| Date parseDate(string text8Digit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.