@@ -43,6 +43,29 @@ class JDBCWriteSuite extends FunSuite with BeforeAndAfter {
4343
4444 conn1 = DriverManager .getConnection(url1, properties)
4545 conn1.prepareStatement(" create schema test" ).executeUpdate()
46+ conn1.prepareStatement(" drop table if exists test.people" ).executeUpdate()
47+ conn1.prepareStatement(
48+ " create table test.people (name TEXT(32) NOT NULL, theid INTEGER NOT NULL)" ).executeUpdate()
49+ conn1.prepareStatement(" insert into test.people values ('fred', 1)" ).executeUpdate()
50+ conn1.prepareStatement(" insert into test.people values ('mary', 2)" ).executeUpdate()
51+ conn1.prepareStatement(" drop table if exists test.people1" ).executeUpdate()
52+ conn1.prepareStatement(
53+ " create table test.people1 (name TEXT(32) NOT NULL, theid INTEGER NOT NULL)" ).executeUpdate()
54+ conn1.commit()
55+
56+ TestSQLContext .sql(
57+ s """
58+ |CREATE TEMPORARY TABLE PEOPLE
59+ |USING org.apache.spark.sql.jdbc
60+ |OPTIONS (url ' $url1', dbtable 'TEST.PEOPLE', user 'testUser', password 'testPass')
61+ """ .stripMargin.replaceAll(" \n " , " " ))
62+
63+ TestSQLContext .sql(
64+ s """
65+ |CREATE TEMPORARY TABLE PEOPLE1
66+ |USING org.apache.spark.sql.jdbc
67+ |OPTIONS (url ' $url1', dbtable 'TEST.PEOPLE1', user 'testUser', password 'testPass')
68+ """ .stripMargin.replaceAll(" \n " , " " ))
4669 }
4770
4871 after {
@@ -114,5 +137,17 @@ class JDBCWriteSuite extends FunSuite with BeforeAndAfter {
114137 df2.insertIntoJDBC(url, " TEST.INCOMPATIBLETEST" , true )
115138 }
116139 }
117-
140+
141+ test(" INSERT to JDBC Datasource" ) {
142+ TestSQLContext .sql(" INSERT INTO TABLE PEOPLE1 SELECT * FROM PEOPLE" )
143+ assert(2 == TestSQLContext .jdbc(url1, " TEST.PEOPLE1" , properties).count)
144+ assert(2 == TestSQLContext .jdbc(url1, " TEST.PEOPLE1" , properties).collect()(0 ).length)
145+ }
146+
147+ test(" INSERT to JDBC Datasource with overwrite" ) {
148+ TestSQLContext .sql(" INSERT INTO TABLE PEOPLE1 SELECT * FROM PEOPLE" )
149+ TestSQLContext .sql(" INSERT OVERWRITE TABLE PEOPLE1 SELECT * FROM PEOPLE" )
150+ assert(2 == TestSQLContext .jdbc(url1, " TEST.PEOPLE1" , properties).count)
151+ assert(2 == TestSQLContext .jdbc(url1, " TEST.PEOPLE1" , properties).collect()(0 ).length)
152+ }
118153}
0 commit comments