ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.09k stars 435 forks source link

Add ability to detect NULL values #120

Closed lubomirmatus closed 2 years ago

lubomirmatus commented 3 years ago

The lib now does not have ability to detect that some value in row is NULL.

col1, col2, col3
0,0,0
0,0,
0,,0
,0,0

When reading numeric rows

CSVReader<3, trim_chars<>, double_quote_escape<',', '\"'>> csv(file);
int col1, col2, col3;
csv.read_row(col1, col2, col3);

the columns with missing values are returned as 0, so we cannot determine wheather it is real 0 or NULL.

Possible proposal is to use some kind of "nullable" wrapping type.

CSVReader<3, trim_chars<>, double_quote_escape<',', '\"'>> csv(file);
Nullable<int> col1, col2, col3;
csv.read_row(col1, col2, col3);
if (col1.is_null()) { ... }
ben-strasser commented 3 years ago

You can do this:

CSVReader<3, trim_chars<>, double_quote_escape<',', '\"'>> csv(file); char col1, col2, col3; sv.read_row(col1, col2, col3); if (col1 == 0) { ... } else { int val = atoi(col1); ... }

Best Regards Dr. Ben Strasser

On 2021-05-12 15:14, lubomirmatus wrote:

The lib now does not have ability to detect that some value in row is NULL.

col1, col2, col3 0,0,0 0,0, 0,,0 ,0,0

When reading numeric rows

CSVReader<3, trim_chars<>, double_quote_escape<',', '\"'>> csv(file); int col1, col2, col3; csv.read_row(col1, col2, col3);

the columns with missing values are returned as 0, so we cannot determine wheather it is real 0 or NULL.

Possible proposal is to use some kind of "nullable" wrapping type.

CSVReader<3, trim_chars<>, double_quote_escape<',', '\"'>> csv(file); Nullable col1, col2, col3; csv.read_row(col1, col2, col3); if (col1.is_null()) { ... }

-- You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub [1], or unsubscribe [2].

Links:

[1] https://github.com/ben-strasser/fast-cpp-csv-parser/issues/120 [2] https://github.com/notifications/unsubscribe-auth/AC3IBD2YGTV6L6MZFAZLH5DTNJ5LVANCNFSM44YST5NA

lubomirmatus commented 3 years ago

Thank you for your fast response. Yes, I have been thinking about this solution, but it is kind of Do-It-Yourself. It would be fine to have some incorporated solution for NULLs directly in lib.

ben-strasser commented 2 years ago

There are two problems with NULLs:

All of these are problems that are circumvented in a do-it-yourself model. The simple cases that cover 99% get a pretty interface. Everything else needs to go via char*. The library is carefully written, that you will not loose speed by parsing the char* yourself. No copy is involved. It directly points into the internal storage.