2017-09-27 9 views
0
나는 Vertica의 테이블에 *를 쿼리 일부 선택 실행 인해 반복에 MySQL의 table.But에 사람들을 둘 필요가

에 배치하여 MySQL의 테이블에 vertcicadb 테이블에서 큰 데이터를로드 그것은 매우 느립니다. 훨씬 더 빠른 프로세스가 무엇입니까? 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

나는 내가 그것을 찬성 투표했다 .. 답변 너무 좋아한다. 필드/레코드 분리 기호 (예 : CTRL-A 및 CTRL-B)와 vsql과 mysqlimport 사이의 명명 된 파이프로 인쇄 할 수없는 문자를 사용할 수 있습니다. – mauro