Live data from Hacker News

Time to retire the CSV?

bitsondisk.com

551–560 of 594 posts

Re: Time to retire the CSV?

#551

Earlier quoted context omitted.

That sounds like the problem of badly formatted CSV, not a problem with CSV per se. If you stick to one delimiter, and that delimiter is a comma, and escape the delimiter in the data with double-quotes around the entry, and escape double quotes with two double-quotes, well, you have written CSV that is correct and looks correct and will be parsed correctly by literally every CSV parser.

> That sounds like the problem of badly formatted CSV That’s what CSV is. That’s what happens when you ingest CSVs whose production you don’t control. > If you [ignore everything people literally clamour for in these comments and praise csv for] Yes i also like ponies.

> "That’s what CSV is."

That's really not a serious argument against CSV. Since you paraphrase in a silly way, I can do it too! Your "argument" is "Badly formatted files exist, therefore CSV bad".

Everyone "against CSV" seems to be arguing against badly formatted CSV, and leaping to the conclusion that "CSV is just bad" without much more to say about it. I'm sorry that badly formatted CSV gave you a bad time, but the format is fine and gets its job done.

"It doesn't have x, y or z feature therefore no one should be using it ever" is kind of a dumb argument, honestly.

Re: Time to retire the CSV?

#552

Every few years an article like this pops up. I find it tiring - because they are primarily from a software engineer's viewpoint who is probably trying to write a parser and needs to handle the edge cases. As a data scientist, I receive and process around 75GB of CSV every day - of course I don't process it manually. Our processes have been running a few years now and millions of dollars of revenue rides on it. I don…

That's pretty much how I feel as well. People that complain about all the variations in CSV "formats" out there aren't wrong but in practice, for me anyway, most of the files I work with in any given situation come from the same source or a small set of sources and use the same variant. If/when I get a data source introduced into my workflow that differs from this variant I come up with a routine to normalize it, int…

Pretty much the opposite here. Dealing with lots of different formats from different sources, often once off. There's all kinds of crazy things people will call "data" (CSV 'variants' are the tip of the iceberg).

Re: Time to retire the CSV?

#553
post #459

Earlier quoted context omitted.

More generally than editor support, how is the average person expected to type them? I could easily add them to my keyboard, but if "editor support" turned out to mean "Edit > Insert > Record Separator Character" and I was now bound only to editors that support this, absolutely nobody is going to bother. They specifically need to be trivially typable in exactly the way commas and newlines are. Realistically I don't t…

> how is the average person expected to type them? [modifier]-[C,D,E,F]

Actually, there is already a standard way for someone to type these with the control key. To be specific, they are:

  FS: ^\ GS: ^] RS: ^^ US: ^_
Since these delimiters are not much used, on many terminals ^\ is mapped to send SIGQUIT. Use 'stty quit undef' and you can then type this at the keyboard. This works on Linux and OS X, and likely most other systems. Note that with most keyboards you are also using shift for RS and US. For emacs, prefix with C-q so that it inserts the literal.

Other posters have noted that they have ASCII separators recently, I have as recently as 2018 internally at a FAANG. So they are not completely unknown in the wild.

Re: Time to retire the CSV?

#554

Earlier quoted context omitted.

? Quite the contrary. It's more, "all the ones that any craftsman should be using".

A lot of excels and csvs are made by people other than programming crafters.

Yes indeed. It often means they do extra work because they're using the wrong tools.

But you gotta admit that excel is a pretty terrible tool to hand edit a CSV with... ;-)

Re: Time to retire the CSV?

#555
post #547

Earlier quoted context omitted.

A lot of excels and csvs are made by people other than programming crafters.

As with pretty much everything else computing, the world suffers because Microsoft has been dumping terrible tools on it for decades, and people just take their garbage as the way things have to be.

Excel has its advantages, but it is funny the tools people choose to work with. The number of times Access would make more sense...

Re: Time to retire the CSV?

#556
post #427
post #328

Earlier quoted context omitted.

That is not quite a CSV replacement. I use it for things with objects and stuff all the time. To be a CSV replacement you really need to add that each line must be a JSON array, and that it can only have scalars in it (no sub-arrays or objects). That would be a decent enough replacement for CSV itself. Not perfect, but the CSV "standard" is already a nightmare at the edge anyhow and honestly a lot of it can't be fixe…

> that it can only have scalars in it (no sub-arrays or objects) I see CSV files that contain JSON arrays/objects in their fields all the time. Mainly from exporting Postgres tables that contain json/jsonb-typed columns. Are you saying that these aren't valid CSVs?

These are strings containing JSON

Re: Time to retire the CSV?

#557

Earlier quoted context omitted.

CSV uses decimal representations of numeric data, which means you are getting 3.5 bits of data for every 8 bits of storage space (and that's assuming you are using a reasonably compact text encoding... if you are using UTF-16, it's 16 bits). Using a binary representation you can store 8 bits of data for every 8 bits of storage space. CSV uses a variety of date-time formats, but a prevalent one is YYYY-MM-DDThh:mm:ss.…

> CSV uses decimal representations of numeric data, which means you are getting 3.5 bits of data for every 8 bits of storage space (and that's assuming you are using a reasonably compact text encoding... if you are using UTF-16, it's 16 bits). Using a binary representation you can store 8 bits of data for every 8 bits of storage space. XML, JSON, and YAML all have this issue, too. > CSV uses a variety of date-time fo…

> XML, JSON, and YAML all have this issue, too.

Yes. Though to their credit, some of those work with her numbers, which at least gets you 4 bits out of every 8 bits.

> And I know what you're about to argue, but JSON's datetime format is not in the spec. The common JSON datetime format is convention, not standard.

I'm not sure what argument you thought I was making, or why that comment is relevant.

> All you've shown is that CSV has the same limitations that XML, YAML, and JSON have, and those three formats specifically designed and intended for data serialization. Yes, the other formats do have other advantages, but they don't eliminate those three limitations, either.

I'm not sure what your mean by "eliminate", or why you think it matters that there are other formats with the same design trade offs.

> This is for data serialization, which means it's going to potentially be used with data systems that are wholly foreign separating great distances or great timespans. What data serialization format are you comparing CSV to? What do you think CSV is actually used for?

CSV is used for a variety of purposes. The context of the article is using it for data transfer.

The claim was that it was a compact format for data transfer, which is demonstrably not true.

> Are you arguing for straight binary? You know that CSV, XML, YAML and JSON all grew out of the reaction to how inscrutable both binary files and fixed width files were in the 80s and 90s, right?

I'm not sure what "straight binary" means to you. JSON is, for the most part, a binary encoding standard (just not a particularly good one).

You've got the heritage a bit wrong, as XML was not originally designed for data transfer at all. It was an attempt to simplify the SGML document markup language, and the data transfer aspects were subsequently grafted on. JSON & YAML have a slightly more complicated heritage, but neither was intended as a data transfer format. They've all been pressed in to service for that purpose, for a variety of reasons, that can charitably described as tactically advantageous but strategically flawed.

> Binary has all sorts of lovely problems you get to work with like endianness and some systems getting confused if they encounter a mid-file EOF.

I don't know how to break this to you, but text formats can have endianess (in fact, insanely UTF-8 does!), and systems being confused and whether they are at EOF as well.

> Yes, you do end up with a wasted space, but the file is in plain text and ZIP compression is a thing if that's actually a concern.

Wouldn't ZIP be a binary format, with all the problems and concerns you have with binary formats?

So to summarize what you are saying... "CSV is a compact format because you can compress it if you are concerned and all the space it wastes".

Would it be fair to say then that any binary format is a text format because you can convert the binary into a text representation of the data? ;-)

Re: Time to retire the CSV?

#558
post #369

Earlier quoted context omitted.

>CSV is actually horrible at parse-time vs. other data formats I find this really hard to believe given it's a simple enough syntax. And parsing is usually not the limiting factor, usually fast enough to not be noticed alongside interpreting or loading the source data. Every (much more sophisticated) compiler I can think of uses a linear parser based on this assumption.

Just extracting string views can be fast, but converting numbers to and from text is very slow.

But significant compared to time to load the source in the first place? Or any processing that will come after?

Re: Time to retire the CSV?

#559
post #491

What a crock. The author completely misses the point of what CSV files are useful for. They are useful when both ends of the communication understand the context. They know what the data types are, they know what the character encoding is etcetera. This is a very common situation. CSV files are easy to process, easy to generate, and can be read by a human without too much bother (they are not "for people" as the auth…

I don't agree with the author's thesis, but you're wrong.

1. It is a very common use-case to load CSV data generated by an opaque system which did not specify the format exactly to you.

2. CSV files are _difficult_ to process I: Fields are of variable width, which is not specified elsewhere. So you can't start processing different records in parallel, since you have to process previous lines to figure out where they end. You can't even go by some clear line termination pattern, since the quoting and escaping rules, and the inconsistencies the author mentions, make it so that you may not be able to determine with certainty that what you're reading is an actual end-of-record or end-of-field. Maybe it's all just a dream^H^H^H^H^H quoted string?

3. CSV files are _difficult_ to process II: For the same reasons as the above, it is non-trivial and time consuming to recover from CSV generation mistakes, corruptions during transmission, or missing parts of the data.

However - if you get some guarantees and abot field width and about the non-use of field and record separators in quoted strings, then your life becomes much easier.

Re: Time to retire the CSV?

#560

CSV isn't going away any time soon. It is the only format that is supported by all data-oriented tools. Getting all those tools to agree on an alternative isn't going to happen, especially given that that there are all these old tools that are no longer being updated, that produce and consume CSV. Instead of finding a replacement for CSV it might be easier to standardize it and enhance it. Excel's version of CSV is t…

> Excel's version of CSV is the de-facto standard.

If you're working someplace that uses Excel, then maybe. Otherwise, it isn't.

Anyway, if more tools, including Excel, properly implemented RFC4180, we'd at least have something.

Another option is some sort of meta-data file alongside a large CSV describing its format somehow - which, if missing, you have to fall back on RFC4180 or your parser's "try to figure out the quirks" mode.

Post reply on HN