function hive_check($hive_host,$hive_port,$hive_send_timeout,$hive_recv_timeout) { $shell_ret=0; try{ $transport = new TSocket($hive_host,$hive_port); $transport->setSendTimeout($hive_send_timeout); $transport->setRecvTimeout($hive_recv_timeout); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('show databases'); //var_dump($client->fetchAll()); }catch(Exception $e){ $shell_ret=1; } $transport->close(); return $shell_ret; }
/** * execute * @param $str * @return bool * @throws HiveExecuteException */ public function execute($str) { // あるクエリーの前に実行したいHQLが存在する場合 // 「;」で区切って連続実行させる // ex) use my_db; select * from my_db $queries = preg_split('/;/', $str); foreach ($queries as $query) { $query = str_replace(array('\\r\\n', '\\n', '\\r'), ' ', $query); $query = ltrim($query); if ($query == '') { return false; } try { parent::execute($query); } catch (Exception $e) { $msg = $e->getMessage(); $msg = "HiveExecuteException: Execute Error:: {$msg} query:: {$query} "; throw new HiveExecuteException($msg); } } }
$etc = new Etc(); $auth = new Authorize(); if (!$_GET['database'] || '' == $_GET['database']) { die($lang['dieTableChoose']); } else { include_once 'templates/style.css'; //echo '<div class="container">'; //echo '<div class="span1">'; //echo '</div>'; //echo '<div class="span10">'; echo '<br />' . $_GET['database'] . '<i class=icon-backward></i> <a href=dbStructure.php?database=' . $_GET['database'] . ' target="right">' . $lang['back'] . '</a><br /><br />'; include_once 'templates/sql_query_navi.html'; echo "<br /><br />"; $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $sql = 'use `' . $_GET['database'] . '`'; //echo $sql.'<br /><br />'; $client->execute($sql); //$client->fetchOne(); $sql = 'desc formatted ' . $_GET['table']; $client->execute($sql); $array_desc_table = $client->fetchAll(); $array_desc_table_1 = $etc->GetTableDetail($array_desc_table, "1"); $array_desc_table_4 = @$etc->GetTableDetail($array_desc_table, "4"); if ($array_desc_table_4[0] != "") { $array_desc_desc = @array_merge($array_desc_table_1, $array_desc_table_4); } else { $array_desc_desc = $array_desc_table_1; }
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $hql = $_GET['sql']; if (substr($hql, -1) == ";") { $hql = substr($hql, 0, -1); } $hql = "EXPLAIN EXTENDED " . $hql; echo "<br>"; echo "<center><input type=button value=\"Close Window\" onclick='window.close()'></center>"; echo "<hr>"; try { $res = $client->execute($hql); $array = $client->fetchAll(); foreach ($array as $k => $v) { $echo .= str_replace(" ", " ", $v) . "<br />"; } echo "<font color=red>HQL Syntax OK!!!<br><br></font>"; echo $echo; } catch (Exception $e) { $echo = $e->getMessage(); $tmp = explode("FAILED", $echo); $echo = $tmp[0] . "FAILED <font color=red>" . $tmp[1] . "<font>"; echo "Exception: " . $echo; } echo "<hr>";
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; if (!@$_GET['schema']) { die($lang['dieSchemaChoose']); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_GET['schema']); $sql = "DROP SCHEMA IF EXISTS " . $_GET['schema']; $client->execute($sql); echo "<script>alert('" . $lang['dropSchemaSuccess'] . "');window.location='index.php?frame=right'</script>"; $transport->close(); }
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); #$client->execute('add jar '.$env['hive_jar']); $status = $client->getSchema(); //var_dump($status); echo "<<< <a href=index.php?frame=right>" . $lang['back'] . "</a><br><br>"; echo 'Field Schemas: ' . $status->fieldSchemas . '<br />'; echo 'Properties: ' . $status->properties . '<br />'; $transport->close();
<?php include_once "config.inc.php"; include_once "templates/style.css"; if (!@$_GET['database']) { die($lang['dieDatabaseChoose']); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_GET['database']); $client->execute($env['showTables']); $db_array = $client->fetchAll(); $db_array = array_reverse($db_array); $i = 0; echo '<br/>'; echo "<table class=\"table table-hover\">"; echo "<thead><tr>"; echo '<td><a href="javascript:showsd(\'dbList.php\',\'index.php?frame=right\')" target=left><i class="icon-backward"></i> ' . $lang['back'] . '</a></td>'; echo "</tr></thead>"; while ('' != @$db_array[$i]) { echo "<tbody><tr><td>"; echo '<a href=sqlQuery.php?table=' . $db_array[$i] . '&database=' . $_GET['database'] . ' target="right"><i class="icon-th-list"></i>' . $db_array[$i] . '</a>'; echo "</td></tr></tbody>"; $i++; } echo "<tfoot><tr>"; echo '<td><a href="javascript:showsd(\'dbList.php\',\'index.php?frame=right\')" target=left><i class="icon-backward"></i> ' . $lang['back'] . '</a></td>'; echo "</tr></tfoot>"; echo "</table>";
$hive_host=$argv[1]; $hive_port=$argv[2]; //defaultは常に出力 print("default\n"); /////////////////////////////////////////////////////////////////// //データベース名取得 /////////////////////////////////////////////////////////////////// $shell_ret=0; try{ $transport = new TSocket($hive_host,$hive_port); $transport->setSendTimeout(HIVE_SEND_TIMEOUT); $transport->setRecvTimeout(HIVE_RECV_TIMEOUT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute("show databases"); // HiveQL結果出力 while( ($arr=$client->fetchN(10000)) ){ foreach ($arr as $row){ if ( $row == "default" ){ continue; } print("$row\n"); } } $transport->close(); }catch(Exception $e){
<?php include_once 'config.inc.php'; if (!$_GET['database']) { $file = "js/hiveudfs.txt"; $array = file($file); } else { if (!$_GET['table']) { $file = "js/hiveudfs.txt"; $array = file($file); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_GET['database']); $sql = "desc " . $_GET['table']; $client->execute($sql); $array_desc_table = $client->fetchAll(); $i = 0; while ('' != @$array_desc_table[$i]) { $array_desc = explode(' ', $array_desc_table[$i]); $array_desc_desc[$i] = $array_desc[0]; $i++; } $array_table = array($_GET['table']); $file = "js/hiveudfs.txt"; $array = file($file); $array = array_merge($array, $array_desc_desc); $array = array_merge($array, $array_table); }
// Licensed to the Apache Software Foundation (ASF) under one // or more contributor license agreements. See the NOTICE file // distributed with this work for additional information // regarding copyright ownership. The ASF licenses this file // to you under the Apache License, Version 2.0 (the // "License"); you may not use this file except in compliance // with the License. You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // set THRIFT_ROOT to php directory of the hive distribution $GLOBALS['THRIFT_ROOT'] = '/lib/php/'; // load the required files for connecting to Hive 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'; // Set up the transport/protocol/client $transport = new TSocket('localhost', 10000); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); // run queries, metadata calls etc $client->execute('SELECT * from src'); var_dump($client->fetchAll()); $transport->close();
sql = "select count(*) from exampledb.exampletable where a=1" hostname = "192.168.1.49" port = "10000" username = "" password = "" database = "example_hive_database" table = "example_hive_table" ; type can be set to csv and sql, but suggest to use csv type = "csv" udf = "/opt/modules/hive/hive-0.7.1/lib/hive-contrib-0.7.1.jar" terminator = "," */ $db = mysql_connect($ini['mysql']['hostname'] . ":" . $ini['mysql']['port'], $ini['mysql']['username'], $ini['mysql']['password']); $transport = new TSocket($ini['hive']['hostname'], $ini['hive']['port']); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $filename = "/tmp/" . sha1(time()) . ".csv"; echo $hql = "INSERT OVERWRITE LOCAL DIRECTORY '/tmp/tmp0' " . $ini['hive']['sql']; $transport->open(); $client->execute('add jar ' . $ini['hive']['udf']); $client->execute($hql); $fd = fopen("/tmp/tmp0/000000_0", "rb"); $fp = fopen($filename, "wb"); while (!feof($fd)) { $str = trim(fgets($fd, 4096)); $str = str_replace("", $ini['mysql']['terminator'], $str) . "\n"; fwrite($fp, $str); unset($str); } fclose($fp); fclose($fd);
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('show databases'); $db_array = $client->fetchAll(); $i = 0; echo '<br />'; echo '<table class="table table-hover">'; if ($_SESSION['role'] == "superadmin") { while ('' != @$db_array[$i]) { echo "<tr>"; echo '<td><a href="javascript:showsd(\'tableList.php?database=' . $db_array[$i] . '\',\'dbStructure.php?database=' . $db_array[$i] . '\')" target="left"><i class="icon-zoom-in"></i>' . $db_array[$i] . '</a></td>' . "\n"; echo "</tr>"; $i++; } } else { $onlydb = explode(",", $_SESSION['onlydb']); while ('' != @$db_array[$i]) { if (in_array($db_array[$i], $onlydb)) { echo "<tr>"; echo '<td><a href="javascript:showsd(\'tableList.php?database=' . $db_array[$i] . '\', \'dbStructure.php?database=' . $db_array[$i] . '\')" target="left"><i class="icon-zoom-in"></i>' . $db_array[$i] . '</a></td>' . "\n"; echo "</tr>"; } $i++; } }
if ( empty($argv[1]) or empty($argv[2]) or empty($argv[3]) ){ //print "ERR:parameter error\n"; exit(1); } $hive_host=$argv[1]; $hive_port=$argv[2]; $dbname=$argv[3]; /////////////////////////////////////////////////////////////////// //データベース名取得 /////////////////////////////////////////////////////////////////// $shell_ret=0; try{ $transport = new TSocket($hive_host,$hive_port); $transport->setSendTimeout(HIVE_SEND_TIMEOUT); $transport->setRecvTimeout(HIVE_RECV_TIMEOUT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute("create database $dbname"); $transport->close(); }catch(Exception $e){ $msg=$e->getMessage(); $shell_ret=1; } exit($shell_ret); ?>
} break; case "keyword": $keyword = $_REQUEST['keyword']; if ($keyword == "") { exit; } mysql_connect("localhost", "root", "123456"); mysql_select_db("biglaw"); $sql = "select number from cache WHERE keyword = '" . $keyword . "'"; $query = mysql_query($sql); $rows = mysql_num_rows($query); if ($rows == 0) { $transport = new TSocket("localhost", 10000); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); //show tables //$client->execute('select * from `BigLaw` WHERE `mcase` like '.$keyword.' or mcontext like '.$keyword.' or mcourt like '.$keyword.' or mnumber like '.$keyword.' or mtype like '.$keyword); $client->execute('select key from `BigLaw` WHERE `mcontext` like "%' . $keyword . '%"'); $rows = $client->fetchAll(); $result = array(); foreach ($rows as $row) { $result[] = $row; $sql = "insert into `cache`(`keyword`,`number`) values('" . $keyword . "' , '" . $row . "') ;"; mysql_query($sql); /*echo "<fieldset>"; print_r( str_replace( '\n' , "<br />" ,$row )); echo "<br />"; echo "</fieldset>";*/ }
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; $etc = new Etc(); if (!@$_GET['database']) { die($lang['dieDatabaseChoose']); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_GET['database']); echo '<div class="container">'; echo '<div class="span10">'; if (!@$_GET['table']) { die($lang['dieTableChoose']); } else { $sql = "desc formatted " . $_GET['table']; $client->execute($sql); $arr = $client->fetchAll(); $arr = $etc->GetTableDetail($arr, "2"); $j = 0; foreach ($arr as $k => $v) { $array_desc = explode(':', $v); $array_desc_desc['key'][$j] = trim($array_desc[0]); $array_desc_desc['value'][$j] = trim($array_desc[1]); if ($array_desc_desc['value'][$j] == 'MANAGED_TABLE' || $array_desc_desc['value'][$j] == 'INDEX_TABLE') { $tmp['key'] = $array_desc_desc['key'][$j]; $tmp['value'] = $array_desc_desc['value'][$j]; }
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; if (!@$_POST['newschemaname'] || @$_POST['newschemaname'] == "") { die($lang['invalidEntry']); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $sql = "CREATE SCHEMA IF NOT EXISTS " . $_POST['newschemaname'] . " COMMENT '" . $_POST['newschemacomment'] . "'"; $client->execute($sql); echo $sql; //$db_array = $client->fetchOne(); echo '<script>alert(\'' . $lang['createSchemaSuccess'] . '\');window.location=\'index.php?frame=right\';</script>'; $transport->close(); }
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); #$client->execute('add jar '.$env['hive_jar']); $status = $client->getThriftSchema(); //var_dump($status); echo "<<< <a href=index.php?frame=right>" . $lang['back'] . "</a><br><br>"; echo 'Field Schemas: ' . $status->fieldSchemas . '<br />'; echo 'Properties: ' . $status->properties . '<br />'; $transport->close();
exit(1); } while(!feof($fp)){ $data = fgets($fp, 1024); $u_query.=$data; } fclose($fp); /////////////////////////////////////////////////////////////////// // Hive接続 /////////////////////////////////////////////////////////////////// $transport = new TSocket($hive_host,$hive_port); $transport->setSendTimeout(HIVE_SEND_TIMEOUT); $transport->setRecvTimeout(HIVE_RECV_TIMEOUT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); print "INF:hive server($hive_host:$hive_port) connect ok\n"; /////////////////////////////////////////////////////////////////// // 簡単なSQL文を発行(ログを認識させる為) /////////////////////////////////////////////////////////////////// try{ $client->execute("show tables"); }catch(Exception $e){ $msg=$e->getMessage(); print "ERR:$msg\n"; exit(1); } $res=$client->getQueryPlan(); $queryid=$res->queries[0]->queryId;
<?php include_once 'config.inc.php'; include_once 'templates/style.css'; if (!@$_POST['database']) { die($lang['dieDatabaseChoose']); } else { $transport = new TSocket(HOST, PORT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('use ' . $_POST['database']); if (!@$_POST['table_name']) { die($lang['dieTableChoose']); } else { if (!$_POST['confirm']) { echo "<form method=post>"; foreach ($_POST['table_name'] as $k => $v) { echo "drop table " . $v . "<br />\n"; echo "<input type=hidden name=table_name[] value=" . $v . " />\n"; } echo "<input type=hidden name=database value=" . $_POST['database'] . " />\n"; echo "<input type=hidden name=confirm value=1 /><br>\n"; echo "<input type=submit name=submit value=" . $lang['submit'] . " />"; echo " "; echo "<input type=button value=" . $lang['cancel'] . " onclick=\"window.location='dbStructure.php?database=" . $_POST['database'] . "';\">"; echo "</form>"; } else { if (is_array($_POST['table_name'])) { foreach ($_POST['table_name'] as $k => $v) { $sql = "drop table " . $v;
<?php define('ROOT', dirname(dirname(__FILE__))); require_once(ROOT."/config/app.php"); $GLOBALS['THRIFT_ROOT'] = DIR_HIVE_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'; $transport = new TSocket(HIVE_HOST, HIVE_PORT); $transport->setSendTimeout(HIVE_SEND_TIMEOUT); $transport->setRecvTimeout(HIVE_RECV_TIMEOUT); $protocol = new TBinaryProtocol($transport); $client = new ThriftHiveClient($protocol); $transport->open(); $client->execute('show tables'); var_dump($client->fetchAll()); $transport->close(); ?>