Skip to content

Instantly share code, notes, and snippets.

Last active April 24, 2017 07:30
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Using the Hive Thrift Client in Java and Scala - an example
import junit.framework.TestCase;
import org.apache.hadoop.hive.service.HiveClient;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import java.util.List;
* Created by psamtani on 3/11/14.
public class TestThriftClientJava extends TestCase {
public void testThriftClient() throws TException {
final TSocket tSocket = new TSocket(HIVE_SERVER_LOCATION, 10098);
final TProtocol protocol = new TBinaryProtocol(tSocket);
final HiveClient client = new HiveClient(protocol);;
client.execute("show tables");
final List<String> results = client.fetchAll();
for (String result : results) {
import junit.framework.TestCase
import org.apache.hadoop.hive.service.HiveClient
import org.apache.thrift.transport.{TTransport, TSocket}
import org.apache.thrift.protocol.TBinaryProtocol
* Created by psamtani on 3/11/14.
* Requires the following maven packages:
* 1) org.apache.hive:hive-jdbc:0.12.0
class ThriftClientTest extends TestCase {
def testThriftClient() {
val transport = new TSocket(HIVE_SERVER_LOCATION, 10098)
val protocol = new TBinaryProtocol(transport)
val hiveClient = new HiveClient(protocol)
hiveClient.execute("show tables")
Copy link

asw456 commented Apr 1, 2014

does this work for both hiveserver and hiverserver2? If 2 then it requires SASL to be turned off? cheers

Copy link

no it doesn't worked.. I tried directly connecting instead of extending an interface or another class.

Here is my code

TTransport transport;
transport = new TSocket("remmote ip address", hiveport);;
TProtocol protocol = new TBinaryProtocol(transport);
HiveClient client = new HiveClient(protocol);
client.execute("show tables");
final List results = client.fetchAll();
for (String result : results) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment