Skip to main content

No project description provided

Project description

spark_sql_to_sqlite

Easily save a Spark dataframe into a SQLite database.

Why do you need it

Although you can use jdbc with Spark to write to SQLite, this method is error prone, and doesn't handle complex data types such as Map, Struct and Array.

spark_sql_to_sqlite automatically converts these complex data types to json, which can be used in SQLite queries using standard json functions such as json_extract.

It also has sensible defaults to create or replace the SQLite database and table(s) as needed.

How To Use

You can use this on Spark environments such as Databricks, where you have a spark variable available that represents the SparkContext.

Install it as follows:

%pip install spark-sql-to-sqlite

Then import it as follows:

from spark_sql_to_sqlite import spark_sql_to_sqlite

You can now use it as follows:

spark_sql_to_sqlite("SELECT * from {catalog}.{schema}.{table}", path_to_sqlite_db, table_name)

Example:

spark_sql_to_sqlite(spark, "SELECT * FROM hive_metastore.fire.bronze", "/tmp/fire.db", "bronze")

The above command will create a SQLite database at /tmp/fire.db if it doesn't already exists. It will create or replace the bronze table in this database and overwrite it with the results of the Spark SQL query

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

spark_sql_to_sqlite-0.7.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file spark_sql_to_sqlite-0.7.tar.gz.

File metadata

  • Download URL: spark_sql_to_sqlite-0.7.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.1 keyring/23.1.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.7

File hashes

Hashes for spark_sql_to_sqlite-0.7.tar.gz
Algorithm Hash digest
SHA256 3ccbf15dd8e8736311b69917cff1977721a0c874f230bc9e92a2713ed73f26e5
MD5 f7fa70bad33376730e4f525b1de7a5b5
BLAKE2b-256 5e1059f844aa399f2b323c028b9f069498d57e8bd5f77e2cebba82e2463c0556

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