Reputation: 614
I have a MySQL table which includes a column that is AUTO_INCREMENT
:
CREATE TABLE features (
id INT NOT NULL AUTO_INCREMENT,
name CHAR(30),
value DOUBLE PRECISION
);
I created a 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 the error, Column count doesn’t match value count at row 1
. If I delete the id
column it works. How could I insert this data into the table without changing the schema?
Upvotes: 5
Views: 5282
Reputation: 27455
You have to include an id
field in the DataFrame, but its value will be ignored and replaced with the auto-incremented ID. That is:
case class Feature(id: Int, name: String, value: Double)
Then just set id
to 0, or any number when you create a Feature
.
Upvotes: 4