Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.lang.time.StopWatch;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Test {
- private static String driverName = "org.apache.hive.jdbc.HiveDriver";
- public static void main(String[] args) throws SQLException, InterruptedException {
- try {
- Class.forName(driverName);
- } catch (ClassNotFoundException e){
- System.out.println(e);
- System.exit(1);
- }
- asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 1);
- Thread.sleep(3000);
- asyncExecute("alter table mobile_connections drop if exists partition (dt=20151124, msisdn_last_digit=2) purge", 2);
- Thread.sleep(3000);
- asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 3);
- Thread.sleep(3000);
- asyncExecute("Select count(distinct in_info_msisdn) from mobile_connections where dt=20151124 and msisdn_last_digit=2", 4);
- }
- private static void asyncExecute(String query, int threadNumber) {
- Thread t = new Thread(new HiveQuery(query, threadNumber));
- t.start();
- }
- private static class HiveQuery implements Runnable{
- String query;
- int threadNumber;
- public HiveQuery(String query, int threadNumber) {
- this.query = query;
- this.threadNumber = threadNumber;
- }
- @Override
- public void run() {
- try (Connection connection = DriverManager.getConnection("jdbc:hive2://10.189.128.231:10000/default", "hdfs", "root");
- Statement stmt = connection.createStatement()){
- StopWatch sw = new StopWatch();
- sw.start();
- System.out.println("Start " + threadNumber);
- stmt.execute(query);
- System.out.println("Finished " + threadNumber);
- sw.stop();
- System.out.println(threadNumber + " completed in : " + sw.getTime());
- System.out.println();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement