Insert DataFrame into SQL table with AUTO_INCREMENT column
I have a MySQL table that contains a column AUTO_INCREMENT
:
CREATE TABLE features (
id INT NOT NULL AUTO_INCREMENT,
name CHAR(30),
value DOUBLE PRECISION
);
I created DataFrame
and wanted to insert it into this table.
case class Feature(name: String, value: Double)
val rdd: RDD[Feature]
val df = rdd.toDF()
df.write.mode(SaveMode.Append).jdbc("jdbc:mysql://...", "features", new Properties)
I get an error Column count doesnβt match value count at row 1
. If I remove the column id
it works. How can I insert this data into a table without changing the schema?
+3
source to share