I'd like to save a JSON to a table in MySQL.
After a bit of reading I found out that the path to load the data into mysql is json->dataframe->mysql.
{"name":"Johny","hobbies":["swiming","cooking"]}
{"name":"James","hobbies":["baseketball","fishing"]}
{"name":"Tom","hobbies":["singing","football"]}
I read the json file be using below command:
val df = sqlContext.read.json("test.json")
df.show()
df.printSchema()
and output:
+--------------------+-----+
| hobbies| name|
+--------------------+-----+
| [swiming, cooking]|Johny|
|[baseketball, fis...|James|
| [singing, football]| Tom|
+--------------------+-----+
root
|-- hobbies: array (nullable = true)
| |-- element: string (containsNull = true)
|-- name: string (nullable = true)
When using below command:
df.registerTempTable("mytable")
sqlContext.
sql("SELECT * FROM mytable").
write.
mode(SaveMode.Append).
jdbc(url,"jsontest",prop)
I am getting below error:
java.lang.IllegalArgumentException: Can't get JDBC type for array
How can I convert the array of strings to one string like swiming, cooking in the DataFrame?