We’re happy with SQLite and not urgently interested in a fancier DBMS (2016)
beets.io
beets.io
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.
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
Non-coders technical users
I find this very useful to quickly summarize, filter, reorder/rename columns etc. in csv files.
Simple, I can edit this with only a text editor if need be.
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.
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.
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.
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...
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.
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.
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...
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.
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.
See https://ronaldduncan.wordpress.com/2009/10/31/text-file-form...
(goes on to say a bunch of applications don't parse it correctly; lets add mssql to the pile)
Big data applications tend to use other structured binary formats like parquet and avro, which any big data tool can typically parse.
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.)
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.
If you have any idea how to do it, I'd be more than glad to hear about it.
There are free alternatives, but many require programming.
There's your reason.
- 0h to manage backups ("cp"),
- 0h to manage seeds and tests fixtures ("cp"),
- 0h to configure and secure (void),
- 0h to write the deployment scripts (void),
- 0h monitoring/watchdog jobs (void),
- 1h to rsync for failover ("rsync")
My last projects always spent at least a good 100h to do all of this the right way. Then, if it is not good enough, we'll move to RDS or equivalent.
Do you have multiple servers? How do you handle real-time filesystem sync? If you only have one server, how do you handle its inevitable failure?
Do you loose any data collected between last backup and failure?
(I'm not saying SQLite isn't good, because it's f-ing amazing. I'm just not sold on it as a multi-process, multi-user database.)
(If you have a filesystem capable of atomic snapshots, then you can simply snapshot any database and treat the backup as a single file.)
I'd also be interested in that. Last time I wanted to use Sqlite opening twice the same file for writing either would not succeed or could time out.
That's fine. It was never designed to be a multi-process, multi-user database. Even the authors don't pretend it works in that use case:
Are you aware that's unsafe? To make a safe backup use sqlite3's ".dump" command (or filesystem snapshotting, but I've had bad experiences with that, at least on btrfs).
(Unless you use e.g. the --reflink option of GNU cp, in which case it makes atomic snapshots on filesystems that support it).
{
echo line1
echo line2
} > test.txt
{
read line
echo got "$line"
sleep 2
read line
echo got "$line"
} < test.txt &
# concurrent write
sleep 1;
{
echo line2
echo line1
} > test.txt
wait
This script does a concurrent write while the reader is in the "sleep 2" phase. The output should be got line1
got line1
(given that the sleeps do the expected thing).POSIX might contain something that requires aligned blocks of 512 bytes or so to be read or written atomically. But only if you do that in a single system call, of course.
https://www.sqlite.org/howtocorrupt.html#_backup_or_restore_...
> > 0h to manage backups ("cp")
not if you are on btrfs and use a snapshot (same for xfs or even lvm)
>Beeing coded in a single C file makes it portable as hell.
It's not coded in a single C file...
I wonder if the alleged 5-10% performance gains are compared with usage of LTO.
Read-only workloads, most of which eventually get cached by the webserver, but still. Each visualization ends up pulling a large amount of data (sometimes in the 10 thousands of rows) so the network / serde overhead and the administration costs of an external database server adds up, though things have changed recently so perhaps a revisit is in order.
Where it hurts is: The query optimizer sometimes stumbles and does silly things (e.g. not always very smart about column / index selectivity statistics). The data import takes a long time (compared to e.g. postgres' COPY), so that's another pain point.
How "huge" are they talking about? I built a tool that imports Apache logs into sqlite for quick analysis and that easily handles several million records.
[0]: https://www.quora.com/How-many-music-albums-are-available-in...
My music collection is massive. It's got 30 years of singles and albums in there. And several years of DJing too. Plus a massive amount of DJ sets (like several hundred gig of DJ sets alone). Yet XBMC / Kodi handles it fine "despite" being sqlite backed. So does Subsonic and that just uses some Java equivalent. And as I've said already, I can throw several million records of Apache logs into sqlite without any issue.
The performance of sqlite is actually really good. It's super fast. Which is why the author can make those boasts on its website. Plus the compactness of the db (ie one file produced) and the ease to create a db makes it a perfect choice for desktop and mobile applications.
I think some people read that WordPress runs on MySQL or spend 10 minutes building their first CMS in PostgreSQL and then think the world and their mother should be using this miraculous new RDBMS they've just discovered themselves. (I'm probably being too harsh there)
Of course once your application needs to do multithreaded DB access (especially if writes are involved), then you're far better off ditching SQLite. Then again, this is probably not a very common use case for a typical desktop application.
0 - https://github.com/cretz/yukup/blob/eecb3b24b33f40e6a1eefaa5... 1 - https://github.com/cretz/yukup/tree/eecb3b24b33f40e6a1eefaa5...
It has drawbacks but if accepting several db is an important goal, you don't want to handcraft this unless you can measure inaceptable perfs.
I am admittedly unfamiliar with this specific case, but even a cursory glance showed me some sqlite-specific code embedded in the main library portion [0].
0 - https://github.com/beetbox/beets/blob/4f7c1c9beda6c2a5b0705e...
I know this is kind of a snarky response, but seriously... why? This would take developer resources away from real feature work, introduce boatloads of complexity, add more points of failure, make testing and validation harder and make it harder to reason about the entire system end-to-end. Not that that isn't sometimes necessary, but you need a compelling reason, not just jumping into it because it sounds like a good idea.
Programmers have this strange compulsion to design swappable interfaces even when they're totally unnecessary and more often than not just break everything while– ironically– only one implementation is ever used.
YAGNI.
To allow others to impl the data store they want and to avoid having to write blog posts like these.
It's not that much real work to quickly pull out an iface on a stable system. Assuming it would be just mostly pass-through to your main impl anyways and this is a common approach in refactorization. You don't need some huge system, just drop it back a layer and abstract it.
Often, what you end up learning about your system when you do this minimal work (again, nothing big) is that you screwed up and buried SQL and string concatenation and a bunch of other hard-to-review pieces all throughout your app because you keep a stranglehold on terms like YAGNI when separation of concerns has real value. Sometimes you also end up learning that your tests don't cover what you thought they did. Nobody wants bloat, but this adds very little and helps devs clamoring for alternative stores.
But why?
For the longest time MySQL didn't support window function or CTEs. What do you do if you're using those? (I'm not sure of SQLite's window support, but I'm pretty sure it has CTEs.)
If you're using postgres, should you not use pg_trgm (trigram indexer to use an index for regex searches on text), postgis (GIS tools), pg-routing (routing tools), ossp_uuid (uuid support), better types (boolean, range, inet, geometric, &c), or features such as RETURNING just because someone doesn't like my choice of database? No, I'm going to do what makes my life easier and my application faster and more featureful.
That's not a good enough reason. Those others need to first justify what the specific benefits of switching would be. I have a strong feeling that a lot of these people don't actually know why this change should be made beyond "I heard that SQLite 'isn't a real DB' but I don't know what that means". The customer is not always right; sometimes people making feature requests need to be told "No".
> It's not that much real work to quickly pull out an iface on a stable system
Maybe we've worked on different things, but this has not been my experience. IME, replacing a DBMS is agony, and adding an abstraction layer so you can use multiple DBMS's is agony exponentially magnified. Some of that is due to bad choices you made in the original design, but a lot of it is just because these systems will never behave identically, no matter what promises they make about SQL standards. Don't forget, also, that when you target multiple DBMS's, you're locking yourself into hitting the lowest common denominator of the intersection between their feature sets. You might end up making performance worse because you can no longer use DBMS-specific optimizations!
But this is all immaterial: no matter how much or how little work it is, it's all unnecessary work. If there's no benefit to switching, why do any work at all, especially when it has all the downsides I mentioned above.
> Often, what you end up learning about your system when you do this minimal work (again, nothing big) is that you screwed up and buried SQL and string concatenation and a bunch of other hard-to-review pieces....
I agree! So go through the app and fix those and then see if you still need to swap out the storage layer (which is actually what the author is recommending). Don't just do it because it's faddish before you've even established that it would actually add value.
Let me show you why is insane.
Imagine you work on Java. Do you build a DSL/Transpiler to Java so you MAYBE could change later to C#?
A RDBMS is even more important that the glue code. Why hide it, why think is something "easy" to trow away?
Why think is nut to code most or all the code on it?
Why would I do such a thing? I rarely ever promote abstraction for abstraction's sake and will in almost all cases disagree with premature abstraction. There are levels and for simple CRUD things, a thin contract over your DB is a reasonable tradeoff.
> A RDBMS is even more important that the glue code. Why hide it, why think is something "easy" to trow away?
I don't think you even need glue code. You just need a well-specified contract. You don't want to throw away anything of course.
> Why think is nut to code most or all the code on it?
I don't think that. Often it can be prudent to use plsql/triggers for things. Doesn't mean the frontend of your web app needs to build the SQL in the JS though, right? Just a high level "DoThing" contract with a description of what it should do is fine.
(I think "glue code" in parent referred to "what is not the UI or DB" BTW, i.e. the "Java app".)
When the database is the most fundamental thing, then trying to abstract away the database can be a bit like trying to abstract away the programming language you are using.
I have code where I would much rather rewrite the "backend" in another language than swap out the database.
I think it was a very good analogy to say that abstracting over database is a bit like abstracting over what programming language you are using.
The real wins for us are multithreaded and multiprocess DB I/O. This is something MySQL can handle, but SQLite really isn't designed to do well or efficiently.
I totally wish for a fancier DBMS that can be embebed (firebird fit here!) and work on mobile (but not here yet).
And not only "fancier" in the limited sense that most believe. I truly mean A LOT FANCIER.
Your web page will fail, as it will time out on database lock because of that background process.
* No external services required * Backups, when the application isn't run, is just a copy * Good SQL support
I'm not even sure it's possible to get to the point where SQLite is going to fall over in this context (music collection metadata managment).
SQLite is good enough for pretty much everything, just use it!!!
I don't say it lightly, but you're basically spamming HN, as users have been complaining for a long time (e.g. [1], [2]). Even when you don't appear to be doing it, you're doing it [3]. It's past time for this to stop; please stop.
1. https://news.ycombinator.com/item?id=16893429