-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Thrift Hive
More file actions
56 lines (45 loc) · 1.66 KB
/
Java Thrift Hive
File metadata and controls
56 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.List;
import org.apache.hadoop.hive.service.HiveClient;
import org.apache.hadoop.hive.service.HiveServerException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
public class thrift_hive_java {
private static String HOST = "127.0.0.1";
private static int PORT = 10000;
public static void main(String[] args)
{
TTransport transport = new TSocket(HOST, PORT);
TProtocol protocol = new TBinaryProtocol(transport);
HiveClient client = new HiveClient(protocol);
try {
long time1 = System.currentTimeMillis();
transport.open();
client.execute("select a, b, c from tb where a='' and b='' limit 10");
List<String> list = client.fetchAll();
long time2 = System.currentTimeMillis();
String str = "";
for(int i = 0; i < list.size(); i++)
{
str = list.get(i);
System.out.println(str);
}
System.out.println("use time : " + (time2 - time1) + " ms." );
} catch (TTransportException e) {
e.printStackTrace();
} catch (HiveServerException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
try {
client.shutdown();
} catch (TException e) {
e.printStackTrace();
}
transport.close();
}
}