Skip to main content

A custom PySpark extension for writing data to DuckDB

Project description

DuckDB Extension for PySpark

Since DuckDB supports only a single writer at a time, writing directly from PySpark can lead to locking errors due to Spark's multi-worker write process.

This custom PySpark extension provides a reliable way to write DataFrames to DuckDB, ensuring smooth data transfer without concurrency issues.

Features

  • Seamlessly write PySpark DataFrames to DuckDB
  • Supports overwrite and append modes
  • Automatically detects and adds new columns when appending data
  • Simple integration with PySpark's DataFrameWriter API

Installation

You can install the package using pip:

pip install duckdb-spark


## Usage

```bash
from pyspark.sql import SparkSession
from duckdb_extension import register_duckdb_extension

spark = SparkSession.builder.appName("DuckDB Example").getOrCreate()

# Register the DuckDB extension
register_duckdb_extension(spark)

df=spark.read.csv("employe.csv",header=True)

# Use the custom extension to write the DataFrame to DuckDB and specify the table name
df.write.duckdb_extension(database="./company_database.duckdb", table_name="employe_tbl", mode="append")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duckdb_spark-1.0.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duckdb_spark-1.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file duckdb_spark-1.0.4.tar.gz.

File metadata

  • Download URL: duckdb_spark-1.0.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for duckdb_spark-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d71abadeb82c0ba9bd121c374edafbd55f3b4550c5d0b16188853aad2c69a7f5
MD5 32290492cb9fbefcc5c964b2c230d94b
BLAKE2b-256 431d419f5062d459a3d8bd9a2104e4189ef3d05a938a91c3fa680fc78f66ab13

See more details on using hashes here.

File details

Details for the file duckdb_spark-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: duckdb_spark-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for duckdb_spark-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 858c405f9ce2e822ce8306004f965841710ade3c2e1ec50b239b965ff0908c96
MD5 f678f57485aecc959b53abb04251eb55
BLAKE2b-256 93a18adafaba380897febe959bd84737bb612174fd327d83242933258f53f8e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page