Specific data display from Hive Select *

I have been trying to retrieve data from my hadoop database using hive. I have checked that the thrift server is up and running and I am able to connect to the data via command line too. I can assure there’s nothing wrong with the setup. In the PHP thrift client, I am running the query and retrieving the result as $client->fetchAll() command. I am trying to locate the equivalent of fetch_array(MYSQLI_BOTH) for my hive client so that I can print specific columns from my table on the user interface. Here’s the code for your perusal:

$GLOBALS['THRIFT_ROOT'] = dirname(__FILE__) . '/lib';
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';

require_once dirname(__FILE__) . '/ThriftHiveClientEx.php';

$transport = new TSocket('localhost', 10001);
$transport->setSendTimeout(600 * 1000);
$transport->setRecvTimeout(600 * 1000);
$client = new ThriftHiveClientEx(new TBinaryProtocol($transport));

$client->execute("Select time, cardno from table1");
echo "< tr>";
echo "< td>" .$row[0]." < /td>";
echo "< /tr>";



I’ve tried a lot of things but nothing seems to work. The thrift server is running on the 10001 port so no connectivity issues. The above code gets me the complete first row from the table and display it on a single column. I’ve tried displaying

echo "< td>" .$row['time']." < /td>";

but that didn’t show anything. I used fetchN() and just fetch() as well but that didn’t print the output as well. I want only specific columns to choose from a wide variety of columns in the table. I’ve implemented the same thing in mysql and fetch_array(MYSQLI_BOTH) solved that purpose of mine. All the requires libraries imported in the beginning are available in the same directory where program is running. Please let me know if any other information is needed from my side. Looking forward to responses. Thanks in advance

I don’t know this lib but $row is not defined anywhere so it won’t show anything.

You should probs do something like

$row = $client->fetchAll();

I am currently doing that only but it’s of no use as well… Sorry my bad. I guess i wrote incomplete code. I have used $row=$client->fetchAll();

from select * statement, I intend to display specific columns using echo[‘column-name1’] ; echo[‘column-name2’] ; and so on…

What happens if you var_dump($row); after that line? (By convention, fetchAll should be returning an array of result rows. So you probably need a loop structure (foreach) to walk through them…)

Using foreach is giving me just the first literal of arrays.

what does var_dump tell you the result looks like?

var_dump with foreach gives me the literals. In general, it prints everything in a single column of the table.

Ok… show me your code and the output because i think we’ve crossed our signals at this point.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.