Advertisement
Guest User

Untitled

a guest
Jun 6th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import org.apache.commons.lang.time.StopWatch;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7.  
  8. public class Test {
  9.     private static String driverName = "org.apache.hive.jdbc.HiveDriver";
  10.  
  11.     public static void main(String[] args) throws SQLException, InterruptedException {
  12.         try {
  13.             Class.forName(driverName);
  14.         } catch (ClassNotFoundException e){
  15.             System.out.println(e);
  16.             System.exit(1);
  17.         }
  18.         asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 1);
  19.         Thread.sleep(3000);
  20.         asyncExecute("alter table mobile_connections drop if exists partition (dt=20151124, msisdn_last_digit=2) purge", 2);
  21.         Thread.sleep(3000);
  22.         asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 3);
  23.         Thread.sleep(3000);
  24.         asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 4);
  25.     }
  26.  
  27.     private static void asyncExecute(String query, int threadNumber) {
  28.         Thread t = new Thread(new HiveQuery(query, threadNumber));
  29.         t.start();
  30.  
  31.     }
  32.  
  33.     private static class HiveQuery implements Runnable{
  34.         String query;
  35.         int threadNumber;
  36.  
  37.         public HiveQuery(String query, int threadNumber) {
  38.             this.query = query;
  39.             this.threadNumber = threadNumber;
  40.         }
  41.  
  42.         @Override
  43.         public void run() {
  44.             try (Connection connection = DriverManager.getConnection("jdbc:hive2://10.189.128.231:10000/default", "hdfs", "root");
  45.                  Statement stmt = connection.createStatement()){
  46.  
  47.                 StopWatch sw = new StopWatch();
  48.                 sw.start();
  49.                 System.out.println("Start " + threadNumber);
  50.                 stmt.execute(query);
  51.                 System.out.println("Finished " + threadNumber);
  52.                 sw.stop();
  53.                 System.out.println(threadNumber + " completed in : " + sw.getTime());
  54.                 System.out.println();
  55.             } catch (SQLException e) {
  56.                 e.printStackTrace();
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement