This repository was archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathThriftHiveClientEx.php
More file actions
81 lines (68 loc) · 1.96 KB
/
ThriftHiveClientEx.php
File metadata and controls
81 lines (68 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* ThriftHiveClientEx
*
* デフォルトのThriftHiveClientの場合、
* socketのopen & close がTSocketクラスでしか行えない。
*
* TSocketインスタンスは、ThriftHiveClientインスタンスが
* 参照しているがopenするメソッドがない為、ThriftHiveClientを
* 継承してopen & close 用のメソッド作成した。
*
* @uses ThriftHiveClient
* @author noto
*/
class ThriftHiveClientEx extends ThriftHiveClient {
/**
* __construct
* @param $input
* @param null $output
*/
public function __construct($input, $output = null) {
parent::__construct($input, $output);
}
/**
* open
* @return void
*/
public function open() {
if (!$this->input_->getTransport()->isOpen()) {
$this->input_->getTransport()->open();
}
}
/**
* close
* @return void
*/
public function close() {
if ($this->input_->getTransport()->isOpen()) {
$this->input_->getTransport()->close();
}
}
/**
* 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);
}
}
}
}
class HiveExecuteException extends Exception {
}