-
-
Save hubte1g/50a083805f86b720dafe 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