Coder Social home page Coder Social logo

isabella232 / arrow-datafusion Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apache/datafusion

0.0 0.0 0.0 13.16 MB

Apache Arrow DataFusion and Ballista query engines

Home Page: https://arrow.apache.org/datafusion

License: Apache License 2.0

Emacs Lisp 0.03% Shell 3.96% Batchfile 0.38% Python 1.74% Dockerfile 2.19% CMake 0.22% Rust 90.67% HTML 0.07% CSS 0.05% TypeScript 0.70%

arrow-datafusion's Introduction

DataFusion

DataFusion is an extensible query execution framework, written in Rust, that uses Apache Arrow as its in-memory format.

DataFusion supports both an SQL and a DataFrame API for building logical query plans as well as a query optimizer and execution engine capable of parallel execution against partitioned data sources (CSV and Parquet) using threads.

DataFusion also supports distributed query execution via the Ballista crate.

Use Cases

DataFusion is used to create modern, fast and efficient data pipelines, ETL processes, and database systems, which need the performance of Rust and Apache Arrow and want to provide their users the convenience of an SQL interface or a DataFrame API.

Why DataFusion?

  • High Performance: Leveraging Rust and Arrow's memory model, DataFusion achieves very high performance
  • Easy to Connect: Being part of the Apache Arrow ecosystem (Arrow, Parquet and Flight), DataFusion works well with the rest of the big data ecosystem
  • Easy to Embed: Allowing extension at almost any point in its design, DataFusion can be tailored for your specific usecase
  • High Quality: Extensively tested, both by itself and with the rest of the Arrow ecosystem, DataFusion can be used as the foundation for production systems.

Known Uses

Here are some of the projects known to use DataFusion:

(if you know of another project, please submit a PR to add a link!)

Example Usage

Run a SQL query against data stored in a CSV:

use datafusion::prelude::*;
use datafusion::arrow::util::pretty::print_batches;
use datafusion::arrow::record_batch::RecordBatch;

#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
  // register the table
  let mut ctx = ExecutionContext::new();
  ctx.register_csv("example", "tests/example.csv", CsvReadOptions::new()).await?;

  // create a plan to run a SQL query
  let df = ctx.sql("SELECT a, MIN(b) FROM example GROUP BY a LIMIT 100").await?;

  // execute and print results
  df.show().await?;
  Ok(())
}

Use the DataFrame API to process data stored in a CSV:

use datafusion::prelude::*;
use datafusion::arrow::util::pretty::print_batches;
use datafusion::arrow::record_batch::RecordBatch;

#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
  // create the dataframe
  let mut ctx = ExecutionContext::new();
  let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new()).await?;

  let df = df.filter(col("a").lt_eq(col("b")))?
          .aggregate(vec![col("a")], vec![min(col("b"))])?;

  // execute and print results
  df.show_limit(100).await?;
  Ok(())
}

Both of these examples will produce

+---+--------+
| a | MIN(b) |
+---+--------+
| 1 | 2      |
+---+--------+

Using DataFusion as a library

DataFusion is published on crates.io, and is well documented on docs.rs.

To get started, add the following to your Cargo.toml file:

[dependencies]
datafusion = "5.0.0"

Using DataFusion as a binary

DataFusion also includes a simple command-line interactive SQL utility. See the CLI reference for more information.

Status

General

  • SQL Parser
  • SQL Query Planner
  • Query Optimizer
  • Constant folding
  • Join Reordering
  • Limit Pushdown
  • Projection push down
  • Predicate push down
  • Type coercion
  • Parallel query execution

SQL Support

  • Projection
  • Filter (WHERE)
  • Filter post-aggregate (HAVING)
  • Limit
  • Aggregate
  • Common math functions
  • cast
  • try_cast
  • Postgres compatible String functions
    • ascii
    • bit_length
    • btrim
    • char_length
    • character_length
    • chr
    • concat
    • concat_ws
    • initcap
    • left
    • length
    • lpad
    • ltrim
    • octet_length
    • regexp_replace
    • repeat
    • replace
    • reverse
    • right
    • rpad
    • rtrim
    • split_part
    • starts_with
    • strpos
    • substr
    • to_hex
    • translate
    • trim
  • Miscellaneous/Boolean functions
    • nullif
  • Approximation functions
    • approx_distinct
  • Common date/time functions
  • nested functions
    • Array of columns
  • Schema Queries
    • SHOW TABLES
    • SHOW COLUMNS
    • information_schema.{tables, columns}
    • information_schema other views
  • Sorting
  • Nested types
  • Lists
  • Subqueries
  • Common table expressions
  • Set Operations
    • UNION ALL
    • UNION
    • INTERSECT
    • INTERSECT ALL
    • EXCEPT
    • EXCEPT ALL
  • Joins
    • INNER JOIN
    • LEFT JOIN
    • RIGHT JOIN
    • FULL JOIN
    • CROSS JOIN
  • Window
    • Empty window
    • Common window functions
    • Window with PARTITION BY clause
    • Window with ORDER BY clause
    • Window with FILTER clause
    • Window with custom WINDOW FRAME
    • UDF and UDAF for window functions

Data Sources

  • CSV
  • Parquet primitive types
  • Parquet nested types

Extensibility

DataFusion is designed to be extensible at all points. To that end, you can provide your own custom:

  • User Defined Functions (UDFs)
  • User Defined Aggregate Functions (UDAFs)
  • User Defined Table Source (TableProvider) for tables
  • User Defined Optimizer passes (plan rewrites)
  • User Defined LogicalPlan nodes
  • User Defined ExecutionPlan nodes

Rust Version Compatbility

This crate is tested with the latest stable version of Rust. We do not currrently test against other, older versions of the Rust compiler.

Supported SQL

This library currently supports many SQL constructs, including

  • CREATE EXTERNAL TABLE X STORED AS PARQUET LOCATION '...'; to register a table's locations
  • SELECT ... FROM ... together with any expression
  • ALIAS to name an expression
  • CAST to change types, including e.g. Timestamp(Nanosecond, None)
  • most mathematical unary and binary expressions such as +, /, sqrt, tan, >=.
  • WHERE to filter
  • GROUP BY together with one of the following aggregations: MIN, MAX, COUNT, SUM, AVG
  • ORDER BY together with an expression and optional ASC or DESC and also optional NULLS FIRST or NULLS LAST

Supported Functions

DataFusion strives to implement a subset of the PostgreSQL SQL dialect where possible. We explicitly choose a single dialect to maximize interoperability with other tools and allow reuse of the PostgreSQL documents and tutorials as much as possible.

Currently, only a subset of the PostgreSQL dialect is implemented, and we will document any deviations.

Schema Metadata / Information Schema Support

DataFusion supports the showing metadata about the tables available. This information can be accessed using the views of the ISO SQL information_schema schema or the DataFusion specific SHOW TABLES and SHOW COLUMNS commands.

More information can be found in the Postgres docs).

To show tables available for use in DataFusion, use the SHOW TABLES command or the information_schema.tables view:

> show tables;
+---------------+--------------------+------------+------------+
| table_catalog | table_schema       | table_name | table_type |
+---------------+--------------------+------------+------------+
| datafusion    | public             | t          | BASE TABLE |
| datafusion    | information_schema | tables     | VIEW       |
+---------------+--------------------+------------+------------+

> select * from information_schema.tables;

+---------------+--------------------+------------+--------------+
| table_catalog | table_schema       | table_name | table_type   |
+---------------+--------------------+------------+--------------+
| datafusion    | public             | t          | BASE TABLE   |
| datafusion    | information_schema | TABLES     | SYSTEM TABLE |
+---------------+--------------------+------------+--------------+

To show the schema of a table in DataFusion, use the SHOW COLUMNS command or the or information_schema.columns view:

> show columns from t;
+---------------+--------------+------------+-------------+-----------+-------------+
| table_catalog | table_schema | table_name | column_name | data_type | is_nullable |
+---------------+--------------+------------+-------------+-----------+-------------+
| datafusion    | public       | t          | a           | Int32     | NO          |
| datafusion    | public       | t          | b           | Utf8      | NO          |
| datafusion    | public       | t          | c           | Float32   | NO          |
+---------------+--------------+------------+-------------+-----------+-------------+

>   select table_name, column_name, ordinal_position, is_nullable, data_type from information_schema.columns;
+------------+-------------+------------------+-------------+-----------+
| table_name | column_name | ordinal_position | is_nullable | data_type |
+------------+-------------+------------------+-------------+-----------+
| t          | a           | 0                | NO          | Int32     |
| t          | b           | 1                | NO          | Utf8      |
| t          | c           | 2                | NO          | Float32   |
+------------+-------------+------------------+-------------+-----------+

Supported Data Types

DataFusion uses Arrow, and thus the Arrow type system, for query execution. The SQL types from sqlparser-rs are mapped to Arrow types according to the following table

SQL Data Type Arrow DataType
CHAR Utf8
VARCHAR Utf8
UUID Not yet supported
CLOB Not yet supported
BINARY Not yet supported
VARBINARY Not yet supported
DECIMAL Float64
FLOAT Float32
SMALLINT Int16
INT Int32
BIGINT Int64
REAL Float64
DOUBLE Float64
BOOLEAN Boolean
DATE Date32
TIME Time64(TimeUnit::Millisecond)
TIMESTAMP Timestamp(TimeUnit::Nanosecond)
INTERVAL Not yet supported
REGCLASS Not yet supported
TEXT Not yet supported
BYTEA Not yet supported
CUSTOM Not yet supported
ARRAY Not yet supported

Architecture Overview

There is no formal document describing DataFusion's architecture yet, but the following presentations offer a good overview of its different components and how they interact together.

  • (March 2021): The DataFusion architecture is described in Query Engine Design and the Rust-Based DataFusion in Apache Arrow: recording (DataFusion content starts ~ 15 minutes in) and slides
  • (Feburary 2021): How DataFusion is used within the Ballista Project is described in *Ballista: Distributed Compute with Rust and Apache Arrow: recording

Developer's guide

Please see Developers Guide for information about developing DataFusion.

arrow-datafusion's People

Contributors

kou avatar wesm avatar kszucs avatar andygrove avatar pitrou avatar alamb avatar nealrichardson avatar xhochy avatar jorgecarleitao avatar dandandan avatar jimexist avatar fsaintjacques avatar nevi-me avatar paddyhoran avatar sunchao avatar seddonm1 avatar bkietz avatar emkornfield avatar julienledem avatar cpcloud avatar houqp avatar bryancutler avatar kiszk avatar pcmoritz avatar jorisvandenbossche avatar trxcllnt avatar shiro615 avatar mrkn avatar ovr avatar lidavidm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.