Daily Tech Briefing
AI 科技速览

每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。

AI 快讯
Hacker News · 2026/8/4 22:09:43

DuckDB – Data power tools for your laptop, now in Clojure (2023)

AI 中文解读
DuckDB给笔记本电脑装上了数据超能力!这个新版本让Clojure开发者也能用上高性能数据分析工具,最震撼的是,处理50GB的庞大CSV文件只需要不到2分钟,还能将文件压缩到18GB,这速度简直惊人。 以前处理这种量级的数据,需要搭建复杂的服务器集群,就像为了切个菜非要开个中央厨房。而DuckDB就像是给每个程序员配了一把"瑞士军刀",直接在笔记本上就能完成大规模数据处理。它特别聪明的地方在于,能把数据压缩存储并自动建立索引,让查询变得飞快,而这一切都不需要额外的服务器。 这项技术最实在的好处在于,它让数据分析的门槛大大降低了。以前小团队或个人要处理大规模数据,往往需要借助昂贵的企业级工具或云服务,现在只要一台笔记本电脑就够了。这意味着更多的小型创业公司和个人开发者都能轻松挖掘大数据价值,比如分析用户行为、优化业务流程,甚至进行复杂的科学研究。简单来说,DuckDB正在让"大数据"平民化,让每个人都拥有处理海量信息的能力。
Blog HomeContact2023-09-02DuckDB - Data power tools for your laptop, now in ClojureEstablishing the NeedOur in-memory column-major data processing platform, tech.ml.dataset (TMD), drives the future of functional data science. When data gets large enough not to fit in memory, one can continue with TMD by operating on samples of data, or otherwise filtering to relevant subsets to fit in bounds imposed by the working environment. Moreover, one can accomplish persistence, for data small and large, with nippy, arrow, or parquet.When data becomes large enough, for example sets of .csv files on the order of ~100GB with relational aspects to them, the tools in their current state can become unwieldy. One is tempted to get involved in nonfunctional sparky cluster snafus. Of course, maintaining some level of transactional interaction and a simple disk IO model is still super-desirable. Local disks are big enough, and local chips are fast enough, no need to do anything rash.Relational databases are well adapted for out-of-memory storage and fast relational queries - but, how to leverage this without giving up the advantages of functional programming, and TMD's column-major processing model? JDBC, along with Postgres, provide a good first answer to this question, but it's irritating to perform a full row-to-column conversion through an inefficient, non-batched API in order to get the data through JDBC and into TMD.A New Challenger AppearsDuckDB showed up via a github issue in May of 2021 and tmducken was minimally integrated with their C bindings by December of that year. In that version, all query results were returned at once, and so needed to fit in memory. Also, in those early days of DuckDB there was not a specific high performance append or insert system, so IO was limiting potential performance, and Postgres persisted as the adjunct processing system to TMD. Much has changed since then.In the last two years, DuckDB improved a lot. Importantly, the C interface now provides a batched system for both inserts and querying, which enables processing very large joins - more on that later. These improved capabilities can now be leveraged in Clojure, through TMD, to access DuckDB's state of the art vectorized SQL execution engine, and it's good.Actual UseBuilding on our previous post, there is a 50 gigabyte .csv file with 3 years of transaction data, totaling 400,000,000 rows:$ ll -h data.csv -rw-rw-r-- 1 harold harold 50G Aug 8 09:49 data.csv Loading that into DuckDB is surprisingly easy - though, you do have to wait 2 minutes:$ time duckdb data.ddb 'CREATE TABLE data AS FROM "data.csv";' 100% ▕████████████████████████████████████████████████████████████▏ real 1m50.091s user 21m42.693s sys 0m57.887s $ ll -h data.ddb -rw-rw-r-- 1 harold harold 18G Sep 6 10:57 data.ddb So, that reduced the file to 18GB, which includes all of the indexes (!) created automatically by DuckDB.The data is in there:$ duckdb data.ddb v0.8.1 6536a77232 Enter ".help" for usage hints. D SELECT COUNT(*) AS n FROM data; ┌───────────┐ │ n │ │ int64 │ ├───────────┤ │ 400000000 │ └───────────┘ D DESCRIBE TABLE data; ┌────────────────┬─────────────┬─────────┬─────────┬─────────┬─────────┐ │ column_name │ column_type │ null │ key │ default │ extra │ │ varchar │ varchar │ varchar │ varchar │ varchar │ varchar │ ├────────────────┼─────────────┼─────────┼─────────┼─────────┼─────────┤ │ customer-id │ VARCHAR │ YES │ │ │ │ │ day │ BIGINT │ YES │ │ │ │ │ inst │ TIMESTAMP │ YES │ │ │ │ │ month │ BIGINT │ YES │ │ │ │ │ brand │ VARCHAR │ YES │ │ │ │ │ style │ VARCHAR │ YES │ │ │ │ │ sku │ VARCHAR │ YES │ │ │ │ │ year │ BIGINT │ YES │ │
分享
阅读原文