2017-09-27 34 views
0

我需要運行一些SELECT *查詢Vertica的表,並把這些變成MySQL的 table.But由於反覆加載從vertcicadb表到MySQL表龐大的數據,這是非常slow.What可能是一個更快的進程?誰能向我解釋如何休眠或任何其他快速的過程可以用Java來實現?分批以最快的方式

import java.io.IOException; 
import java.sql.*; 


public class Main { 
public static void main(String args[]) throws SQLException, IOException, ClassNotFoundException { 
     try { 
      Class.forName("com.vertica.jdbc.Driver"); 
      Connection c = null; 
      Statement stmt = null; 

    c=DriverManager.getConnection("jdbc:vertica://host,user,pass); 
      stmt = c.createStatement(); 
      //File f2 = new File("/Users/pragati.ratan/Desktop/Kalyan.csv"); 
      //CSVWriter csvWriter = new CSVWriter(new FileWriter(f2), ','); 
      String sql = "select * from unified_global_dw.offnetwork_daily_burn_fact_v where date >= '2017-09-03 00:00:00';"; 
      ResultSet rs = stmt.executeQuery(sql); 
      //csvWriter.writeAll(rs, true); 


      Class.forName("com.mysql.jdbc.Driver"); 
      Connection c1 = null; 
      Statement stmt1 = null; 
      c1 = DriverManager.getConnection("jdbc:mysql://hostname/database", "user", "pass"); 
      // stmt1 = c1.createStatement(); 
      String sql1 = "insert into offnetwork_daily_burn (id,offer_id,date,latest_pull_on,burn) values (null,?,?,?,?)"; 
      PreparedStatement preparedStatement = c1.prepareStatement(sql1); 
      while (rs.next()) { 
       int offer_id = rs.getInt(2); 
       Date dateTime = rs.getDate(3); 
       Date datetime1 = rs.getDate(4); 
       double burn = rs.getDouble(5); 

       preparedStatement.setInt(1, offer_id); 
       preparedStatement.setDate(2, dateTime); 
       preparedStatement.setDate(3, datetime1); 
       preparedStatement.setDouble(4, burn); 

       preparedStatement.executeUpdate(); 


      } 
      c.close(); 
      c1.close(); 
     }catch (Exception e){ 
      e.printStackTrace(); 
     } 



     } 

} 

這裏是我的編碼,現在的代碼。

回答

1

這可能不是正確的答案,但!

爲什麼不試圖實現從主要大宗出口和進口都疊加麼?

Vertica的出口

vsql -U user -w password-H hosts -F ',' -At -c "SELECT * FROM schema.TableName"' > /tmp/TableName.csv 

MySQL的導入

mysqlimport --ignore-lines=1 \ 
      --fields-terminated-by=, \ 
      --local -u root \ 
      -p Database \ 
      TableName.csv 
+0

我喜歡你的答案所以..我也給予好評的。只是你可能要考慮一些額外的改進:使用VSQL和mysqlimport的之間的非打印字符作爲字段/記錄分隔符(例如CTRL-A和CTRL-B)和命名管道... – mauro