Created
September 1, 2024 17:07
-
-
Save Darkflib/14d263226ab3415f68b1260a5023177d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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