Last active
April 24, 2017 07:30
-
-
Save ZenBowman/9492608 to your computer and use it in GitHub Desktop.
Using the Hive Thrift Client in Java and Scala - an example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
tSocket.open(); | |
client.execute("show tables"); | |
final List<String> results = client.fetchAll(); | |
for (String result : results) { | |
System.out.println(result); | |
} | |
tSocket.close(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
transport.open() | |
hiveClient.execute("show tables") | |
hiveClient.fetchAll().toArray.foreach(Console.println(_)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
HiveClient client = new HiveClient(protocol);
client.execute("show tables");
final List results = client.fetchAll();
for (String result : results) {
System.out.println(result);
}
transport.close();