New Contributor
Posts: 7
Registered: ‎12-26-2014

Hive Thrift Server - Empty result / Port Connection Problem

Hi Community & Cloudera Team


I want to access Hive (5.3) via PHP.



So it wanted to start the thrift server via:

hive --service hiveserver





org.apache.thrift.transport.TTransportException: Could not create ServerSocket on address



OK, seems already running.


Now I run my script:




//thrift php
$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__).'/thrift/src';
require_once( $GLOBALS['THRIFT_ROOT'].'/Thrift.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php' );

//hive thrift
require_once dirname(__FILE__).'/thrift/ThriftHive.php';

//open connection
$transport = new TSocket("localhost", 10000);
$protocol = new TBinaryProtocol($transport);
$client = new ThriftHiveClient($protocol);

//show tables
$client->execute('SHOW TABLES');
$tables = $client->fetchAll();
foreach ($tables as $name){
echo( " found: {$name}\n" );

//Query table
$client->execute('SHOW databases');


And the result is always nothing. No output.


So I try to start another server  on a diffrent port



hive --service hiveserver -p 10001


Now the I get data via PHP on port 10001


php test.php 
/root/thrift/src found: sample_07
 found: sample_08
testarray(1) {
  string(7) "default"


So my question:


Why do I get an empty result on port 10000?

How can I get data with the default port?


Maybe  I do something wrong?












PS: Source of Script and classes



Cloudera Employee
Posts: 509
Registered: ‎07-30-2013

Re: Hive Thrift Server - Empty result / Port Connection Problem

You should be using HiveServer2 instead of the old hiveserver. HS2 is supported by Cloudera and managed by Cloudera Manager, whereas the old hiveserver is not. HS2 runs on port 10000, so you might be using code that works with hiveserver but not with HS2.

For more details on how to use HS2's thrift API, please ask in the Hive forum.