Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 76 additions & 12 deletions docs/integrate/dask/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
(dask)=
# Dask

:::{div} .float-right .text-right
[![Dask logo](https://github.com/crate/crate-clients-tools/assets/453543/99bd2234-c501-479b-ade7-bcc2bfc1f288){height=60px loading=lazy}][Dask]
<br>
[![Dask CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-dask.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-dask.yml)
:::
:::{div} .clearfix
:::

:::{rubric} About
:::

[Dask] is a parallel computing library for analytics with task scheduling.
It is built on top of the Python programming language, making it easy to scale
the Python libraries that you know and love, like NumPy, pandas, and scikit-learn.

```{div}
:style: "float: right"
[![](https://github.com/crate/crate-clients-tools/assets/453543/99bd2234-c501-479b-ade7-bcc2bfc1f288){w=180px}](https://www.dask.org/)
```

- [Dask DataFrames] help you process large tabular data by parallelizing pandas,
either on your laptop for larger-than-memory computing, or on a distributed
cluster of computers.
Expand All @@ -20,16 +24,78 @@ the Python libraries that you know and love, like NumPy, pandas, and scikit-lear
generic Python workflows across a Dask cluster with minimal code changes,
by extending Python's `concurrent.futures` interface.

```{div}
:style: "clear: both"
:::{rubric} Install
:::

```shell
pip install 'dask[dataframe]' 'sqlalchemy-cratedb'
```

:::{rubric} Learn
:::{rubric} Synopsis
:::

Write Dask dataframe to CrateDB.

`example.py`
```python
import dask.dataframe as dd
from sqlalchemy_cratedb import insert_bulk

CRATEDB_URI = "crate://crate:crate@localhost:4200"
TABLE_NAME = "example"

df = makeTimeDataFrame(rows=500_000, freq="s")
ddf = dd.from_pandas(df, npartitions=4)
ddf.to_sql(
TABLE_NAME,
uri=CRATEDB_URI,
index=False,
if_exists="replace",
chunksize=20_000,
parallel=True,
method=insert_bulk,
)
```

:::{rubric} Quickstart example
:::

Create the file `example.py` including the synopsis code shared above.
Complete the example by using the `makeTimeDataFrame()` function.

:::{literalinclude} ../pandas/makeTimeDataFrame.py
:::

:::{include} /connect/_cratedb.md
:::
```shell
pip install 'dask[dataframe]' 'sqlalchemy-cratedb'
python example.py
```

:::{rubric} Full example
:::

:::{card}
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/dask
:link-type: url
{material-regular}`play_arrow;2em`
Connect to CrateDB and CrateDB Cloud using Dask.
+++
Includes basic examples of how to use Dask with CrateDB.
:::

:::{rubric} Guides
:::

- {ref}`dask-usage`
- [Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]

:::{rubric} Related sections
:::

- {ref}`Efficient batch/bulk INSERT operations for pandas, Dask, and Polars <sqlalchemy-cratedb:dataframe>`
- {ref}`arrow-import-parquet`
- [Import weather data using Dask]
- [Dask code examples]


:::{toctree}
Expand All @@ -40,8 +106,6 @@ Usage <usage>


[Dask]: https://www.dask.org/
[Dask code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/dask
[Dask DataFrames]: https://docs.dask.org/en/latest/dataframe.html
[Dask Futures]: https://docs.dask.org/en/latest/futures.html
[Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]: https://cratedb.com/docs/python/en/latest/by-example/sqlalchemy/dataframe.html
[Import weather data using Dask]: https://github.com/crate/cratedb-examples/blob/main/topic/timeseries/dask-weather-data-import.ipynb
2 changes: 2 additions & 0 deletions docs/integrate/pandas/efficient-ingest.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(pandas-bulk-import)=
(pandas-efficient-import)=

# Efficient bulk imports with pandas

## Introduction
Expand Down
105 changes: 76 additions & 29 deletions docs/integrate/pandas/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(pandas)=
# pandas

```{div}
:style: "float: right"
[![](https://pandas.pydata.org/static/img/pandas.svg){w=180px}](https://pandas.pydata.org/)
```
```{div} .clearfix
```
:::{div} .float-right .text-right
[![pandas logo](https://pandas.pydata.org/static/img/pandas.svg){height=60px loading=lazy}][pandas]
<br>
[![pandas CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-pandas.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-pandas.yml)
:::
:::{div} .clearfix
:::

:::{rubric} About
:::
Expand All @@ -15,35 +16,83 @@
and manipulation tool, built on top of the Python programming language. It offers
data structures and operations for manipulating numerical tables and time series.

:::{rubric} Data Model
Pandas is built around data structures called Series and DataFrames. Data for these
collections can be imported from various file formats such as comma-separated values,
JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
A Series is a 1-dimensional data structure built on top of NumPy's array.

:::{rubric} Install
:::
- Pandas is built around data structures called Series and DataFrames. Data for these
collections can be imported from various file formats such as comma-separated values,
JSON, Parquet, SQL database tables or queries, and Microsoft Excel.
- A Series is a 1-dimensional data structure built on top of NumPy's array.
- Pandas includes support for time series, such as the ability to interpolate values
and filter using a range of timestamps.
- By default, a Pandas index is a series of integers ascending from 0, similar to the
indices of Python arrays. However, indices can use any NumPy data type, including
floating point, timestamps, or strings.
- Pandas supports hierarchical indices with multiple values per data point. An index
with this structure, called a "MultiIndex", allows a single DataFrame to represent
multiple dimensions, similar to a pivot table in Microsoft Excel. Each level of a
MultiIndex can be given a unique name.

```shell
pip install pandas sqlalchemy-cratedb
```

:::{rubric} Learn
:::{rubric} Synopsis
:::

Write pandas dataframe to CrateDB.

`example.py`
```python
import sqlalchemy as sa
from sqlalchemy_cratedb import insert_bulk

CRATEDB_URI = "crate://crate:crate@localhost:4200"
TABLE_NAME = "example"

df = makeTimeDataFrame(rows=500_000, freq="s")
engine = sa.create_engine(CRATEDB_URI)
df.to_sql(
name=TABLE_NAME,
con=engine,
if_exists="replace",
index=False,
chunksize=20_000,
method=insert_bulk,
)
```

:::{rubric} Quickstart example
:::

Create the file `example.py` including the synopsis code shared above.
Complete the example by using the `makeTimeDataFrame()` function.

:::{literalinclude} ../pandas/makeTimeDataFrame.py
:::

:::{include} /connect/_cratedb.md
:::
```shell
pip install pandas sqlalchemy-cratedb
python example.py
```

:::{rubric} Full example
:::

:::{card}
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas
:link-type: url
{material-regular}`play_arrow;2em`
Connect to CrateDB and CrateDB Cloud using pandas.
+++
Includes basic examples of how to use pandas with CrateDB.
:::

:::{rubric} Guides
:::

- {ref}`pandas-efficient-import`
- {ref}`pandas-tutorial-start`
- {ref}`pandas-tutorial-jupyter`
- {ref}`arrow-import-parquet`
- {ref}`pandas-bulk-import`
- See also: {ref}`dask-bulk-import`
- See also: [Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]

:::{rubric} Code examples
:::{rubric} Related sections
:::
- [pandas code examples]

- {ref}`Efficient batch/bulk INSERT operations for pandas, Dask, and Polars <sqlalchemy-cratedb:dataframe>`
- {ref}`arrow-import-parquet`


:::{toctree}
Expand All @@ -55,6 +104,4 @@ Efficient ingest <efficient-ingest>
:::


[Efficient batch/bulk INSERT operations with pandas, Dask, and SQLAlchemy]: https://cratedb.com/docs/python/en/latest/by-example/sqlalchemy/dataframe.html
[pandas]: https://pandas.pydata.org/
[pandas code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/pandas
8 changes: 8 additions & 0 deletions docs/integrate/pandas/makeTimeDataFrame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def makeTimeDataFrame(rows=5_000, freq = "B"):
import numpy as np
import pandas as pd
return pd.DataFrame(
np.random.default_rng(2).standard_normal((rows, 4)),
columns=pd.Index(list("ABCD"), dtype=object),
index=pd.date_range("2000-01-01", periods=rows, freq=freq),
)
91 changes: 78 additions & 13 deletions docs/integrate/polars/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(polars)=
# Polars

```{div}
:style: "float: right; margin-left: 0.5em"
[![Polars logo](https://github.com/pola-rs/polars-static/raw/master/logos/polars-logo-dark.svg){w=180px}][Polars]
```
```{div} .clearfix
```
:::{div} .float-right .text-right
[![Polars logo](https://github.com/pola-rs/polars-static/raw/master/logos/polars-logo-dark.svg){height=60px loading=lazy}][Polars]
<br>
[![Polars CI](https://img.shields.io/github/actions/workflow/status/crate/cratedb-examples/dataframe-polars.yml?branch=main)](https://github.com/crate/cratedb-examples/actions/workflows/dataframe-polars.yml)
:::
:::{div} .clearfix
:::

:::{rubric} About
:::
Expand All @@ -15,6 +16,13 @@
Rust, Python, Node.js, and R, plus a SQL context. It is powered by a
multithreaded, vectorized query engine and written in Rust.

:::{dropdown} Features and data formats

Polars is an open-source library for data manipulation, known for being
one of the fastest data processing solutions on a single machine.
It features a well-structured, typed API that is both expressive and
easy to use.

- **Fast:** Written from scratch in Rust and with performance in mind,
designed close to the machine, and without external dependencies.

Expand All @@ -29,7 +37,7 @@ multithreaded, vectorized query engine and written in Rust.
- **Out of Core:** The streaming API allows you to process your results without
requiring all your data to be in memory at the same time.

- **Parallel:** Polars' multi-threaded query engine utilizes the power of your
- **Parallel:** Polars' multithreaded query engine utilizes the power of your
machine by dividing the workload among the available CPU cores without any
additional configuration.

Expand All @@ -41,9 +49,6 @@ multithreaded, vectorized query engine and written in Rust.
community of developers. Everyone is encouraged to add new features and contribute.
It is free to use under the MIT license.

:::{rubric} Data formats
:::

Polars supports reading and writing to many common data formats.
This allows you to easily integrate Polars into your existing data stack.

Expand All @@ -53,11 +58,71 @@ This allows you to easily integrate Polars into your existing data stack.
- Databases: MySQL, PostgreSQL, SQLite, Redshift, SQL Server, etc. (via ConnectorX)
- Cloud storage: Amazon S3, Azure Blob/ADLS (via fsspec‑compatible backends)

:::{rubric} Learn
:::
- [Polars code examples]

:::{rubric} Install
:::

```shell
pip install 'polars[pyarrow]' sqlalchemy-cratedb
```

:::{rubric} Synopsis
:::

Write Polars dataframe to CrateDB.

`example.py`
```python
import polars as pl
import sqlalchemy as sa
from sqlalchemy_cratedb import insert_bulk

CRATEDB_URI = "crate://crate:crate@localhost:4200"
TABLE_NAME = "example"

df = pl.from_pandas(makeTimeDataFrame(rows=500_000, freq="s"))
engine = sa.create_engine(CRATEDB_URI)
df.write_database(
engine="sqlalchemy",
connection=engine,
table_name=TABLE_NAME,
if_table_exists="replace",
engine_options={
"method": insert_bulk,
"chunksize": 20_000,
},
)
```

:::{rubric} Quickstart example
:::

Create the file `example.py` including the synopsis code shared above.
Complete the example by using the `makeTimeDataFrame()` function.

:::{literalinclude} ../pandas/makeTimeDataFrame.py
:::

:::{include} /connect/_cratedb.md
:::
```shell
pip install 'polars[pyarrow]' sqlalchemy-cratedb pandas
python example.py
```

:::{rubric} Full example
:::

:::{card}
:link: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/polars
:link-type: url
{material-regular}`play_arrow;2em`
Connect to CrateDB and CrateDB Cloud using Polars.
+++
Includes basic examples of how to use Polars with CrateDB.
:::


[Apache Arrow]: https://arrow.apache.org/
[Polars]: https://pola.rs/
[Polars code examples]: https://github.com/crate/cratedb-examples/tree/main/by-dataframe/polars
Loading