批量装载数据
Posted sorliran
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了批量装载数据相关的知识,希望对你有一定的参考价值。
var srcDs="zjkvta"; var destDs = "loadgsdw"; function main(args) { copyData(srcDs, "F_ZJLRLC", destDs, "TEST_F_ZJLRLC"); } /** * * @param srcDs 源数据所在数据源名 * @param srcTableName 查询源数据SQL * @param destDs 转换的数据 * @param destTableName 转换的目的表数据 */ function copyData(srcDs, srcTableName, destDs, destTableName){ var logfile = sz.sys.getWorkDir() + "/log.txt"; println("开始抽取:"+srcTableName); var ds = sz.db.getDataSource(srcDs); var conn = ds.getConnection(); try { var stmt = conn.createStatement(); try { var ss = (new Date()).getTime(); var rs = stmt.executeQuery("select * from "+srcTableName); try{ var rowCount = loadTable(rs, destDs, destTableName); var ee = (new Date()).getTime(); var info = "耗时 " + (ee - ss); println("抽取完成:"+srcTableName+info+",迁移行数:"+rowCount); }finally{ rs.close(); } } finally { stmt.close(); } } finally { conn.close(); } } /** * */ function loadTable(srcResultSet, destDataSource, destTableName) { var ds = sz.db.getDataSource(destDataSource); try { var conn = ds.getConnection(); var realConn = conn.getSourceConnection().getConnection(); var bulkLoader = com.ddtek.jdbc.extensions.DDBulkLoadFactory.getInstance(realConn); try { bulkLoader.setTableName(destTableName); return bulkLoader.load(srcResultSet); } finally { bulkLoader.close(); } } finally { conn.close(); } }
以上是关于批量装载数据的主要内容,如果未能解决你的问题,请参考以下文章
使用标准库Ruby将数据标记到Elasticsearch批量中