delta-rs
repository·main·Indexed 25 days ago
https://github.com/delta-io/delta-rsA native Rust implementation of the Delta Lake storage format providing high-performance, low-level APIs for data lake operations. It includes official Python bindings via the deltalake package (version 1.6.2), allowing users to query, inspect, and operate Delta Lakes with ACID transaction guarantees and schema enforcement.
What's inside delta-rs
- Delta Lake allows you to create Delta tables, run queries, perform DML (Data Manipulation Language) operations, and optimize tables. It is designed to be compatible with various DataFrame libraries, including pandas, Polars, Rust, and any other PyArrow-like library.
Overview of delta-rs
maindelta-rs is a native Rust library for Delta Lake with Python bindings. It provides low-level APIs for developers and integrators, as well as high-level operations to query, inspect, and operate Delta Lakes. Delta Lake is an open-source storage format that provides ACID transaction guarantees, schema enforcement, and scalable data handling, compatible with engines like Apache Spark.Overview of the Python deltalake package
mainThedeltalakePython package is a native implementation for reading, writing, and managing Delta Lake tables. It is built on top of thedelta-rsRust library and does not require Spark or a JVM. Because it usesApache Arrowinternally, it is compatible with Arrow-native libraries such asPandas,DuckDB, andPolars.Understand Delta Lake performance advantages
mainDelta Lake provides performance optimizations over standard data lakes (like Parquet or CSV) through two primary mechanisms:
- File Skipping: Delta Lake stores min/max values for each column of every file in the transaction log. This allows queries to skip entire files based on metadata without opening the files themselves.
- Efficient File Discovery: Instead of performing slow file-listing operations on cloud object stores (which can be particularly slow with Hive-style partitions), Delta Lake retrieves all necessary file paths directly from the transaction log.
To further optimize performance, you can use techniques like partitioning or Z-Ordering to colocate similar data in the same files, maximizing the effectiveness of file skipping.
Understand Delta Lake table architecture
mainA Delta table is composed of two main parts:
- Parquet files: These contain the actual data.
_delta_logdirectory: This contains a transaction log that stores metadata about all transactions, including:- Files added to the table.
- The schema of the files.
- Column-level metadata (e.g., min/max values for each file).
This architecture allows for ACID transactions by using a transaction log to manage state rather than relying on the physical presence of files in storage.
Supported languages and environments for Delta Lake
mainDelta Lake is highly portable and supports a wide range of environments and languages:
- Languages: This project provides native APIs for Rust and Python without requiring a Java or Scala dependency. It serves as an alternative to using pandas, Polars, DuckDB, or DataFusion directly on raw files.
- Cloud Providers: Full support for AWS, GCP, and Azure.
- Local/On-Prem: Can be run on local machines or in on-premises environments.
Understand Delta Lake File Skipping
mainDelta Lake implements file skipping by storing min/max metadata for each column in the transaction log. Query engines use this metadata to skip entire files that do not contain relevant data for a specific predicate (e.g.,
WHERE age < 20), significantly reducing I/O.Key requirements for file skipping:
- File Format: Data must be in a format that supports file-level metadata, such as Parquet. Formats like CSV do not support this optimization.
- Query Type: Queries must include predicates (filters) that can be evaluated against the min/max values. Queries like
GROUP BYwithout filters typically cannot benefit from file skipping. - Data Layout: The effectiveness of skipping depends on how data is distributed across files.
Use OpenDAL storage backends in delta-rs
mainYou can access any storage service supported by Apache OpenDAL using a generic backend in
delta-rs. This allows you to use services that do not have a dedicated native integration indelta-rsby using an OpenDAL scheme.In the Python wheel, the following services are enabled via OpenDAL:
fs(filesystem)memorys3gcs(Google Cloud Storage)azblob(Azure Blob Storage)azdls(Azure Data Lake Storage)oss(Alibaba Cloud OSS)obs(Huawei Cloud OBS)cos(Tencent Cloud COS)tos(ByteDance TOS)b2(Backblaze B2)swift(OpenStack Swift)webhdfswebdavftpsftphf(HuggingFace Hub)
Perform data operations with Delta Lake
mainUnlike traditional data lakes where only appending data is straightforward, Delta Lake supports a full range of data manipulation operations (DML) performed efficiently under the hood:
- Appends: Adding new data to the table.
- Upserts: Updating existing records or inserting new ones.
- Deletes: Removing specific rows of data.
- Replace where: Replacing a subset of data based on a predicate.
Ensure data reliability with Delta Lake transactions
mainDelta Lake uses transactions to ensure that write operations are safe and do not cause downtime or data corruption. Transactions in Delta Lake guarantee that operations:
- Are Atomic: They either finish completely or do not run at all.
- Are Isolated: They are executed in a serial manner and do not conflict with other transactions.
- Maintain Integrity: They do not corrupt the table or violate table constraints.
This prevents common data lake issues such as schema mismatches during appends, reading incorrect/partial data during active writes, and data loss from conflicting concurrent transactions.
Understand Delta Lake ACID transaction properties
mainDelta Lake provides ACID (Atomicity, Consistency, Isolation, Durability) guarantees to ensure data reliability, which are typically absent in standard data lakes.
- Atomicity: Transactions either fully complete or fully fail. Delta Lake writes data files first and only creates a transaction log entry upon success. If a job fails mid-write, the partial data is ignored by the table and can be cleaned up using the
vacuumoperation. - Consistency: Ensures data integrity through Schema enforcement (verifying new data matches the existing table schema) and Column constraints (rejecting data that violates specific requirements, such as a positive value for an
agecolumn). Note that schema evolution must be enabled to allow schema changes. - Isolation: Transactions are applied sequentially using monotonically increasing transaction files (e.g.,
0000...00.json,0000...01.json). Delta Lake uses concurrency control to manage simultaneous user operations. - Durability: Once a transaction is committed, it remains persisted in the underlying storage (e.g., Azure Blob Storage, S3) even in the event of service outages or computation cluster crashes.
- Atomicity: Transactions either fully complete or fully fail. Delta Lake writes data files first and only creates a transaction log entry upon success. If a job fails mid-write, the partial data is ignored by the table and can be cleaned up using the
Understand Delta Lake Transactions
mainTransactions in Delta Lake are operations that change the state of a table and record descriptive metadata entries in the
_delta_logtransaction log.Examples of transactions include:
- Appending data to a table
- Deleting rows
- Upserting rows
- Overwriting rows
- Compacting small files
- Rearranging data (e.g., Z Ordering)
Key Characteristics:
- Write operations are transactions: Any operation that changes underlying files and adds metadata to the log is a transaction.
- Reads are not transactions: Reading data does not result in new entries in the transaction log.
- Single-table scope: Delta Lake transactions are only valid for a single table; multi-table transactions are not supported.
- MVCC Model: Delta Lake uses Multi-Version Concurrency Control (MVCC). Writers operate optimistically and will abandon a transaction if a conflict is detected at the end of the process.