News for hackers. Stuff that matters.
Re:DuckDB – in-process SQL OLAP database management system by nerdponx on Friday February 10, 2023 @12:35PM (#34742880)
* * *
Re:DuckDB – in-process SQL OLAP database management system by corford on Friday February 10, 2023 @12:52PM (#34743079)
This blog post offers a nice summary: https://motherduck.com/blog/six-reasons-duckdb-slaps/
Re:DuckDB – in-process SQL OLAP database management system by nerdponx on Friday February 10, 2023 @01:10PM (#34743346)
The blog post doesn't really make a comparison between DuckDB and data frame libraries. It mentions that the DuckDB Python bindings can interoperate with Pandas, but it doesn't really explain why you would use DuckDB instead of Pandas, or Polars (which is both faster and more portable than Pandas).
Re:DuckDB – in-process SQL OLAP database management system by simonw on Friday February 10, 2023 @05:45PM (#34747037)
Don't Polars and Pandas both require your entire data to fit in memory?
Re:DuckDB – in-process SQL OLAP database management system by nerdponx on Friday February 10, 2023 @06:37PM (#34747577)
* * *
Re:DuckDB – in-process SQL OLAP database management system by jcheng on Friday February 10, 2023 @07:46PM (#34748220)
I think you mean that Pandas does require your entire data to fit in memory? https://pandas.pydata.org/docs/user_guide/scale.html
Re:DuckDB – in-process SQL OLAP database management system by nerdponx on Friday February 10, 2023 @08:14PM (#34748431)
Yes, thank you, that was a typo.
Re:DuckDB – in-process SQL OLAP database management system by corford on Friday February 10, 2023 @09:32PM (#34748986)
Apparently duckdb paired with arrow lets you work performatively on bigger than memory parquet data (I haven't tried this though)
Re:DuckDB – in-process SQL OLAP database management system by riezebos on Saturday February 11, 2023 @03:31AM (#34750618)
Arrow seems to be the common denominator for larger than ram. Polars is completely built on arrow, so the same advantages should apply.

https://github.com/pola-rs/polars#handles-larger-than-ram-da...

Re:DuckDB – in-process SQL OLAP database management system by syntaxfree on Friday February 10, 2023 @12:56PM (#34743135)
It’s a drop in alternative to SQLite that’s column-oriented/OLAP. I’ve been profiling entire projects in production switching between SQLite and duckdb (no clear conclusions yet)
Re:DuckDB – in-process SQL OLAP database management system by nerdponx on Friday February 10, 2023 @01:11PM (#34743366)
I suppose that leads to a broader question: when should you use an in-memory database, and when should you use a data frame library? The distinction between the two seems to be getting blurry (which maybe is a good thing).
Re:DuckDB – in-process SQL OLAP database management system by IanCal on Friday February 10, 2023 @02:43PM (#34744713)
Very blurry. The answer now is just "whichever is easier for the small part of the task right now". Since duckdb happily talks arrow, you can use pandas for part of it, quickly do some SQL where that is easier (with no data copying) then switch back to pandas for something. You don't really have to choose which one to use any more.
Re:DuckDB – in-process SQL OLAP database management system by wenc on Friday February 10, 2023 @06:39PM (#34747598)
* * *
Re:DuckDB – in-process SQL OLAP database management system by benjaminwootton on Friday February 10, 2023 @04:23PM (#34746054)
SQL is easier and more natural to work with than Pandas.
Re:DuckDB – in-process SQL OLAP database management system by nojito on Friday February 10, 2023 @11:34PM (#34749620)
How would you do df.T in sql?
Re:DuckDB – in-process SQL OLAP database management system by wenc on Saturday February 11, 2023 @03:33AM (#34750631)
df.T is a special Pandas dataframe transpose on the dataframe index and the columns.

DuckDB produces Pandas dataframes, so you would just do df.T. No need to choose between one the other.

But to answer your original question, the SQL analogue to a transpose are PIVOT/UNPIVOT operations which are mathematically rotation operations on invariants (your dimensions). This makes them much more general than a transpose -- which are just rotation operations on the rows/cols. PIVOT/UNPIVOT work on non-square data and allow you to specify different types of aggregations. PIVOT/UNPIVOT keywords are not yet implemented in DuckDB but are on the roadmap if I'm not mistaken.

Re:DuckDB – in-process SQL OLAP database management system by nojito on Sunday February 12, 2023 @07:23PM (#34768676)
>DuckDB produces Pandas dataframes, so you would just do df.T. No need to choose between one the other.

Transforming into a pandas df isn't zero copy.

UNPIVOT and PIVOT are quite verbose compared to df.T.

Re:DuckDB – in-process SQL OLAP database management system by brahbrah on Monday February 13, 2023 @09:35AM (#34773853)
Sometimes yes and sometimes no. For example if you had price data and you wanted to bump prices up a dollar in 2020 how would you do that in sql?

In pandas it’s:

    prices_df.loc['2020'] += 1
If you had a temperature forecast and you wanted to add the expected temperature miss to them, how would you do that on sql?

In pandas it’s:

    temps_df + expected_miss_df
Re:DuckDB – in-process SQL OLAP database management system by brahbrah on Monday February 13, 2023 @08:23AM (#34773050)
Pandas is in a separate category from all of these, including polars. If you were to say “pandas in long format only” then yes that would be correct, but the power of pandas comes in its ability to work in a long relational or wide ndarray style. Pandas was originally written to replace excel in financial/econometric modeling, not as a replacement for sql. Models written solely in the long relational style are near unmaintainable for constantly evolving models with hundreds of data sources and thousands of interactions being developed and tuned by teams of analysts and engineers.

For example, this is how some basic operations would look in pandas.

Bump prices in 2020 up $1:

    prices_df.loc['2020'] += 1
Add expected temperature offsets to base temperature forecast:

    temp_df + offset_df
Now imagine thousands of such operations, and you can see the necessity of pandas in models like this.