Skip to content

Commit

Permalink
update README.md (datafusion-contrib#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
hozan23 authored Aug 24, 2024
1 parent 5d240d7 commit f4babee
Showing 1 changed file with 59 additions and 25 deletions.
84 changes: 59 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
## DataFusion Federation
# DataFusion Federation

[![crates.io](https://img.shields.io/crates/v/datafusion-federation.svg)](https://crates.io/crates/datafusion-federation)
[![docs.rs](https://docs.rs/datafusion-federation/badge.svg)](https://docs.rs/datafusion-federation)

DataFusion Federation allows [DataFusion](https://github.com/apache/arrow-datafusion) to execute (part of) a query plan by a remote execution engine.
DataFusion Federation allows
[DataFusion](https://github.com/apache/arrow-datafusion) to execute (part of) a
query plan by a remote execution engine.

┌────────────────┐
┌────────────┐ │ Remote DBMS(s) │
SQL Query ───> │ DataFusion │ ───> │ ( execution │
└────────────┘ │ happens here ) │
└────────────────┘

The goal is to allow resolving queries across remote query engines while pushing down as much compute as possible to the remote database(s). This allows execution to happen as close to the storage as possible. This concept is referred to as 'query federation'.
The goal is to allow resolving queries across remote query engines while
pushing down as much compute as possible to the remote database(s). This allows
execution to happen as close to the storage as possible. This concept is
referred to as 'query federation'.

> [!TIP]
> This repository implements the federation framework itself. If you want to connect to a specific database, check out the compatible providers available in [datafusion-contrib/datafusion-table-providers](https://github.com/datafusion-contrib/datafusion-table-providers/).
> This repository implements the federation framework itself. If you want to
> connect to a specific database, check out the compatible providers available
> in
> [datafusion-contrib/datafusion-table-providers](https://github.com/datafusion-contrib/datafusion-table-providers/).
#### Usage
## Usage

> :warning: **All the examples are deprecated for now**
Check out [the examples](./examples/) to get a feel for how it works.

Potential use-cases:
## Potential use-cases:

- Querying across SQLite, MySQL, PostgreSQL, ...
- Pushing down SQL or [Substrait](https://substrait.io/) plans.
- DataFusion -> Flight SQL -> DataFusion
- ..

#### Design concept
## Design concept

Say you have a query plan as follows:

Expand All @@ -50,9 +58,9 @@ Say you have a query plan as follows:
DataFusion Federation will identify the largest possible sub-plans that
can be executed by an external database:

┌────────────┐ Optimizer pass
│ Join │ recognizes B and C
└────────────┘ are available in an
┌────────────┐ Optimizer recognizes
│ Join │ that B and C are
└────────────┘ available in an
▲ external database
┌──────────────┴────────┐
│ ┌ ─ ─ ─ ─ ─ ─ ┴ ─ ── ─ ─ ─ ─ ─┐
Expand Down Expand Up @@ -82,21 +90,47 @@ The sub-plans are cut out and replaced by an opaque federation node in the plan:
┃external database)┃
┗━━━━━━━━━━━━━━━━━━┛

Different databases may have different query languages and execution capabilities. To accommodate for this, we allow each 'federation provider' to self-determine what part of a sub-plan it will actually federate. This is done by letting each federation provider define its own optimizer rule. When a sub-plan is 'cut out' of the overall plan, it is first passed the federation provider's optimizer rule. This optimizer rule determines the part of the plan that is cut out, based based on the execution capabilities of the database it represents.

#### Implementation

A remote database is represented by the `FederationProvider` trait. To identify table scans that are available in the same database, they implement `FederatedTableSource` trait. This trait allows lookup of the corresponding `FederationProvider`.

Identifying sub-plans to federate is done by the `FederationOptimizerRule`. This rule needs to be registered in your DataFusion SessionState. One easy way to do this is using `default_session_state`. To do its job, the `FederationOptimizerRule` currently requires that all TableProviders that need to be federated are `FederatedTableProviderAdaptor`s. The `FederatedTableProviderAdaptor` also has a fallback mechanism that allows implementations to fallback to a 'vanilla' TableProvider in case the `FederationOptimizerRule` isn't registered.

The `FederationProvider` can provide a `compute_context`. This allows it to differentiate between multiple remote execution context of the same type. For example two different mysql instances, database schemas, access level, etc. The `FederationProvider` also returns the `Optimizer` that is allows it to self-determine what part of a sub-plan it can federate.

The `sql` module implements a generic `FederationProvider` for SQL execution engines. A specific SQL engine implements the `SQLExecutor` trait for its engine specific execution. There are a number of compatible providers available in [datafusion-contrib/datafusion-table-providers](https://github.com/datafusion-contrib/datafusion-table-providers/).

#### Status

The project is in alpha status. Contributions welcome; land a PR = commit access.
Different databases may have different query languages and execution
capabilities. To accommodate for this, we allow each 'federation provider' to
self-determine what part of a sub-plan it will actually federate. This is done
by letting each federation provider define its own optimizer rule. When a
sub-plan is 'cut out' of the overall plan, it is first passed the federation
provider's optimizer rule. This optimizer rule determines the part of the plan
that is cut out, based on the execution capabilities of the database it
represents.

## Implementation

A remote database is represented by the `FederationProvider` trait. To identify
table scans that are available in the same database, they implement
`FederatedTableSource` trait. This trait allows lookup of the corresponding
`FederationProvider`.

Identifying sub-plans to federate is done by the `FederationOptimizerRule`.
This rule needs to be registered in your DataFusion SessionState. One easy way
to do this is using `default_session_state`. To do its job, the
`FederationOptimizerRule` currently requires that all TableProviders that need
to be federated are `FederatedTableProviderAdaptor`s. The
`FederatedTableProviderAdaptor` also has a fallback mechanism that allows
implementations to fallback to a 'vanilla' TableProvider in case the
`FederationOptimizerRule` isn't registered.

The `FederationProvider` can provide a `compute_context`. This allows it to
differentiate between multiple remote execution context of the same type. For
example two different mysql instances, database schemas, access level, etc. The
`FederationProvider` also returns the `Optimizer` that is allows it to
self-determine what part of a sub-plan it can federate.

The `sql` module implements a generic `FederationProvider` for SQL execution
engines. A specific SQL engine implements the `SQLExecutor` trait for its
engine specific execution. There are a number of compatible providers available
in
[datafusion-contrib/datafusion-table-providers](https://github.com/datafusion-contrib/datafusion-table-providers/).

## Status

The project is in alpha status. Contributions welcome; land a PR = commit
access.

- [Docs (release)](https://docs.rs/datafusion-federation)
- [Docs (main)](https://datafusion-contrib.github.io/datafusion-federation/)

0 comments on commit f4babee

Please sign in to comment.