Skip to content

Instantly share code, notes, and snippets.

@Darkflib
Created September 1, 2024 17:07
Show Gist options
  • Save Darkflib/14d263226ab3415f68b1260a5023177d to your computer and use it in GitHub Desktop.
Save Darkflib/14d263226ab3415f68b1260a5023177d to your computer and use it in GitHub Desktop.
from pyspark.sql import SparkSession
# Initialize a Spark session
spark = SparkSession.builder \
.appName("Read SQLite with PySpark") \
.config("spark.jars", "/path/to/sqlite-jdbc-3.34.0.jar") \
.getOrCreate()
# Define the JDBC URL for the SQLite database
jdbc_url = "jdbc:sqlite:/path/to/example.db"
# Define the properties
connection_properties = {
"driver": "org.sqlite.JDBC"
}
# Load the data into a DataFrame
df = spark.read.jdbc(url=jdbc_url, table="my_table", properties=connection_properties)
# Show the DataFrame
df.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment