forked from pauldeschacht/impala-java-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImpalaConnectTest.java
More file actions
71 lines (56 loc) · 2.06 KB
/
ImpalaConnectTest.java
File metadata and controls
71 lines (56 loc) · 2.06 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.ImpalaConnectTest;
import java.util.List;
import org.apache.thrift.transport.*;
import org.apache.thrift.protocol.*;
import com.cloudera.impala.thrift.*;
import com.cloudera.beeswax.api.*;
public class ImpalaConnectTest
{
private static String host="nceoricloud02";
private static int port=21000;
private static String stmt="SELECT * FROM document LIMIT 5";
public static void main(String [] args)
{
if (args.length < 3) {
System.out.println("Usage: ImpalaConnectTest host port");
return;
}
try {
host = args[0];
port = Integer.parseInt(args[1]);
stmt = args[2];
//open connection
TSocket transport = new TSocket(host,port);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
//connect to client
ImpalaService$Client client = new ImpalaService.Client(protocol);
client.PingImpalaService();
Query query = new Query();
query.setQuery(stmt); // hive statement: SELECT * FROM table LIMIT 10;
QueryHandle handle = client.query(query);
boolean done = false;
while(done == false) {
Results results = client.fetch(handle,false,100);
QueryState queryState = client.get_state(handle);
/*
while(queryState != ImpalaService$Client.FINISHED) {
//sleep(0.5)
queryState = client.get_state(query);
}
*/
List<String> data = results.data;
for(int i=0;i<data.size();i++) {
System.out.println(data.get(i));
}
if(results.has_more==false) {
done = true;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}