I am trying to write a Spark dataframe to a sqlite3 database in Python using sqlite-jdbc from xerial and this example. I am getting the error
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: test)
The database file hello.db
is actually created with a table test
which has the schema
sqlite> .schema test
CREATE TABLE test (age BIGINT , name TEXT );
I am running it with spark-submit --jars ../extras/sqlite-jdbc-3.8.11.2.jar example.py
in order for it to find the driver.
I am running Spark 1.6.0.
(Hopefully) reproducible example
import os
os.environ["SPARK_HOME"] = "/usr/lib/spark"
import findspark
findspark.init()
from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext
config = {
"spark.cores.max": "5",
"spark.master" : "spark://master2:7077",
"spark.python.profile": "false",
"spark.ui.enabled": "false",
"spark.executor.extraClassPath": "../extras/sqlite-jdbc-3.8.11.2.jar",
"spark.driver.extraClassPath": "../extras/sqlite-jdbc-3.8.11.2.jar",
"spark.jars": "../extras/sqlite-jdbc-3.8.11.2.jar"
}
conf = SparkConf()
for key, value in config.iteritems():
conf = conf.set(key, value)
sc = SparkContext(appName="test", conf=conf)
sqlcontext = SQLContext(sc)
d = [{'name': 'Alice', 'age': 31}]
df = sqlcontext.createDataFrame(d)
url = "jdbc:sqlite:hello.db"
df.write.jdbc(url=url, table="test", mode="overwrite", properties={"driver":"org.sqlite.JDBC"})