- 1
- In memory
- 2
- or persisted to disk
How DuckDB transformed my data science workflow
Exploratory data analysis (EDA) is essential in the data science workflow. As a data scientist, and the necessity arises, I need a tool capable of effectively facing various challenges:
- Collect: preparing datasets from diverse sources (flat files: CSV, JSON, Parquet; databases: MySQL, Postgres; cloud storage: GCS, S3).
- Transform: filtering, aggregating, sorting data, joining multiple tables, pivot table and creating views to simplify complex queries.
- Fast and Memory-Efficient: analytic workflow takes time; save your time and money.
- Rich-Features: supports advanced datatypes such as array, list, map, struct, geometry (for geography information systems) and full text search.
- Easy to integrate: supports popular programming languages like Python, R, Java, Rust, Typescript/Javascript, and Julia. Integrating different Python libraries (Pandas, Arrow and Polars; stored in variables and can be queried with SQL), is a good idea.
DuckDB is an open-source database that provides these functionalities with efficiency, reliability, and ease of use.
For more technical details, you can visit the link: Why DuckDB
Source code (python only) of this post you can find at GitHub: quangtiencs/duckdb-tutorial.
1. Multiple sources and easy to integrate
DuckDB supports two types of connection:
- In memory: data is not persisted to disk. Suitable for ad hoc queries.
- Persisted to disk: given a file, all tables, indexes, constraints, views, etc., will be stored in a single file.
DuckDB quickly loads data from diverse sources without boilerplate code. Without configuration, DuckDB auto-detects types and dialects (for some data sources, e.g. csv, json).
┌─────────────┬──────────┬────────┬───────────┬─────────────────────────────────────────────┬─────────┬────────┬───────┬───────┬──────────────────┬─────────┬─────────┬──────────┐
│ PassengerId │ Survived │ Pclass │ Lname │ Name │ Sex │ Age │ SibSp │ Parch │ Ticket │ Fare │ Cabin │ Embarked │
│ int64 │ int64 │ int64 │ varchar │ varchar │ varchar │ double │ int64 │ int64 │ varchar │ double │ varchar │ varchar │
├─────────────┼──────────┼────────┼───────────┼─────────────────────────────────────────────┼─────────┼────────┼───────┼───────┼──────────────────┼─────────┼─────────┼──────────┤
│ 1 │ 0 │ 3 │ Braund │ Mr. Owen Harris │ male │ 22.0 │ 1 │ 0 │ A/5 21171 │ 7.25 │ NULL │ S │
│ 2 │ 1 │ 1 │ Cumings │ Mrs. John Bradley (Florence Briggs Thayer) │ female │ 38.0 │ 1 │ 0 │ PC 17599 │ 71.2833 │ C85 │ C │
│ 3 │ 1 │ 3 │ Heikkinen │ Miss. Laina │ female │ 26.0 │ 0 │ 0 │ STON/O2. 3101282 │ 7.925 │ NULL │ S │
│ 4 │ 1 │ 1 │ Futrelle │ Mrs. Jacques Heath (Lily May Peel) │ female │ 35.0 │ 1 │ 0 │ 113803 │ 53.1 │ C123 │ S │
│ 5 │ 0 │ 3 │ Allen │ Mr. William Henry │ male │ 35.0 │ 0 │ 0 │ 373450 │ 8.05 │ NULL │ S │
│ 6 │ 0 │ 3 │ Moran │ Mr. James │ male │ NULL │ 0 │ 0 │ 330877 │ 8.4583 │ NULL │ Q │
│ 7 │ 0 │ 1 │ McCarthy │ Mr. Timothy J │ male │ 54.0 │ 0 │ 0 │ 17463 │ 51.8625 │ E46 │ S │
└─────────────┴──────────┴────────┴───────────┴─────────────────────────────────────────────┴─────────┴────────┴───────┴───────┴──────────────────┴─────────┴─────────┴──────────┘
We can easily convert query_result object to pandas dataframe by:
And more…
- Load from MySQL or PostgreSQL
- Load from remote files: httpfs
- Load from Google Cloud Storage
2. Simplified Pivot Statement
Pivot statement helps us reorganize data in a table that allows we to create a new table with new columns based on distinct values (in the original table).
DuckDB supports SQL Standard PIVOT syntax and Simplified PIVOT syntax. Simplified PIVOT syntax is more intuitive. Try it!
For example, if we want to convert gender to new columns and count survived classes of each gender.
+----+------------+----------+--------+
| | Survived | female | male |
|----+------------+----------+--------|
| 0 | 0 | 16 | 86 |
| 1 | 1 | 40 | 14 |
+----+------------+----------+--------+
3. Join syntax is less messy compared with Pandas dataframe
Joining two tables is a common task in data analysis. Although Pandas pd.merge API worked well, the problem is when you have multiple tables (data frame), it becomes verbose.
Consider this example (adapt from pandas documentation):
import pandas as pd
left_df = pd.DataFrame(
{
"key": ["K0", "K1", "K2", "K3"],
"A": ["A0", "A1", "A2", "A3"],
"B": ["B0", "B1", "B2", "B3"],
}
)
print(left_df.to_markdown(tablefmt='psql'))
right_df = pd.DataFrame(
{
"key": ["K0", "K1", "K2", "K3"],
"C": ["C0", "C1", "C2", "C3"],
"D": ["D0", "D1", "D2", "D3"],
}
)
print(right_df.to_markdown(tablefmt='psql'))
pandas_join_result = pd.merge(left_df, right_df, on="key")
print(pandas_join_result.to_markdown(tablefmt='psql'))+----+-------+-----+-----+
| | key | A | B |
|----+-------+-----+-----|
| 0 | K0 | A0 | B0 |
| 1 | K1 | A1 | B1 |
| 2 | K2 | A2 | B2 |
| 3 | K3 | A3 | B3 |
+----+-------+-----+-----+
+----+-------+-----+-----+
| | key | C | D |
|----+-------+-----+-----|
| 0 | K0 | C0 | D0 |
| 1 | K1 | C1 | D1 |
| 2 | K2 | C2 | D2 |
| 3 | K3 | C3 | D3 |
+----+-------+-----+-----+
+----+-------+-----+-----+-----+-----+
| | key | A | B | C | D |
|----+-------+-----+-----+-----+-----|
| 0 | K0 | A0 | B0 | C0 | D0 |
| 1 | K1 | A1 | B1 | C1 | D1 |
| 2 | K2 | A2 | B2 | C2 | D2 |
| 3 | K3 | A3 | B3 | C3 | D3 |
+----+-------+-----+-----+-----+-----+
Sometimes, condition joining needs preprocessing in columns; in this case, we can create a temporary column by Pandas .apply (on pd.Series). It also leads to verbose code.
DuckDB Join Statement is more concise. Luckily, we can access Pandas pd.DataFrames objects as DuckDB tables!
+----+-------+-----+-----+---------+-----+-----+
| | key | A | B | key_1 | C | D |
|----+-------+-----+-----+---------+-----+-----|
| 0 | K0 | A0 | B0 | K0 | C0 | D0 |
| 1 | K1 | A1 | B1 | K1 | C1 | D1 |
| 2 | K2 | A2 | B2 | K2 | C2 | D2 |
| 3 | K3 | A3 | B3 | K3 | C3 | D3 |
+----+-------+-----+-----+---------+-----+-----+
4. Geospatial analytics
DuckDB provides spatial data management and analysis capabilities (through extension). It allows users to store and manipulate geographic data, including points, lines, and polygons, and perform spatial queries.
DuckDB supports over 50 different formats. We can quickly load the Singapore Map (in GeoJSON format):
┌───────────┬────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ COUNTRY │ NAME_1 │ geom │
│ varchar │ varchar │ geometry │
├───────────┼────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Singapore │ Central │ MULTIPOLYGON (((103.8478 1.2222, 103.8489 1.2231, 103.8517 1.2203, 103.8504 1.2141, 103.8432 1.2216, 103.8452 1.2235, 103.8478 1.2222)), ((103.8604 1.2243, 103.862 1.224, 103.8622 1.2218, 103.8569 1.225, 103.8589 1.2261, 103.8604 1.2243)), ((103.8516 1.2303, 103.858 1.2323, 103.8577 1.2298, 103.8538 1.2291, 103.8533 1.2266, 103.8556 1.2259, 103.8582 1.2217, 103.8568 1.2179, 103.8528 1.2217, 103.8516 1.2267, 103.8494 1.2286, 103.8468 1.2268, 103.8492 1.2294, 103.8457 1.2321, 103.8516 1.2303)), ((103.8365 1.2318, 103.8374 1.2325, 103.8397 1.2287, 103.8394 1.2285, 103.8365 1.2318)), ((103.8339 1.2128, 103.8344 1.2155, 103.8358 1.2156, 103.8361 1.2141, 103.8339 1.2128)), ((103.8319 1.2156, 103.8322 1.2169, 103.8336 1.2169, 103.8333 1.215, 103.8319 1.2156)), ((103.8108 1.2592, 103.8183 1.2589, 103.8275 1.2542, 103.8367 1.2532, 103.8381 1.2544, 103.842 1.2537, 103.8419 1.2522, 103.8464 1.2532, 103.8484 1.2519, 103.8429 1.2431, 103.8328 1.2372, 103.825 1.2433, 103.8225 1.2478, 103.8069 1.2589, 103.8108 1.2592)), ((103.8406 1.2606, 103.8425 1.2572, 103.8364 1.2544, 103.8269 1.2567, 103.825 1.26, 103.8311 1.2644, 103.8367 1.2644, 103.8406 1.2606)), ((103.8114 1.2626, 103.8117 1.2647, 103.8136 1.2633, 103.8131 1.2625, 103.8114 1.2626)), ((103.8972 1.3368, 103.9055 1.3285, 103.9051 1.3176, 103.91 1.3055, 103.9183 1.3075, 103.9194 1.3022, 103.8933 1.2932, 103.875 1.2814, 103.8697 1.2869, 103.8664 1.2939, 103.8666 1.2976, 103.8722 1.2994, 103.8717 1.3028, 103.8692 1.3039, 103.8644 1.2989, 103.8633 1.2964, 103.8644 1.2897, 103.8622 1.2892, 103.8616 1.287, 103.8675 1.2833, 103.8714 1.2775, 103.86 1.2688, 103.8531 1.2733, 103.8527 1.2618, 103.8514 1.2601, 103.8481 1.2633, 103.8456 1.2603, 103.8383 1.2672, 103.8319 1.2667, 103.8258 1.2628, 103.82 1.2619, 103.8118 1.2665, 103.8043 1.2634, 103.7986 1.2681, 103.7931 1.2697, 103.7783 1.2789, 103.7722 1.2678, 103.7522 1.28, 103.7538 1.2845, 103.7582 1.2829, 103.7569 1.2844, 103.758 1.2848, 103.7603 1.2825, 103.7637 1.2837, 103.7655 1.281, 103.7698 1.2806, 103.7706 1.2822, 103.7697 1.2844, 103.7606 1.2908, 103.7603 1.2939, 103.7622 1.2958, 103.7584 1.2991, 103.7623 1.3013, 103.7667 1.2922, 103.7691 1.2939, 103.7723 1.3121, 103.7709 1.3213, 103.7756 1.3264, 103.7648 1.3324, 103.7656 1.3358, 103.7642 1.3392, 103.7651 1.3421, 103.7671 1.3428, 103.7632 1.3467, 103.7704 1.349, 103.7778 1.3419, 103.7874 1.3447, 103.7883 1.3457, 103.7862 1.3486, 103.7877 1.3494, 103.7894 1.348, 103.7951 1.3493, 103.8042 1.3414, 103.8099 1.3417, 103.8186 1.3358, 103.8201 1.3392, 103.8232 1.3407, 103.8339 1.3406, 103.8371 1.3435, 103.8368 1.3464, 103.8338 1.3496, 103.8267 1.3542, 103.8235 1.3523, 103.8185 1.3549, 103.8207 1.3612, 103.8243 1.3618, 103.8251 1.3635, 103.8271 1.3627, 103.8283 1.368, 103.83 1.3679, 103.8476 1.3636, 103.8519 1.3607, 103.8569 1.3555, 103.8604 1.3434, 103.8651 1.3443, 103.8696 1.3427, 103.8773 1.3443, 103.8851 1.3409, 103.8889 1.3336, 103.8962 1.3378, 103.8972 1.3368))) │
│ Singapore │ East │ MULTIPOLYGON (((104.0242 1.3656, 104.0386 1.3569, 104.0364 1.3533, 104.0333 1.3536, 104.0317 1.3586, 104.03 1.3572, 104.0267 1.3586, 104.0291 1.3557, 104.0288 1.3505, 104.0259 1.3481, 104.0253 1.345, 104.0183 1.3478, 104.0139 1.3447, 104.0158 1.3525, 104.0147 1.3536, 104.0106 1.3422, 104.0081 1.3403, 104.0081 1.3375, 104.0036 1.3306, 104.0022 1.3336, 104.0042 1.3378, 104.0028 1.3392, 104.0106 1.3556, 104.0086 1.3575, 104.0094 1.3606, 104.0136 1.3653, 104.0106 1.3578, 104.0125 1.3569, 104.0142 1.3589, 104.0167 1.355, 104.0203 1.3628, 104.0242 1.3656)), ((103.9194 1.3024, 103.9183 1.3075, 103.91 1.3055, 103.9051 1.3176, 103.9055 1.3285, 103.8962 1.3378, 103.899 1.3428, 103.8984 1.3474, 103.8962 1.3468, 103.8935 1.3488, 103.8957 1.354, 103.8972 1.3536, 103.8985 1.3562, 103.902 1.3572, 103.91 1.3759, 103.9175 1.3824, 103.9143 1.3859, 103.9169 1.391, 103.9251 1.3978, 103.9311 1.3997, 103.9349 1.3979, 103.9377 1.3904, 103.9459 1.3847, 103.9508 1.3825, 103.9602 1.3814, 103.9674 1.3816, 103.9653 1.3828, 103.9656 1.3856, 103.9698 1.3856, 103.9758 1.3928, 103.9878 1.3928, 103.9958 1.39, 103.9997 1.3911, 104.0045 1.3772, 104.0083 1.3731, 104.0064 1.3711, 104.0064 1.3653, 103.9987 1.3502, 103.9908 1.329, 103.9961 1.3258, 103.9944 1.3233, 103.9981 1.3211, 104.0139 1.3242, 104.0322 1.3253, 104.0328 1.3211, 104.035 1.3192, 104.0328 1.3156, 104.0336 1.31, 104.0322 1.3097, 104.0311 1.3131, 104.0269 1.3167, 104.0283 1.3181, 104.0269 1.3197, 104.0228 1.3186, 104.0239 1.3128, 104.0275 1.3111, 104.0264 1.3092, 104.0225 1.3114, 104.0217 1.315, 104.0117 1.3156, 104.0006 1.31, 103.9908 1.3139, 103.9881 1.3114, 103.9833 1.3167, 103.9775 1.3152, 103.9734 1.3164, 103.9614 1.3139, 103.9558 1.311, 103.9474 1.3104, 103.9339 1.305, 103.9194 1.3024))) │
│ Singapore │ North │ MULTIPOLYGON (((103.8282 1.3665, 103.8271 1.3627, 103.8251 1.3635, 103.8243 1.3618, 103.8207 1.3612, 103.8185 1.3549, 103.8235 1.3523, 103.8267 1.3542, 103.8338 1.3496, 103.8368 1.3464, 103.8371 1.3435, 103.8343 1.3408, 103.8232 1.3407, 103.8204 1.3395, 103.8181 1.3359, 103.8099 1.3417, 103.8042 1.3414, 103.7964 1.3489, 103.7917 1.3493, 103.7806 1.3611, 103.7744 1.3903, 103.765 1.3908, 103.7533 1.389, 103.7525 1.4038, 103.7441 1.4061, 103.7419 1.4083, 103.7421 1.4139, 103.74 1.4204, 103.7466 1.4289, 103.7428 1.4397, 103.7446 1.4404, 103.7503 1.4372, 103.7545 1.4388, 103.7617 1.4387, 103.7695 1.4492, 103.7828 1.4556, 103.7961 1.4667, 103.8061 1.4706, 103.8203 1.4701, 103.8225 1.4682, 103.8191 1.4659, 103.8189 1.4636, 103.8221 1.4666, 103.8249 1.466, 103.8289 1.4714, 103.8311 1.4694, 103.8306 1.4675, 103.8505 1.4556, 103.8511 1.4509, 103.8461 1.4487, 103.8544 1.4486, 103.8563 1.4436, 103.8528 1.4392, 103.8574 1.4415, 103.8622 1.4358, 103.8625 1.433, 103.8478 1.4097, 103.8436 1.4075, 103.8328 1.4102, 103.8297 1.4083, 103.8281 1.404, 103.8289 1.4031, 103.8314 1.4058, 103.835 1.4065, 103.8349 1.3987, 103.8392 1.3979, 103.8419 1.4016, 103.8444 1.401, 103.8454 1.4036, 103.8577 1.4134, 103.8611 1.4182, 103.8616 1.4113, 103.8551 1.4049, 103.8555 1.3997, 103.8519 1.3969, 103.8427 1.3964, 103.8274 1.3929, 103.8188 1.3943, 103.8184 1.3886, 103.8167 1.3869, 103.8194 1.3854, 103.8178 1.3803, 103.8273 1.3791, 103.8263 1.3735, 103.8279 1.3721, 103.8282 1.3665)), ((103.7392 1.426, 103.7398 1.4252, 103.7375 1.4233, 103.7379 1.427, 103.7392 1.426)), ((103.7098 1.4126, 103.705 1.4125, 103.701 1.4168, 103.7016 1.4181, 103.6987 1.4187, 103.7001 1.4232, 103.6971 1.4242, 103.695 1.4315, 103.6916 1.4336, 103.696 1.4354, 103.7072 1.4465, 103.714 1.45, 103.7253 1.4514, 103.7306 1.4497, 103.7385 1.4394, 103.7363 1.4309, 103.7382 1.4296, 103.7355 1.4208, 103.7296 1.4151, 103.7232 1.4123, 103.7192 1.4122, 103.715 1.4147, 103.7098 1.4126)), ((103.8644 1.4378, 103.8598 1.4436, 103.86 1.4461, 103.8569 1.4503, 103.8594 1.4497, 103.8656 1.4417, 103.8661 1.4381, 103.8644 1.4378))) │
│ Singapore │ North-East │ MULTIPOLYGON (((103.8959 1.3374, 103.8889 1.3336, 103.8851 1.3409, 103.8773 1.3443, 103.8696 1.3427, 103.8651 1.3443, 103.8604 1.3434, 103.8569 1.3555, 103.8519 1.3607, 103.8465 1.3639, 103.8283 1.3675, 103.8278 1.3723, 103.8263 1.3735, 103.8273 1.3791, 103.8178 1.3802, 103.8194 1.3854, 103.8167 1.3869, 103.8184 1.3886, 103.8188 1.3943, 103.8274 1.3929, 103.8524 1.3971, 103.8556 1.3999, 103.8551 1.4049, 103.8613 1.4105, 103.8611 1.4182, 103.863 1.423, 103.8658 1.4247, 103.8719 1.4239, 103.8758 1.4187, 103.8802 1.4159, 103.8807 1.4124, 103.881 1.416, 103.8829 1.417, 103.8941 1.4137, 103.8941 1.4101, 103.8869 1.4042, 103.8869 1.4019, 103.8956 1.4064, 103.8944 1.4078, 103.8985 1.4174, 103.9083 1.4214, 103.9129 1.4215, 103.9131 1.4107, 103.9214 1.4008, 103.9143 1.3859, 103.9175 1.3824, 103.91 1.3759, 103.902 1.3572, 103.8985 1.3562, 103.8972 1.3536, 103.8957 1.354, 103.8935 1.3488, 103.8962 1.3468, 103.8984 1.3474, 103.899 1.3451, 103.8959 1.3374)), ((103.9216 1.4136, 103.9298 1.405, 103.9299 1.4024, 103.9263 1.4055, 103.924 1.405, 103.9235 1.4075, 103.9157 1.4159, 103.9216 1.4136)), ((103.89 1.4247, 103.8981 1.4186, 103.8947 1.4144, 103.8839 1.4181, 103.8885 1.4249, 103.89 1.4247)), ((103.8816 1.4177, 103.879 1.4183, 103.87 1.4255, 103.8706 1.429, 103.8743 1.4316, 103.879 1.4316, 103.888 1.4258, 103.8816 1.4177)), ((103.9531 1.3997, 103.9472 1.405, 103.9453 1.4078, 103.9478 1.4072, 103.9542 1.3992, 103.9531 1.3997)), ((104.0592 1.4315, 104.0718 1.43, 104.0796 1.4239, 104.0836 1.4193, 104.0851 1.4152, 104.0833 1.4148, 104.0836 1.4135, 104.0858 1.4101, 104.083 1.4077, 104.083 1.4016, 104.0794 1.3913, 104.0761 1.3899, 104.0702 1.3913, 104.0574 1.3857, 104.0556 1.3818, 104.0503 1.3807, 104.0406 1.3932, 104.0414 1.3955, 104.038 1.396, 104.0366 1.4013, 104.0283 1.4071, 104.0311 1.4134, 104.0279 1.4128, 104.0278 1.4156, 104.0312 1.4157, 104.0286 1.4249, 104.0303 1.426, 104.0377 1.4252, 104.0417 1.4277, 104.0425 1.4302, 104.0522 1.4297, 104.055 1.4318, 104.0592 1.4315)), ((103.9381 1.4265, 103.9543 1.4203, 103.9528 1.4193, 103.9548 1.4175, 103.9694 1.4196, 103.9779 1.4178, 103.9897 1.4182, 103.9919 1.4154, 103.9903 1.4113, 103.9919 1.4082, 103.9842 1.4068, 103.9781 1.4079, 103.9739 1.4063, 103.9739 1.404, 103.9711 1.4021, 103.9578 1.3999, 103.9522 1.4068, 103.9522 1.4104, 103.9508 1.4104, 103.9494 1.4071, 103.9483 1.4099, 103.9392 1.4146, 103.9411 1.4179, 103.9378 1.4151, 103.9353 1.4151, 103.9339 1.4182, 103.9303 1.4174, 103.9258 1.4226, 103.9333 1.4279, 103.9372 1.4282, 103.9381 1.4265)), ((104.0219 1.4211, 104.0258 1.4189, 104.0269 1.4142, 104.025 1.4122, 104.0211 1.4122, 104.0167 1.4158, 104.0186 1.4231, 104.0219 1.4211))) │
│ Singapore │ West │ MULTIPOLYGON (((103.7346 1.175, 103.7419 1.1742, 103.7389 1.1664, 103.7336 1.1669, 103.7311 1.1719, 103.7281 1.1731, 103.7322 1.1761, 103.7346 1.175)), ((103.7644 1.2108, 103.77 1.2086, 103.7792 1.2119, 103.7816 1.2082, 103.7814 1.2, 103.7758 1.1967, 103.7756 1.1933, 103.7697 1.1886, 103.7653 1.1903, 103.7717 1.1911, 103.7742 1.1942, 103.7736 1.1972, 103.7661 1.2017, 103.7608 1.1969, 103.7639 1.1914, 103.7592 1.1958, 103.76 1.1983, 103.7575 1.2047, 103.7583 1.2164, 103.7592 1.2172, 103.7622 1.2111, 103.7644 1.2108)), ((103.7961 1.2089, 103.8022 1.2031, 103.8012 1.2007, 103.7922 1.2042, 103.7912 1.2079, 103.7925 1.2108, 103.7944 1.2111, 103.7961 1.2089)), ((103.7483 1.2233, 103.7475 1.2258, 103.7503 1.2258, 103.7497 1.2228, 103.7483 1.2233)), ((103.7287 1.191, 103.7317 1.1875, 103.7289 1.1867, 103.7275 1.1833, 103.7191 1.1803, 103.7164 1.1872, 103.7214 1.1872, 103.7233 1.1914, 103.7287 1.191)), ((103.7244 1.2106, 103.7294 1.2114, 103.7302 1.2095, 103.7281 1.2081, 103.732 1.2066, 103.7336 1.2032, 103.7165 1.2022, 103.707 1.2046, 103.7139 1.2114, 103.7225 1.2139, 103.7244 1.2106)), ((103.7097 1.2925, 103.7111 1.2914, 103.7119 1.2928, 103.7144 1.2903, 103.7233 1.2903, 103.7281 1.2828, 103.7331 1.2786, 103.7352 1.2787, 103.7397 1.2744, 103.7397 1.2725, 103.7356 1.2681, 103.7261 1.271, 103.7251 1.2689, 103.7266 1.2678, 103.7263 1.2652, 103.7218 1.2605, 103.7123 1.2649, 103.7092 1.2692, 103.7067 1.2686, 103.705 1.2658, 103.7078 1.2611, 103.7131 1.2594, 103.7144 1.2544, 103.7092 1.2558, 103.7036 1.2517, 103.6989 1.2508, 103.6953 1.2519, 103.6928 1.2575, 103.6928 1.2647, 103.6914 1.2653, 103.6897 1.2633, 103.6855 1.267, 103.6801 1.2621, 103.6834 1.258, 103.6773 1.247, 103.6801 1.2446, 103.6858 1.2535, 103.6907 1.2405, 103.6785 1.2291, 103.6769 1.2328, 103.6793 1.2421, 103.676 1.2446, 103.6736 1.2426, 103.6642 1.2487, 103.6667 1.2507, 103.6561 1.2698, 103.6834 1.289, 103.6878 1.2914, 103.6917 1.2908, 103.6933 1.2939, 103.6944 1.2931, 103.6906 1.2873, 103.6908 1.2846, 103.6831 1.2756, 103.6858 1.2725, 103.6922 1.2778, 103.6917 1.2731, 103.6942 1.2719, 103.6958 1.2792, 103.6944 1.2819, 103.6989 1.2858, 103.7022 1.2836, 103.7069 1.2756, 103.7104 1.2758, 103.7118 1.2782, 103.7069 1.2806, 103.7039 1.2897, 103.7069 1.2939, 103.7097 1.2925)), ((103.7901 1.3487, 103.7862 1.3486, 103.7883 1.3457, 103.7874 1.3447, 103.7778 1.3419, 103.7704 1.349, 103.7632 1.3467, 103.7671 1.3428, 103.7651 1.3421, 103.7642 1.3392, 103.7656 1.3358, 103.7648 1.3324, 103.7756 1.3264, 103.7709 1.3213, 103.7722 1.3114, 103.7695 1.2947, 103.7674 1.2917, 103.7623 1.3013, 103.7581 1.2992, 103.7561 1.2956, 103.7522 1.295, 103.7414 1.2989, 103.7306 1.3005, 103.7272 1.3072, 103.7272 1.3108, 103.7322 1.3189, 103.7325 1.3225, 103.7281 1.3167, 103.7239 1.3069, 103.7269 1.3025, 103.7264 1.3009, 103.7178 1.3061, 103.7169 1.3053, 103.7208 1.3014, 103.72 1.2997, 103.7186 1.2986, 103.7136 1.3003, 103.7108 1.3067, 103.7092 1.305, 103.7094 1.3022, 103.7072 1.3008, 103.7033 1.3011, 103.7006 1.3039, 103.6992 1.2997, 103.6958 1.2986, 103.6947 1.3039, 103.6942 1.2997, 103.6853 1.2989, 103.6833 1.2992, 103.6818 1.3044, 103.6822 1.2983, 103.6788 1.2967, 103.6711 1.3058, 103.6697 1.3015, 103.6753 1.2953, 103.6756 1.2931, 103.6711 1.2922, 103.6672 1.2878, 103.6631 1.2919, 103.6606 1.2914, 103.6592 1.2936, 103.6581 1.2931, 103.6581 1.2961, 103.6556 1.2953, 103.6442 1.3069, 103.6483 1.3108, 103.6469 1.3128, 103.6447 1.3128, 103.6429 1.3055, 103.6389 1.3045, 103.6381 1.3069, 103.6372 1.3064, 103.6338 1.298, 103.6473 1.291, 103.6477 1.2869, 103.6424 1.286, 103.6386 1.2702, 103.6215 1.262, 103.6212 1.2575, 103.6156 1.2531, 103.6221 1.2377, 103.6182 1.2366, 103.6221 1.2236, 103.6091 1.2191, 103.6108 1.2271, 103.6176 1.2292, 103.6159 1.2363, 103.6129 1.2383, 103.6111 1.251, 103.6185 1.2596, 103.619 1.2623, 103.615 1.2678, 103.622 1.2873, 103.6169 1.2919, 103.6167 1.2956, 103.6205 1.3015, 103.6341 1.3394, 103.6328 1.3425, 103.6344 1.3461, 103.6331 1.3508, 103.6375 1.3522, 103.6383 1.3497, 103.6451 1.3439, 103.6503 1.3425, 103.6499 1.3388, 103.6514 1.3361, 103.6551 1.3362, 103.6563 1.3384, 103.6539 1.3383, 103.6525 1.344, 103.645 1.3504, 103.6412 1.3562, 103.6445 1.3581, 103.6453 1.3611, 103.6514 1.3627, 103.6544 1.3619, 103.6524 1.3677, 103.6552 1.3727, 103.6689 1.3728, 103.6708 1.3672, 103.6739 1.3675, 103.6742 1.3706, 103.6714 1.3753, 103.6734 1.3786, 103.6771 1.3793, 103.6739 1.38, 103.6722 1.3831, 103.6625 1.3817, 103.6594 1.3833, 103.6572 1.3817, 103.6569 1.3828, 103.6622 1.3925, 103.6622 1.3964, 103.6606 1.3981, 103.6625 1.4006, 103.6626 1.4051, 103.6655 1.4092, 103.6699 1.411, 103.674 1.4244, 103.6778 1.4289, 103.693 1.4337, 103.695 1.4315, 103.697 1.4243, 103.7001 1.4232, 103.6987 1.4187, 103.7016 1.4181, 103.701 1.4168, 103.705 1.4125, 103.7042 1.4108, 103.7097 1.4117, 103.7117 1.4099, 103.7144 1.4128, 103.717 1.4092, 103.7227 1.4105, 103.7254 1.4094, 103.7263 1.4067, 103.7237 1.399, 103.7244 1.3965, 103.7198 1.3928, 103.7201 1.3915, 103.7262 1.3956, 103.7284 1.4033, 103.7311 1.4009, 103.735 1.3917, 103.7355 1.3977, 103.7297 1.4097, 103.7393 1.418, 103.74 1.4204, 103.7426 1.4072, 103.7526 1.4035, 103.7533 1.389, 103.765 1.3908, 103.7744 1.3903, 103.7806 1.3611, 103.7837 1.3565, 103.7905 1.3511, 103.7917 1.3493, 103.7901 1.3487)), ((103.7525 1.2242, 103.7514 1.2258, 103.7514 1.2264, 103.7531 1.2261, 103.7525 1.2242)), ((103.7642 1.2406, 103.7694 1.2372, 103.7789 1.2272, 103.7786 1.2233, 103.7739 1.2244, 103.7703 1.2289, 103.7686 1.2259, 103.7636 1.225, 103.7561 1.2292, 103.7539 1.2322, 103.7542 1.2361, 103.7567 1.2372, 103.7594 1.2339, 103.7603 1.2358, 103.7589 1.2389, 103.7611 1.2411, 103.7642 1.2406)), ((103.7508 1.2357, 103.7508 1.2333, 103.7472 1.2314, 103.7428 1.2311, 103.7394 1.2336, 103.7431 1.2367, 103.7417 1.2383, 103.7431 1.24, 103.7481 1.2394, 103.7503 1.2408, 103.7508 1.2357)), ((103.7271 1.4048, 103.7277 1.4061, 103.7281 1.406, 103.7282 1.4044, 103.7271 1.4048)), ((103.6504 1.3702, 103.6497 1.3729, 103.654 1.3748, 103.6542 1.3716, 103.6518 1.3696, 103.6504 1.3702)), ((103.6552 1.3789, 103.6559 1.3807, 103.6565 1.3808, 103.6546 1.3777, 103.6552 1.3789)), ((103.7103 1.4125, 103.7095 1.4125, 103.7107 1.4129, 103.7103 1.4125)), ((103.6844 1.4339, 103.6842 1.4346, 103.6859 1.435, 103.6851 1.4337, 103.6844 1.4339))) │
└───────────┴────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Do a spatial query that checks the location of latitude 1.2966 and longitude 103.7764 in which region (Central, East, North, North-East, West):
+----+-----------+----------+
| | COUNTRY | NAME_1 |
|----+-----------+----------|
| 0 | Singapore | Central |
+----+-----------+----------+
5. Benchmark
DuckDB is fast and memory-efficient. There are some benchmarks of Polars and DuckDB:
- DuckDB (database-like ops benchmark): https://duckdblabs.github.io/db-benchmark/
- Polars (TPCH Benchmark): https://pola.rs/posts/benchmarks/
