Related to save to JDBC, trying to import a text file and save to a Hive JDBC file for import by reporting tools.
We are running spark-1.5.1-bin-hadoop2.6 (master + 1 slave), the JDBC thrift server and the beeline client. They all seem to interconnect and communicate. From what I can understand, Hive is included in this release in the datanucleus jars. I have configured directories to hold the Hive files, but have no conf/hive-config.xml.
Simple input CSV file:
Administrator,FiveHundredAddresses1,92121
Ann,FiveHundredAddresses2,92109
Bobby,FiveHundredAddresses3,92101
Charles,FiveHundredAddresses4,92111
The users table has been pre-created in the beeline client using
CREATE TABLE users(first_name STRING, last_name STRING, zip_code STRING);
show tables; // it's there
For the scala REPL session on the master:
val connectionUrl = "jdbc:hive2://x.y.z.t:10000/users?user=blah&password="
val userCsvFile = sc.textFile("/home/blah/Downloads/Users4.csv")
case class User(first_name:String, last_name:String, work_zip:String)
val users = userCsvFile.map(_.split(",")).map(l => User(l(0), l(1), l(2)))
val usersDf = sqlContext.createDataFrame(users)
usersDf.count() // 4
usersDf.schema // res92: org.apache.spark.sql.types.StructType = StructType(StructField(first_name,StringType,true), StructField(last_name,StringType,true), StructField(work_zip,StringType,true))
usersDf.insertIntoJDBC(connectionUrl,"users",true)
OR
usersDf.createJDBCTable(connectionUrl, "users", true) // w/o beeline creation
OR
val properties = new java.util.Properties
properties.setProperty("user", "blah")
properties.setProperty("password", "blah")
val connectionUrl = "jdbc:hive2://172.16.3.10:10000"
contactsDf.write.jdbc(connectionUrl,"contacts", properties)
throws
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
java.sql.SQLException: org.apache.spark.sql.AnalysisException: cannot recognize input near 'TEXT' ',' 'last_name' in column type; line 1 pos
at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:296)
at org.apache.hive.jdbc.HiveStatement.executeUpdate(HiveStatement.java:406)
at org.apache.hive.jdbc.HivePreparedStatement.executeUpdate(HivePreparedStatement.java:119)
at org.apache.spark.sql.DataFrameWriter.jdbc(DataFrameWriter.scala:275)
at org.apache.spark.sql.DataFrame.insertIntoJDBC(DataFrame.scala:1629)
Any ideas where I'm going wrong? Can this version actually write JDBC files from a DataFrame?
Thanks for any help!
Jon