Fail, fail, fail
Sometimes, reading candidates answer is just something that I know is going to piss me off.
We have a question that goes something like this (the actual question is much more detailed):
We have a 15TB csv file that contains web log, the entries are sorted by date (since this is how they were entered). Find all the log entries within a given date range. You may not read more than 32 MB.
A candidate replied with an answered that had the following code:
1: string line = string.Empty;2: StreamReader file;3:4: try5: {6: file = new StreamReader(filename);7: }8: catch (FileNotFoundException ex)9: {10: Console.WriteLine("The file is not found.");11: Console.ReadLine();12: return;13: }14:15: while ((line = file.ReadLine()) != null)16: {17: var values = line.Split(',');18: DateTime date = Convert.ToDateTime(values[0]);19: if (date.Date >= startDate && date.Date <= endDate)20: output.Add(line);21:22: // Results size in MB23: double size = (GetObjectSize(output) / 1024f) / 1024f;24: if (size >= 32)25: {26: Console.WriteLine("Results size exceeded 32MB, the search will stop.");27: break;28: }29: }
My reply was:
The data file is 15TB in size, if the data is beyond the first 32MB, it won't be found.
The candidate then fixed his code. It now includes:
1: var lines = File.ReadLines(filename);
Yep, this is on a 15TB file.
Now I’m going to have to lie down for a bit, I am not feeling so good.

Comments
Comment preview