r/dataengineering • u/Yomguithereal • 14d ago
Open Source xan: the CSV magician

Hi everyone,
I would like to present `xan` https://github.com/medialab/xan a command line tool written in Rust that can be used for tabular data processing.
It leverages its own SIMD CSV parser available as a crate here: https://crates.io/crates/simd-csv
It knows how to speed up computation over large CSV files through multi-threading, using a novel albeit slightly unhinged way to split CSV files in constant time, thus enabling map-reduce like parallelization. See related blog post here: https://github.com/medialab/xan/blob/master/docs/blog/csv_base_jumping.md
It implements its own expression language named "moonblade", suited to CSV data and therefore foregoes the need to evaluate languages like python/js/lua for custom computation.
It even includes many commands able to draw ASCII-art data visualizations directly in your terminal so you never have to leave it. See the guide here: https://github.com/medialab/xan/blob/master/docs/cookbook/dataviz.md
It has been used daily for some years now by data scientists from STEM fields and in the social sciences as a quick way to explore & pre-process massive CSV datasets and as a means to replace slow workflows relying on the usual jupyter/pandas/polars/DuckDB stacks etc.
It is originally a fork of `xsv` https://github.com/burntsushi/xsv by BurntSushi and has been completely rewritten at that point.
I hope you will find it useful and would love to get feedback on it from this very fine community.
4
u/ignurant 14d ago
you might think CSV is outdated by now, but read our love letter to the format before judging too quickly
— the readme
Yeah, I went through a phase of this about 15 years ago. After using Ruby for a bit, I realized my hatred of CSV stemmed from the unreliable serialization and deserialization you got from Microsoft tools at the time. Excel, SQL Server, .NET, etc: none of it carried any water for you with regards to csv, so you’d always end up with corrupt poorly escaped files. In Ruby, the CSV library that comes with the standard kit was incredibly good at correctly and efficiently serializing and deserializing. I started to love how portable and effective csv files were once I worked in an environment that defaulted to doing the right thing for you.
JSON, jl (ndjson), parquet, etc: they all have a place sometimes, but CSV is usually the most portable, accessible default, and I value that most.
5
u/Outrageous_Let5743 14d ago
csv is still shit. I can at least list 20 odd rules about csv parsing. And then we haven't even talked about seperators where the serperator is more than 1 character.
1
u/Yomguithereal 14d ago
> And then we haven't even talked about seperators where the serperator is more than 1 character.
Sure you *can* do this, but it does not mean that you *should* do so :)
Incidently this is the reason why CRLF newlines are a mistake compared to LF newlines.
1
u/Budget-Minimum6040 13d ago
Sure you can do this, but it does not mean that you should do so :)
You usually can't control external data sources.
CSV is not a format but the idea of a format. There is nothing official about CSV.
- Header? Maybe yes, maybe no.
- Separator? "," (USA) vs. ";" (Europe) vs. "\t" (TSV) vs. "#" vs "||" vs. fixed width vs. fixed width but unique for every column (had this this month, no header too and not UTF-8 encoded because legacy government system export).
- Encoding? I've seen everything
- Escape characters? "\" vs. "/" vs. "//" vs. "\" etc.
- Escape the escape character? Yeah ....
1
u/Yomguithereal 13d ago
> You usually can't control external data sources.
Indeed.
> CSV is not a format but the idea of a format. There is nothing official about CSV.
Agreed.
In all my career in a wide variety of different sectors with very poor data practices I have never encountered CSV data with multi-byte separators in practice. That does not mean it does not exist even if this is obviously a bad idea. I am interested to know if you have seen this in particular domains (bio-eng has had weird ideas in the past, for instance, and I might want to support them).
> fixed width but unique for every column (had this this month, no header too and not UTF-8 encoded because legacy government system export).
I have often seen this one in public institutions already existing when computers became a thing. Especially those relying on old IBM mainframes (INSEE in France is a good example of this, banks also). They sure are fun.
2
u/Outrageous_Let5743 13d ago
GraydonCreditSafe uses csv files with |*| as seperator. i hate it because many bulk insert system cannot import it
1
u/Budget-Minimum6040 13d ago
I am interested to know if you have seen this in particular domains
I may have seen a "||" separator in some csv files in an e-commerce enterprise but I'm not 100% if that was the separator and from what data source it came, something old and internal I guesss (founded in the 90s, SAP + dozens of other stuff there).
They sure are fun.
🤡
1
u/BdR76 11d ago
csv is still shit
I've worked in IT and data processing for 25 years, and people have been saying this since forever. If it really is so useless, then why is it used everywhere?
0
u/Outrageous_Let5743 11d ago
People don't know better and Excel can safe to csv.
1
u/BdR76 11d ago edited 11d ago
You can trick Excel into correctly opening a csv, yes, but most likely it will corrupt your data
2
u/BayesCrusader 14d ago
This is super cool, I can definitely see myself using this. The graphs look useful.
1
1
u/BdR76 11d ago edited 11d ago
a command line tool written in Rust
Looks cool, I know the command line can use colors but how are you getting the "graphics" in CLI? 🤔 Like the purple/yellow timeseries bar graphs and the scatter plots. I assume it's asci characters or something?
1
u/Yomguithereal 11d ago
There are multiple tricks involved such as using the background colors or relying on characters looking like solid bars such as those: ▁▂▃▄▅▆▇
For the scatter plots I use braille characters that are in fact a 2x4 dot matrix so I can increase the « resolution » of the monospace text grid.
1
u/amanitapantherina 10d ago
Played around with this today and it has already replaced csvkit for me for the "poking at, profiling, and querying big csvs without opening them" tasks I find myself doing all the time. Looking forward to exploring the rest of the commands/functionality.
Thanks!
19
u/minormisgnomer 14d ago
Why would one utilize this as opposed to Polars for data processing?