So far, I am able to read dataframe from Teradata using Teradata jdbc connector for Spark. Syntax for reading is as follows :
val df = hc.read.format("jdbc").options( Map( "url" -> url, "dbtable" -> (sel * from tableA) as data, "driver" -> "com.teradata.jdbc.TeraDriver" ) ).load() where hc = hiveContext, url = connection url for teradata
I want to save a dataframe to Teradata table. I tried using the above syntax by changing dbtable to insert statement ,
val df = hc.read.format("jdbc").options( Map( "url" -> url, "dbtable" -> (insert into db.tabA values (1,2,3)) as data, "driver" -> "com.teradata.jdbc.TeraDriver" ) ).load() But the above statement gave me an error :
Error: Exception in thread "main" java.sql.SQLException: [Teradata Database] [TeraJDBC 15.10.00.22] [Error 3706] [SQLState 42000] Syntax error: expected something between '(' and the 'insert' keyword. I want to save a dataframe to Teradata in Spark, what is the best possible way of doing it?
"dbtable" -> "insert into db.tabA values (1,2,3)", but I think there's something else you'll have to check: I'm not a Spark expert, but it looks strange that you have to use a "read" method to "write" into a database.