spark-sql做数据同步从大数据平台到关系数据库,采用jdbc方式同部数据表,要求关系数据库表不能重新创建,其代码说明如下:
jdbcDF.write \
.format("jdbc") \\
.mode("overwrite") \\
.***option("truncate", "true")*** \\
.option("url", "jdbc:db2:dbserver") \\
.option("dbtable", "schema.tablename") \\
.option("user", "username") \\
.option("password", "password") \\
.save()
以上同步查询“sql\core\src\main\scala\org\apache\spark\sql\execution\datasources\jdbc\JdbcUtils.scala”,文件
/**
def truncateTable(conn: Connection, table: String): Unit = {
val statement = conn.createStatement
try {
statement.executeUpdate(s"TRUNCATE TABLE $table")
} finally {
statement.close()
}
}
此清表为“TRUNCATE TABLE tabname”,但 db2 要求有immediate参数
问下:
1.如何添加immediate参数,或有其他方式可以清空表吗,能写delete吗?
2.或spark.sql 在DB2上怎么直接执行sql语句 “TRUNCATE TABLE tabname immediate” 或 “delete from tabname ”