delta-rs

repository·main·Indexed 25 days ago

https://github.com/delta-io/delta-rs

A 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.

Tokens
66.9K
Snippets
164
Records
398
Agent score
85%

What's inside delta-rs

  1. Overview of Delta Lake usage

    main
    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.
  2. Overview of delta-rs

    main
    delta-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.
  3. Overview of the Python deltalake package

    main
    The deltalake Python package is a native implementation for reading, writing, and managing Delta Lake tables. It is built on top of the delta-rs Rust library and does not require Spark or a JVM. Because it uses Apache Arrow internally, it is compatible with Arrow-native libraries such as Pandas, DuckDB, and Polars.
  4. Understand Delta Lake performance advantages

    main

    Delta Lake provides performance optimizations over standard data lakes (like Parquet or CSV) through two primary mechanisms:

    1. 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.
    2. 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.

  5. Understand Delta Lake table architecture

    main

    A Delta table is composed of two main parts:

    1. Parquet files: These contain the actual data.
    2. _delta_log directory: 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.

  6. Supported languages and environments for Delta Lake

    main

    Delta 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.
  7. Understand Delta Lake File Skipping

    main

    Delta 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 BY without filters typically cannot benefit from file skipping.
    • Data Layout: The effectiveness of skipping depends on how data is distributed across files.
  8. Use OpenDAL storage backends in delta-rs

    main

    You 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 in delta-rs by using an OpenDAL scheme.

    In the Python wheel, the following services are enabled via OpenDAL:

    • fs (filesystem)
    • memory
    • s3
    • gcs (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)
    • webhdfs
    • webdav
    • ftp
    • sftp
    • hf (HuggingFace Hub)
  9. Perform data operations with Delta Lake

    main

    Unlike 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.
  10. Ensure data reliability with Delta Lake transactions

    main

    Delta 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.

  11. Understand Delta Lake ACID transaction properties

    main

    Delta 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 vacuum operation.
    • 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 age column). 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.
  12. Understand Delta Lake Transactions

    main

    Transactions in Delta Lake are operations that change the state of a table and record descriptive metadata entries in the _delta_log transaction 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.