News for hackers. Stuff that matters.
Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @01:48PM (#16996589)
This is just a thought: SQLite is a really good file format. Why aren't we replacing CSV with it, especially for big data applications?

CSV can be difficult and ambiguous to parse correctly (because there's no real standard) and isn't extremely performant. The only thing it has going for it is its universality.

SQLite is lightweight, structured, supports indexing for performance and is extremely easy to use.

Re:We’re happy with SQLite and not urgently interested in a ... by Someone1234 on Friday May 04, 2018 @01:59PM (#16996706)
CSV's biggest competitor is XML.

But both XML and SQLite have the same issue: They give you just enough rope to hang yourself with. While SQLite is a fantastic micro-database engine and a file format, it isn't a very good universal B2B format because there are too many features you'd have to support to interoperate.

I'd argue CSV's biggest strength is that it is easy to parse correctly, because the format is so simple and the standard is largely the superset. The biggest problem for CSV is that the most popular desktop application for view CSV (Microsoft Excel) sucks at it, and causes data corruption on save (and has for at least twenty years).

If people wanted a relational database as a file, I can think of nothing better than SQLite, but in B2B you want automated tooling that can parse the format without human involvement. If you need some structure there are some simpler XML-based formats which accommodate that, but still offer far fewer features you'd have to support than SQLite does.

Ajax might become popular in this space, but I'm yet to see it.

Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @02:10PM (#16996799)
> I'd argue CSV's biggest strength is that it is easy to parse correctly

Not sure I resonate with that. I work with large CSVs of varying provenance every day (I work in big data) and there's always some CSV edge case that stymies my analysis pipeline.

Timestamp parsing is extremely hard if it's not ISO-8601, as well as handling of unicode encoding, missing data, type inference, European usage of , as a decimal point, hidden characters, etc. One of the costs of almost complete freedom in input is the "interesting" possibilities people come up with to stymie your code.

The Pandas read_csv method has tons of switches to deal with all kinds of CSV parsing definitions precisely because there is no standard. Fortunately this covers 80% of the use-cases. https://pandas.pydata.org/pandas-docs/stable/generated/panda...

Excel's CSV parsing isn't the greatest, but does a surprisingly decent job considering how ill-defined CSV is.

XML isn't really on anyone's radar in the big data world. It's an interchange format yes but is hugely inefficient for dataframe-type data.

Re:We’re happy with SQLite and not urgently interested in a ... by Someone1234 on Friday May 04, 2018 @02:21PM (#16996922)
> Excel's CSV parsing isn't the greatest, but does a surprisingly decent job considering how ill-defined CSV is.

No, it really doesn't. Save this as a CSV, open it in Excel, hit save, and then review the raw CSV:

"1000000000012345", "Hello",

"2000000000067890", "World",

Here's what Excel (O365) does to it for me:

1E+15, Hello,

2E+15, World,

That data is now permanently lost. And this corruption occurs for almost all EAN/UPCs. There are many ways to get around this in Excel, but the default experience is data corruption and has been for most of my lifetime. It is a terrible application for CSV. If they followed the standard every column would be what it is: Text.

> XML isn't really on anyone's radar in the big data world.

But is a central theme in the business to business back-end systems world. I'm talking about ordering, invoicing, remittances, hospital records, hospital billing, and so on. No clue what "big data" is, we deal with billions of transactions a year, but that's likely not what you're referring to.

Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @03:57PM (#16997730)
1. I think in the first instance, Excel performs type-inference and coerces it into a numeric type and writes a truncated precision version of numeric fields in CSV, which is an abominable sin. There are workarounds for this [1], but agree this is terrible behavior due to CSV's lack of types.

Arguably, there should have been an explicit Excel switch which forces all CSV data to be parsed as raw strings.

I've seen problems with Excel CSVs that are worse than that: I have serial numbers that have leading 0's that have semantic meaning, like 000002324122323. Most CSV parsers cannot tell that this isn't a numeric type and so handle it wrongly. So I resort to [1].

2. Big data is of course somewhat ambiguous nomenclature as well, but is nowadays typically understood to mean the Hadoop ecosystem or similar. Data is typically ingested into a distributed file system (HDFS, S3, etc.) in formats such as Parquet, Avro, JSON and often CSV. A schema-on-read database like Hive sits on top of this layer and presents a SQL interface to the user. Tools like Apache Spark provide programmatic transformations that operate on the data on the large.

CSV is often promoted as a format for storing structured data due to ease of ingestion and inspection (all you need is a text editor for troubleshooting). However, you pay a performance penalty every time an analytic query is run because CSV doesn't support indexes, predicate pushdowns, compression, etc. and records can sometimes be uninterpretable under certain schemas (in which case they are simply excluded or dropped).

Sometimes having one too many commas in a row can completely mess things up (all the columns get shifted in a record) -- I found this out the hard way when Spark exported malformed CSVs with un-escaped commas.

[1] http://support.pitneybowes.com/SearchArticles/VFP06_Knowledg...

Re:We’re happy with SQLite and not urgently interested in a ... by laumars on Friday May 04, 2018 @05:41PM (#16998608)
sqlite wouldn't solve any of those issues because it's dynamically typed and what you're asking for is something which is strictly typed. In that regard you're better off with a data format like YAML.

I would also disagree that Excel does a good job with CSV. Well, maybe opening files but certainly not saving them as it rewrites values in weird ways. Back when I used to have to handle CSVs regularly (which admittedly was a while ago now) I found OpenOffice Calc to be far superior in terms of CSV support. I'd assume the same is true for LibreOffice Calc but honestly I've not done a huge amount with CSV since.

Re:We’re happy with SQLite and not urgently interested in a ... by infogulch on Friday May 04, 2018 @02:19PM (#16996895)
> CSV's biggest strength is that it is easy to parse correctly

(goes on to say a bunch of applications don't parse it correctly; lets add mssql to the pile)

Re:We’re happy with SQLite and not urgently interested in a ... by Someone1234 on Friday May 04, 2018 @02:24PM (#16996957)
Please review the comment rules here:

https://news.ycombinator.com/newsguidelines.html

Re:We’re happy with SQLite and not urgently interested in a ... by BjoernKW on Friday May 04, 2018 @02:17PM (#16996872)
> that it is easy to parse correctly

While that's not exactly correct - CSV can be quite hard to parse if you want to cover each and every variation and edge case - for all practical intents and purposes that statement is true in my opinion.

CSV is something of a lowest common denominator, a compromise between well-defined, structured data and portability / accessibility.

Re:We’re happy with SQLite and not urgently interested in a ... by libx on Friday May 04, 2018 @08:18PM (#16999474)
CSV could be much easier to parse if people use the ASCII codes meant to be used as field and line separators, thus avoiding having problems with commas.

See https://ronaldduncan.wordpress.com/2009/10/31/text-file-form...

Re:We’re happy with SQLite and not urgently interested in a ... by debaserab2 on Friday May 04, 2018 @02:01PM (#16996720)
I'd actually argue that CSV's biggest competitor specifically is xlsx. Which is kind of XML...
Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @02:15PM (#16996851)
XLSX is actually a decent format for business users. The only trouble is it has tons of limits [1], most restrictive being the limit of 1,048,576 rows by 16,384 columns.

I'm working with a client who had to split up their data into several XLSX files because they hit a row limit.

They can of course ETL the data into a real SQL database, but ETL tools for end users are still not a common thing plus not all end users have access to a SQL database.

[1] https://support.office.com/en-us/article/excel-specification...

Re:We’re happy with SQLite and not urgently interested in a ... by Someone1234 on Friday May 04, 2018 @02:11PM (#16996801)
I'm talking about business to business transactions, as in automated transactions on VANs and similar data interchanges.

The industry doesn't really use XLSX or XLS because they're unreliable to parse without Microsoft's Office libraries which require Windows licenses, and the two formats have a huge amount of overhead compared to XML formats and CSV (which costs money on VANs).

This is a space where plain text files and binary is still king. Formats like EDI are still massive. In many ways CSV and XML are the new kids on the block.

Only end users are sending Excel formatted files (and PDFs) to one another.

Re:We’re happy with SQLite and not urgently interested in a ... by merb on Friday May 04, 2018 @04:46PM (#16998166)
> The industry doesn't really use XLSX or XLS because they're unreliable to parse without Microsoft's Office libraries

XLS yes, however XLSX is just easy to parse if you document only contains simple types. of course with embedded mathml/wordml it gets a little bit wierd.

Re:We’re happy with SQLite and not urgently interested in a ... by chaz6 on Thursday May 10, 2018 @03:29AM (#17037018)
Just as a point of interest, sqlite is behind the geopackage [1] specification, which is a common format for exchanging geospatial data.

[1] https://www.geopackage.org/

Re:We’re happy with SQLite and not urgently interested in a ... by tomtimtall on Friday May 04, 2018 @02:05PM (#16996747)
Your costumer just sent you a slightly malformed cab, there’s a couple of column names that need to change and some of the rows need to be excluded. 10min tops. Vs your consumer just sent you a slightly mallformed sqlite dB... which tables need to be merged with which tables? What values are actually indexes into other tables? What assumptions are there on the id’s of this table compared to this table? 4days and 20 emails later you still haven’t fed the data into your model. csv has problems that are trivial to solve live. SQLite is just way overkill to be handed over from party to party lightly.
Re:We’re happy with SQLite and not urgently interested in a ... by neves on Friday May 04, 2018 @02:29PM (#16997012)
Because it is human readable. I can inspect it without any tool installed. I can grep it. I can awk it. I can understand it.
Re:We’re happy with SQLite and not urgently interested in a ... by simonw on Friday May 04, 2018 @02:33PM (#16997052)
Replacing CSV with SQLite is one of my goals for the combination of https://github.com/simonw/datasette and https://github.com/simonw/csvs-to-sqlite
Re:We’re happy with SQLite and not urgently interested in a ... by benoror on Friday May 04, 2018 @01:57PM (#16996686)
Don't underestimate the ability to see right away CSV contents using Excel/Numbers/Google Spreadsheets.

Non-coders technical users

Re:We’re happy with SQLite and not urgently interested in a ... by noir_lord on Friday May 04, 2018 @02:04PM (#16996738)
I'm a coder and I still find the ability to eyeball a file useful, also csv can be munged about with the shell easily (cut, grep, sed etc) which can be surprisingly useful.
Re:We’re happy with SQLite and not urgently interested in a ... by shabbyrobe on Friday May 04, 2018 @02:11PM (#16996803)
Re:We’re happy with SQLite and not urgently interested in a ... by ams6110 on Friday May 04, 2018 @02:12PM (#16996822)
csv can also be queried by tools like q[1] if sed, grep, etc. are not quite up to the task.

I find this very useful to quickly summarize, filter, reorder/rename columns etc. in csv files.

[1] https://harelba.github.io/q/

Re:We’re happy with SQLite and not urgently interested in a ... by rossdavidh on Friday May 04, 2018 @02:12PM (#16996807)
...or even, in most cases, Notepad.
Re:We’re happy with SQLite and not urgently interested in a ... by pdabbadabba on Friday May 04, 2018 @02:18PM (#16996880)
I agree that SQLite-as-file-format is a great idea. But CSV still has some significant advantages for certain use cases. One big one that I don't think others have mentioned is that CSVs are human readable with any old text editor. That's a big help when working with unfamiliar datasets, debugging, etc.
Re:We’re happy with SQLite and not urgently interested in a ... by consto on Friday May 04, 2018 @01:52PM (#16996635)
Universality is key. Everything reads it, everything writes it, everyone can read or edit it by virtually any piece of software. Compare that with SQLite.
Re:We’re happy with SQLite and not urgently interested in a ... by rhizome on Friday May 04, 2018 @02:18PM (#16996890)
SQLite has no type safety on its fields; CSV is just text. You can create an integer field and save the value "wenc" in a SQLite record without it complaining, something it calls "dynamic typing."
Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @02:27PM (#16996991)
Good point. Type affinity via dynamic typing [1] isn't strong typing. But I think it's still slightly better than CSV's no-typing.

[1] https://www.sqlite.org/faq.html#q3

Re:We’re happy with SQLite and not urgently interested in a ... by diogofranco on Friday May 04, 2018 @02:15PM (#16996847)
> Why aren't we replacing CSV with it, especially for big data applications?

Big data applications tend to use other structured binary formats like parquet and avro, which any big data tool can typically parse.

Re:We’re happy with SQLite and not urgently interested in a ... by AutoEngineer on Friday May 04, 2018 @03:19PM (#16997408)
Speaking for an Engineer unfortunately often data is simple CSV. Parsing this data robustly and visualizing it without scripting is still something that hasn't been solved.

If you have any idea how to do it, I'd be more than glad to hear about it.

Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @05:04PM (#16998319)
You can visualize CSVs easily without scripting: use Tableau or some other BI tool [1] (not free though).

There are free alternatives, but many require programming.

[1] https://www.absentdata.com/tableau-alternatives/

Re:We’re happy with SQLite and not urgently interested in a ... by wenc on Friday May 04, 2018 @02:19PM (#16996893)
Parquet is a great columnar format, and Avro is great for schema evolution. But they're not that easy to work with directly. To this day there isn't a decent Parquet viewer to do adhoc data viewing.

SQLite on the other hand has a lightweight SQL REPL that can be invoked from the command line.

Spark can work with SQLite via JDBC, though obviously it isn't as native as Parquet. Between SQLite and Parquet, I might pick Parquet under most circumstances.

But it seems to me SQLite ought to at least be a better option than CSV for Spark jobs (less work needed to do type inference, predicate pushdowns are trivial, etc.)

Re:We’re happy with SQLite and not urgently interested in a ... by diogofranco on Friday May 04, 2018 @02:47PM (#16997168)
csv is notoriously bad with spark - in fact you couldn't write to csv for the longest time without external libraries like the databricks one, so I don't contest your last point.

SQlite is usually a single file representing a database though, I don't know how it would work with partitioning and stuff, and then how to handle the schema evolving across sqlite files.

Re:We’re happy with SQLite and not urgently interested in a ... by drej on Friday May 04, 2018 @03:15PM (#16997377)
Also, the now native Spaek CSV export doesn’t follow RFC 4180 with default settings, it escapes double quotes with a backlash. So odd.
Re:We’re happy with SQLite and not urgently interested in a ... by bachmeier on Friday May 04, 2018 @01:51PM (#16996622)
> Why aren't we replacing CSV with it, especially in big data applications?

I'm inclined to say we are. R, for instance, includes an embedded sqlite, and it seems to be used a lot.

Related link: https://sqlite.org/appfileformat.html

Re:We’re happy with SQLite and not urgently interested in a ... by megaman22 on Friday May 04, 2018 @04:34PM (#16998062)
Can you open a SQLite database in Excel, without programming skills?

There's your reason.

Re:We’re happy with SQLite and not urgently interested in a ... by JustSomeNobody on Friday May 04, 2018 @01:58PM (#16996699)
> Why aren't we replacing CSV with it, especially in big data applications?

Simple, I can edit this with only a text editor if need be.

Re:We’re happy with SQLite and not urgently interested in a ... by ju-st on Friday May 04, 2018 @01:56PM (#16996676)
I used it. SQLite can even import directly from CSV (as long as you're only have ASCII characters). Joining several CSVs and the first data cleaning steps took a second instead of 30 minutes with pandas.
Re:We’re happy with SQLite and not urgently interested in a ... by pbreit on Friday May 04, 2018 @02:19PM (#16996905)
CSV is fine for tabular data which is by far the biggest use case. When the data gets even slightly more complicated, people are not importing and exporting it all that much.
Re:We’re happy with SQLite and not urgently interested in a ... by hajile on Friday May 04, 2018 @03:08PM (#16997335)
Why aren't we replacing CSV with json? You can express CSV as an array of arrays (with guaranteed semantics) or do something more complex if needed.