| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
|
|
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
|
|
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
|
|
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
提供apache hive相關應用的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
|
|
32 |
class hive{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
44 |
#參考資料:
|
|
|
45 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
46 |
*/
|
|
|
47 |
public function __call($method,$arguments){
|
|
|
48 |
|
|
|
49 |
#取得當前執行的函式
|
|
|
50 |
$result["function"]=__FUNCTION__;
|
|
|
51 |
|
|
|
52 |
#設置執行不正常
|
|
|
53 |
$result["status"]="false";
|
|
|
54 |
|
|
|
55 |
#設置執行錯誤
|
|
|
56 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
57 |
|
|
|
58 |
#設置所丟入的參數
|
|
|
59 |
$result["error"][]=$arguments;
|
|
|
60 |
|
|
|
61 |
#回傳結果
|
|
|
62 |
return $result;
|
|
|
63 |
|
|
|
64 |
}#function __call end
|
|
|
65 |
|
|
|
66 |
/*
|
|
|
67 |
#函式說明:
|
|
|
68 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
69 |
#回傳結果:
|
|
|
70 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
71 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
72 |
#$result["function"],當前執行的函式名稱.
|
|
|
73 |
#必填參數:
|
|
|
74 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
75 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
|
|
76 |
#參考資料:
|
|
|
77 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
78 |
*/
|
|
|
79 |
public static function __callStatic($method,$arguments){
|
|
|
80 |
|
|
|
81 |
#取得當前執行的函式
|
|
|
82 |
$result["function"]=__FUNCTION__;
|
|
|
83 |
|
|
|
84 |
#設置執行不正常
|
|
|
85 |
$result["status"]="false";
|
|
|
86 |
|
|
|
87 |
#設置執行錯誤
|
|
|
88 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
89 |
|
|
|
90 |
#設置所丟入的參數
|
|
|
91 |
$result["error"][]=$arguments;
|
|
|
92 |
|
|
|
93 |
#回傳結果
|
|
|
94 |
return $result;
|
|
|
95 |
|
|
|
96 |
}#function __callStatic end
|
|
|
97 |
|
|
|
98 |
/*
|
|
|
99 |
#函數說明:
|
|
|
100 |
#apache hive官方提供的PHP API
|
|
|
101 |
#回傳結果:
|
|
|
102 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
103 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
104 |
#$result["error"],陣列,錯訊訊息.
|
|
|
105 |
#$result["content"],執行完query的回傳內容.
|
|
|
106 |
#$result["qStr"],查詢的語句.
|
|
|
107 |
#必填參數:
|
|
|
108 |
#$conf["thrift_root"],字串,存有 hive 散布的 php THRIFT_ROOT 路徑.
|
|
|
109 |
$conf["thrift_root"]="";
|
|
|
110 |
#可省略參數:
|
|
|
111 |
#$conf["fileArgu"],字串,__FILE__的內容,預設為__FILE__.
|
|
|
112 |
#$conf["fileArgu"]=__FILE__;
|
|
|
113 |
#備註:
|
|
|
114 |
#建構中...,套件THRIFT有問題
|
|
|
115 |
*/
|
|
|
116 |
/*
|
|
|
117 |
function nativeQuery(&$conf=array()){
|
|
|
118 |
|
|
|
119 |
#初始化要回傳的結果
|
|
|
120 |
$result=array();
|
|
|
121 |
|
|
|
122 |
#取得當前執行的函數名稱
|
|
|
123 |
$result["function"]=__FUNCTION__;
|
|
|
124 |
|
|
|
125 |
#如果沒有參數
|
|
|
126 |
if(func_num_args()==0){
|
|
|
127 |
|
|
|
128 |
#設置執行失敗
|
|
|
129 |
$result["status"]="false";
|
|
|
130 |
|
|
|
131 |
#設置執行錯誤訊息
|
|
|
132 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
133 |
|
|
|
134 |
#回傳結果
|
|
|
135 |
return $result;
|
|
|
136 |
|
|
|
137 |
}#if end
|
|
|
138 |
|
|
|
139 |
#取得參數
|
|
|
140 |
$result["argu"]=$conf;
|
|
|
141 |
|
|
|
142 |
#如果 $conf 不為陣列
|
|
|
143 |
if(gettype($conf)!="array"){
|
|
|
144 |
|
|
|
145 |
#設置執行失敗
|
|
|
146 |
$result["status"]="false";
|
|
|
147 |
|
|
|
148 |
#設置執行錯誤訊息
|
|
|
149 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
150 |
|
|
|
151 |
#如果傳入的參數為 null
|
|
|
152 |
if($conf==null){
|
|
|
153 |
|
|
|
154 |
#設置執行錯誤訊息
|
|
|
155 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
156 |
|
|
|
157 |
}#if end
|
|
|
158 |
|
|
|
159 |
#回傳結果
|
|
|
160 |
return $result;
|
|
|
161 |
|
|
|
162 |
}#if end
|
|
|
163 |
|
|
|
164 |
#檢查參數
|
|
|
165 |
#函式說明:
|
|
|
166 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
167 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
168 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
169 |
#$result["function"],當前執行的函式名稱.
|
|
|
170 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
171 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
172 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
173 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
174 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
175 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
176 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
177 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
178 |
#必填寫的參數:
|
|
|
179 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
180 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
181 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
182 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("thrift_root");
|
|
|
183 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
184 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
185 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
186 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
187 |
#可以省略的參數:
|
|
|
188 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
189 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
190 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
191 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
192 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
193 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu");
|
|
|
194 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
195 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
196 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
197 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__);
|
|
|
198 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
199 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
200 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
201 |
#參考資料來源:
|
|
|
202 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
203 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
204 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
205 |
|
|
|
206 |
#如果檢查參數失敗
|
|
|
207 |
if($checkArguments["status"]=="false"){
|
|
|
208 |
|
|
|
209 |
#設置執行不正常
|
|
|
210 |
$result["status"]="false";
|
|
|
211 |
|
|
|
212 |
#設置執行錯誤
|
|
|
213 |
$result["error"]=$checkArguments;
|
|
|
214 |
|
|
|
215 |
#回傳結果
|
|
|
216 |
return $result;
|
|
|
217 |
|
|
|
218 |
}#if end
|
|
|
219 |
|
|
|
220 |
#如果檢查參數不通過
|
|
|
221 |
if($checkArguments["passed"]=="false"){
|
|
|
222 |
|
|
|
223 |
#設置執行不正常
|
|
|
224 |
$result["status"]="false";
|
|
|
225 |
|
|
|
226 |
#設置執行錯誤
|
|
|
227 |
$result["error"]=$checkArguments;
|
|
|
228 |
|
|
|
229 |
#回傳結果
|
|
|
230 |
return $result;
|
|
|
231 |
|
|
|
232 |
}#if end
|
|
|
233 |
|
|
|
234 |
#轉換 $conf["thrift_root"] 路徑為伺服器上的絕對路徑
|
|
|
235 |
#函數說明:
|
|
|
236 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
237 |
#回傳結果:
|
|
|
238 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
239 |
#$result["error"],錯誤訊息陣列.
|
|
|
240 |
#$result["function"],函數名稱.
|
|
|
241 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
242 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
243 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
244 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
245 |
#必填參數:
|
|
|
246 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
247 |
$conf["fileAccess::getInternetAddress"]["address"]=$conf["thrift_root"];
|
|
|
248 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
249 |
$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
250 |
#可省略參數:
|
|
|
251 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
252 |
$conf["fileAccess::getInternetAddress"]["userDir"]="true";
|
|
|
253 |
#備註:
|
|
|
254 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
255 |
$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
|
|
|
256 |
unset($conf["fileAccess::getInternetAddress"]);
|
|
|
257 |
|
|
|
258 |
#如果轉換路徑失敗
|
|
|
259 |
if($getInternetAddress["status"]=="false"){
|
|
|
260 |
|
|
|
261 |
#設置執行不正常
|
|
|
262 |
$result["status"]="false";
|
|
|
263 |
|
|
|
264 |
#設置執行錯誤
|
|
|
265 |
$result["error"]=$getInternetAddress;
|
|
|
266 |
|
|
|
267 |
#回傳結果
|
|
|
268 |
return $result;
|
|
|
269 |
|
|
|
270 |
}#if end
|
|
|
271 |
|
|
|
272 |
// set THRIFT_ROOT to php directory of the hive distribution
|
|
|
273 |
$GLOBALS['THRIFT_ROOT'] = $getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
274 |
|
|
|
275 |
#檢查檔案是否存在
|
|
|
276 |
#涵式說明:檢查多個檔案與資料夾是否存在.
|
|
|
277 |
#回傳的結果:
|
|
|
278 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
279 |
#$result["error"],錯誤訊息陣列.
|
|
|
280 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
281 |
#$result["allExist"],所有檔案皆存在的識別,"true"代表皆存在,"false"代表沒有全部都存在.
|
|
|
282 |
#$result["varName"][$i],爲第$i個資料夾或檔案的路徑與名稱。
|
|
|
283 |
#$result["varNameFullPath"][$i],爲第$i個資料夾或檔案的完整檔案系統路徑與名稱。
|
|
|
284 |
#$result["varNameWebPath"][$i],為第$i個資料夾或檔案的網址
|
|
|
285 |
#$result["varExist"][$i],爲第$i個資料夾或檔案是否存在,"true"代表存在,"false"代表不存在。
|
|
|
286 |
#必填參數:
|
|
|
287 |
#$conf["fileArray"],陣列字串,要檢查是否存在的檔案有哪些,須爲一維陣列數值。
|
|
|
288 |
$conf["fileAccess::checkMultiFileExist"]["fileArray"]=array($GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php',$GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php',$GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php',$GLOBALS['THRIFT_ROOT'] . '/packages/hive_metastore/metastore/ThriftHiveMetastore.php');
|
|
|
289 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
290 |
$conf["fileAccess::checkMultiFileExist"]["fileArgu"]=$conf["fileArgu"];
|
|
|
291 |
#可省略參數
|
|
|
292 |
#$conf["disableWebSearch"],"字串",是否取消「當檔案找不到時,改用catchWebContent類別的wget函數來檢查檔案是否存在於網路上」的功能,"false"不取消,若要取消該功能請設為"true",若抓到的內容為空字串則會視為檔案不存在,預設為"true".
|
|
|
293 |
#$conf["disableWebSearch"]="false";
|
|
|
294 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
295 |
#$conf["userDir"]="true";
|
|
|
296 |
#參考資料來源:
|
|
|
297 |
#http://php.net/manual/en/function.file-exists.php
|
|
|
298 |
#http://php.net/manual/en/control-structures.foreach.php
|
|
|
299 |
#備註:
|
|
|
300 |
#函數file_exists檢查的路徑為檔案系統的路徑
|
|
|
301 |
$checkMultiFileExist=fileAccess::checkMultiFileExist($conf["fileAccess::checkMultiFileExist"]);
|
|
|
302 |
unset($conf["fileAccess::checkMultiFileExist"]);
|
|
|
303 |
|
|
|
304 |
#如果檢查檔案是否存在失敗
|
|
|
305 |
if($checkMultiFileExist["status"]=="false"){
|
|
|
306 |
|
|
|
307 |
#設置執行不正常
|
|
|
308 |
$result["status"]="false";
|
|
|
309 |
|
|
|
310 |
#設置執行錯誤
|
|
|
311 |
$result["error"]=$checkMultiFileExist;
|
|
|
312 |
|
|
|
313 |
#回傳結果
|
|
|
314 |
return $result;
|
|
|
315 |
|
|
|
316 |
}#if end
|
|
|
317 |
|
|
|
318 |
#如果檔案不存在
|
|
|
319 |
if($checkMultiFileExist["allExist"]=="false"){
|
|
|
320 |
|
|
|
321 |
#設置執行不正常
|
|
|
322 |
$result["status"]="false";
|
|
|
323 |
|
|
|
324 |
#設置執行錯誤
|
|
|
325 |
$result["error"]=$checkMultiFileExist;
|
|
|
326 |
|
|
|
327 |
#回傳結果
|
|
|
328 |
return $result;
|
|
|
329 |
|
|
|
330 |
}#if end
|
|
|
331 |
|
|
|
332 |
// load the required files for connecting to Hive
|
|
|
333 |
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_metastore/metastore/ThriftHiveMetastore.php';
|
|
|
334 |
require_once $GLOBALS['THRIFT_ROOT'] . '/packages/hive_service/ThriftHive.php';
|
|
|
335 |
require_once $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php';
|
|
|
336 |
require_once $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php';
|
|
|
337 |
|
|
|
338 |
// Set up the transport/protocol/client
|
|
|
339 |
$transport = new TSocket('localhost', 10000);
|
|
|
340 |
$protocol = new TBinaryProtocol($transport);
|
|
|
341 |
$client = new ThriftHiveClient($protocol);
|
|
|
342 |
$transport->open();
|
|
|
343 |
|
|
|
344 |
// run queries, metadata calls etc
|
|
|
345 |
$client->execute('SELECT * from pokes;');
|
|
|
346 |
$result["content"]=($client->fetchAll());
|
|
|
347 |
$transport->close();
|
|
|
348 |
|
|
|
349 |
#設置執行正常
|
|
|
350 |
$result["status"]="true";
|
|
|
351 |
|
|
|
352 |
#回傳結果
|
|
|
353 |
return $result;
|
|
|
354 |
|
|
|
355 |
}#function nativeQuery end
|
|
|
356 |
*/
|
|
|
357 |
|
|
|
358 |
/*
|
|
|
359 |
#涵式說明:
|
|
|
360 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
361 |
#回傳結果:
|
|
|
362 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
363 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
364 |
#$result["error"],陣列,錯訊訊息.
|
|
|
365 |
#$result["argu"],字串陣列,呼叫web service所用的參數.
|
|
|
366 |
#$result["content"],執行完query的回傳內容.
|
|
|
367 |
#$result["cmd"],執行的指令.
|
|
|
368 |
#必填參數:
|
|
|
369 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
370 |
$conf["sql"]="";
|
|
|
371 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
372 |
$conf["beeline"]="beeline";
|
|
|
373 |
#可省略參數:
|
|
|
374 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
375 |
#$conf["fileArgu"]=__FILE__;
|
|
|
376 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
377 |
#$conf["userName"]="liveuser";
|
|
|
378 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
379 |
#$conf["userPass"]="password";
|
|
|
380 |
#備註:
|
|
|
381 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
382 |
*/
|
|
|
383 |
function query(&$conf){
|
|
|
384 |
|
|
|
385 |
#初始化要回傳的結果
|
|
|
386 |
$result=array();
|
|
|
387 |
|
|
|
388 |
#取得當前執行的函數名稱
|
|
|
389 |
$result["function"]=__FUNCTION__;
|
|
|
390 |
|
|
|
391 |
#如果沒有參數
|
|
|
392 |
if(func_num_args()==0){
|
|
|
393 |
|
|
|
394 |
#設置執行失敗
|
|
|
395 |
$result["status"]="false";
|
|
|
396 |
|
|
|
397 |
#設置執行錯誤訊息
|
|
|
398 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
399 |
|
|
|
400 |
#回傳結果
|
|
|
401 |
return $result;
|
|
|
402 |
|
|
|
403 |
}#if end
|
|
|
404 |
|
|
|
405 |
#取得參數
|
|
|
406 |
$result["argu"]=$conf;
|
|
|
407 |
|
|
|
408 |
#如果 $conf 不為陣列
|
|
|
409 |
if(gettype($conf)!="array"){
|
|
|
410 |
|
|
|
411 |
#設置執行失敗
|
|
|
412 |
$result["status"]="false";
|
|
|
413 |
|
|
|
414 |
#設置執行錯誤訊息
|
|
|
415 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
416 |
|
|
|
417 |
#如果傳入的參數為 null
|
|
|
418 |
if($conf==null){
|
|
|
419 |
|
|
|
420 |
#設置執行錯誤訊息
|
|
|
421 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
422 |
|
|
|
423 |
}#if end
|
|
|
424 |
|
|
|
425 |
#回傳結果
|
|
|
426 |
return $result;
|
|
|
427 |
|
|
|
428 |
}#if end
|
|
|
429 |
|
|
|
430 |
#檢查參數
|
|
|
431 |
#函式說明:
|
|
|
432 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
433 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
434 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
435 |
#$result["function"],當前執行的函式名稱.
|
|
|
436 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
437 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
438 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
439 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
440 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
441 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
442 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
443 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
444 |
#必填寫的參數:
|
|
|
445 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
446 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
447 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
448 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sql","beeline");
|
|
|
449 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
450 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
451 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
452 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
453 |
#可以省略的參數:
|
|
|
454 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
455 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
456 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
457 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
458 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
459 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
460 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
461 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
462 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
463 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
464 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
465 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
466 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
467 |
#參考資料來源:
|
|
|
468 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
469 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
470 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
471 |
|
|
|
472 |
#如果檢查參數失敗
|
|
|
473 |
if($checkArguments["status"]=="false"){
|
|
|
474 |
|
|
|
475 |
#設置執行不正常
|
|
|
476 |
$result["status"]="false";
|
|
|
477 |
|
|
|
478 |
#設置執行錯誤
|
|
|
479 |
$result["error"]=$checkArguments;
|
|
|
480 |
|
|
|
481 |
#回傳結果
|
|
|
482 |
return $result;
|
|
|
483 |
|
|
|
484 |
}#if end
|
|
|
485 |
|
|
|
486 |
#如果檢查參數不通過
|
|
|
487 |
if($checkArguments["passed"]=="false"){
|
|
|
488 |
|
|
|
489 |
#設置執行不正常
|
|
|
490 |
$result["status"]="false";
|
|
|
491 |
|
|
|
492 |
#設置執行錯誤
|
|
|
493 |
$result["error"]=$checkArguments;
|
|
|
494 |
|
|
|
495 |
#回傳結果
|
|
|
496 |
return $result;
|
|
|
497 |
|
|
|
498 |
}#if end
|
|
|
499 |
|
|
|
500 |
#產生暫存的檔案名稱
|
|
|
501 |
#函數說明:
|
|
|
502 |
#回傳西元的目前時間,格式為2010年07月24日15時30分33秒
|
|
|
503 |
#回傳結果:
|
|
|
504 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
505 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
506 |
#$result["function"],當前執行的函式名稱.
|
|
|
507 |
#$result["content"],西元的目前時間,格式為2010年07月24日15時30分33秒
|
|
|
508 |
#必填參數:
|
|
|
509 |
#$conf["timeZone"],字串,時區代號,可以設定的時區列表:http://www.php.net/manual/en/timezones.php, ex:"Asia/Taipei".
|
|
|
510 |
$conf["time::getFullDateAndTime"]["timeZone"]="Asia/Taipei";
|
|
|
511 |
#可省略參數:
|
|
|
512 |
#$conf["showSecond"],字串,若爲"true"則會顯示秒數,預設為"true".
|
|
|
513 |
$conf["time::getFullDateAndTime"]["showSecond"]="true";
|
|
|
514 |
#參考資料:
|
|
|
515 |
#date函數用法=>http://php.net/manual/en/function.date.php.
|
|
|
516 |
$getFullDateAndTime=time::getFullDateAndTime($conf["time::getFullDateAndTime"]);
|
|
|
517 |
unset($conf["time::getFullDateAndTime"]);
|
|
|
518 |
|
|
|
519 |
#如果取得時間失敗
|
|
|
520 |
if($getFullDateAndTime["status"]=="false"){
|
|
|
521 |
|
|
|
522 |
#設置執行不正常
|
|
|
523 |
$result["status"]="false";
|
|
|
524 |
|
|
|
525 |
#設置執行錯誤
|
|
|
526 |
$result["error"]=$getFullDateAndTime;
|
|
|
527 |
|
|
|
528 |
#回傳結果
|
|
|
529 |
return $result;
|
|
|
530 |
|
|
|
531 |
}#if end
|
|
|
532 |
|
|
|
533 |
#取得暫存的檔案名稱
|
|
|
534 |
$tempCsvFile=$getFullDateAndTime["content"];
|
|
|
535 |
|
|
|
536 |
#暫存的目錄
|
|
|
537 |
$tempPath=".hive";
|
|
|
538 |
|
|
|
539 |
#轉換暫存的目錄為絕對路徑
|
|
|
540 |
#函數說明:
|
|
|
541 |
#將檔案的位置名稱變成網址,也可以取得檔案位於伺服器上檔案系統的絕對位置.
|
|
|
542 |
#回傳結果:
|
|
|
543 |
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
|
|
|
544 |
#$result["error"],錯誤訊息陣列.
|
|
|
545 |
#$result["function"],函數名稱.
|
|
|
546 |
#$result["content"],網址,若是在命令列執行,則為"null".
|
|
|
547 |
#$result["webPathFromRoot"],相對於網頁根目錄的路徑.
|
|
|
548 |
#$result["fileSystemAbsoulutePosition"],針對伺服器端的絕對位置,亦即從網頁「/」目錄開始的路徑.
|
|
|
549 |
#$result["fileSystemRelativePosition"],針對伺服器檔案系統的相對位置.
|
|
|
550 |
#必填參數:
|
|
|
551 |
#$conf["address"],字串,檔案的相對位置,若為絕對位置則會自動轉換成相對位置.
|
|
|
552 |
$conf["fileAccess::getInternetAddress"]["address"]=$tempPath;
|
|
|
553 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
|
|
|
554 |
$conf["fileAccess::getInternetAddress"]["fileArgu"]=$conf["fileArgu"];
|
|
|
555 |
#可省略參數:
|
|
|
556 |
#$conf["userDir"],字串,網頁是否置放於家目錄底下,"true"為是,"false"為不是,預設為"true".
|
|
|
557 |
#$conf["fileAccess::getInternetAddress"]["userDir"]="false";
|
|
|
558 |
#備註:
|
|
|
559 |
#在命令列執行,所得的路徑是錯誤的。
|
|
|
560 |
$getInternetAddress=fileAccess::getInternetAddress($conf["fileAccess::getInternetAddress"]);
|
|
|
561 |
unset($conf["fileAccess::getInternetAddress"]);
|
|
|
562 |
|
|
|
563 |
#如果取得網路位置失敗
|
|
|
564 |
if($getInternetAddress["status"]=="false"){
|
|
|
565 |
|
|
|
566 |
#設置執行不正常
|
|
|
567 |
$result["status"]="false";
|
|
|
568 |
|
|
|
569 |
#設置執行錯誤
|
|
|
570 |
$result["error"]=$getInternetAddress;
|
|
|
571 |
|
|
|
572 |
#回傳結果
|
|
|
573 |
return $result;
|
|
|
574 |
|
|
|
575 |
}#if end
|
|
|
576 |
|
|
|
577 |
#取得轉換好的絕對位置
|
|
|
578 |
$tempPath=$getInternetAddress["fileSystemAbsoulutePosition"];
|
|
|
579 |
|
|
|
580 |
#函式說明:
|
|
|
581 |
#檢查要建立的檔案路徑是否存在,若不存在則建立新檔案,若檔案已存在則會在原檔名後面加上從(1)開始的編號,再度嘗試建立檔案,以避免資料異常.
|
|
|
582 |
#回傳的結果:
|
|
|
583 |
#$result["status"],執行狀態,"true"代表執行正常,"false"代表執行失敗.
|
|
|
584 |
#$result["error"],錯誤訊息陣列.
|
|
|
585 |
#$result["function"],當前執行的函數名稱.
|
|
|
586 |
#$result["createdFileName"],建立好的檔案名稱.
|
|
|
587 |
#$result["createdFilePath"],檔案建立的路徑.
|
|
|
588 |
#$result["createdFilePathAndName"].建立好的檔案名稱與路徑.
|
|
|
589 |
#必填的參數:
|
|
|
590 |
#$conf["checkedFileAndPath"],字串陣列,要建立的檔案路徑
|
|
|
591 |
$conf["fileAccess::createFileAfterCheck"]["checkedFileAndPath"]=$tempPath."/".$tempCsvFile.".csv";
|
|
|
592 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
593 |
$conf["fileAccess::createFileAfterCheck"]["fileArgu"]=$conf["fileArgu"];
|
|
|
594 |
$createFileAfterCheck=fileAccess::createFileAfterCheck($conf["fileAccess::createFileAfterCheck"]);
|
|
|
595 |
unset($conf["fileAccess::createFileAfterCheck"]);
|
|
|
596 |
|
|
|
597 |
#如果建立檔案失敗
|
|
|
598 |
if($createFileAfterCheck["status"]=="false"){
|
|
|
599 |
|
|
|
600 |
#設置執行不正常
|
|
|
601 |
$result["status"]="false";
|
|
|
602 |
|
|
|
603 |
#設置執行錯誤
|
|
|
604 |
$result["error"]=$createFileAfterCheck;
|
|
|
605 |
|
|
|
606 |
#回傳結果
|
|
|
607 |
return $result;
|
|
|
608 |
|
|
|
609 |
}#if end
|
|
|
610 |
|
|
|
611 |
#取得暫存的csv檔案路徑
|
|
|
612 |
$tempCsvFile=$createFileAfterCheck["createdFilePathAndName"];
|
|
|
613 |
|
|
|
614 |
#初始化要執行的指令
|
|
|
615 |
$cmd="";
|
|
|
616 |
|
|
|
617 |
#如果有設定 $conf["userName"] 跟 $conf["userPass"]
|
|
|
618 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
|
|
619 |
|
|
|
620 |
$cmd="echo ".$conf["userPass"]." | su ".$conf["userName"]." -c '".$conf["beeline"]." --silent=true --outputformat=csv2 -u jdbc:hive2://localhost:10000 -e \"".$conf["sql"]."\" > \"".$tempCsvFile."\"' ";
|
|
|
621 |
|
|
|
622 |
}#if end
|
|
|
623 |
|
|
|
624 |
#反之
|
|
|
625 |
else{
|
|
|
626 |
|
|
|
627 |
$cmd=$conf["beeline"]." --silent=true --outputformat=csv2 -u jdbc:hive2://localhost:10000 -e \"".$conf["sql"]."\" > \"".$tempCsvFile."\"";
|
|
|
628 |
|
|
|
629 |
}#else end
|
|
|
630 |
|
|
|
631 |
#運行beeline執行hiveSQL
|
|
|
632 |
#涵式說明:
|
|
|
633 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
634 |
#回傳的結果:
|
|
|
635 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
636 |
#$result["error"],錯誤訊息陣列.
|
|
|
637 |
#$result["function"],當前執行的函數名稱.
|
|
|
638 |
#$result["cmd"],執行的指令內容.
|
|
|
639 |
#$result["output"],爲執行完二元碼後的輸出陣列.
|
|
|
640 |
#必填的參數
|
|
|
641 |
#$conf["command"],字串,要執行的指令與.
|
|
|
642 |
$conf["external::callShell"]["command"]=$cmd;
|
|
|
643 |
#可省略參數:
|
|
|
644 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
645 |
#$conf["argu"]=array("");
|
|
|
646 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
647 |
#$conf["enablePrintDescription"]="true";
|
|
|
648 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
|
|
|
649 |
#$conf["printDescription"]="";
|
|
|
650 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
651 |
#$conf["escapeshellarg"]="false";
|
|
|
652 |
#備註:
|
|
|
653 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
|
|
|
654 |
#參考資料:
|
|
|
655 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
656 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
657 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
658 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
659 |
unset($conf["external::callShell"]);
|
|
|
660 |
|
|
|
661 |
#如果執行beeline失敗
|
|
|
662 |
if($callShell["status"]=="false"){
|
|
|
663 |
|
|
|
664 |
#設置執行不正常
|
|
|
665 |
$result["status"]="false";
|
|
|
666 |
|
|
|
667 |
#設置執行錯誤
|
|
|
668 |
$result["error"]=$callShell;
|
|
|
669 |
|
|
|
670 |
#回傳結果
|
|
|
671 |
return $result;
|
|
|
672 |
|
|
|
673 |
}#if end
|
|
|
674 |
|
|
|
675 |
#取得執行的指令
|
|
|
676 |
$result["cmd"]=$callShell["cmd"];
|
|
|
677 |
|
|
|
678 |
#取得暫存檔案裡面的內容
|
|
|
679 |
$result["content"]=file($tempCsvFile);
|
|
|
680 |
|
|
|
681 |
#移除暫存的檔案
|
|
|
682 |
unlink($tempCsvFile);
|
|
|
683 |
|
|
|
684 |
#設置執行正常
|
|
|
685 |
$result["status"]="true";
|
|
|
686 |
|
|
|
687 |
#回傳結果
|
|
|
688 |
return $result;
|
|
|
689 |
|
|
|
690 |
}#function query end
|
|
|
691 |
|
|
|
692 |
/*
|
|
|
693 |
#涵式說明:
|
|
|
694 |
#執行hiveSQL,取得資料庫列表.
|
|
|
695 |
#回傳結果:
|
|
|
696 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
697 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
698 |
#$result["error"],陣列,錯訊訊息.
|
|
|
699 |
#$result["content"],執行完query的回傳內容.
|
|
|
700 |
#$result["cmd"],執行的指令.
|
|
|
701 |
#必填參數:
|
|
|
702 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
703 |
$conf["beeline"]="beeline";
|
|
|
704 |
#可省略參數:
|
|
|
705 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
706 |
#$conf["fileArgu"]=__FILE__
|
|
|
707 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
708 |
#$conf["userName"]="liveuser";
|
|
|
709 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
710 |
#$conf["userPass"]="password";
|
|
|
711 |
*/
|
|
|
712 |
function getDbList(&$conf){
|
|
|
713 |
|
|
|
714 |
#初始化要回傳的結果
|
|
|
715 |
$result=array();
|
|
|
716 |
|
|
|
717 |
#取得當前執行的函數名稱
|
|
|
718 |
$result["function"]=__FUNCTION__;
|
|
|
719 |
|
|
|
720 |
#如果沒有參數
|
|
|
721 |
if(func_num_args()==0){
|
|
|
722 |
|
|
|
723 |
#設置執行失敗
|
|
|
724 |
$result["status"]="false";
|
|
|
725 |
|
|
|
726 |
#設置執行錯誤訊息
|
|
|
727 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
728 |
|
|
|
729 |
#回傳結果
|
|
|
730 |
return $result;
|
|
|
731 |
|
|
|
732 |
}#if end
|
|
|
733 |
|
|
|
734 |
#取得參數
|
|
|
735 |
$result["argu"]=$conf;
|
|
|
736 |
|
|
|
737 |
#如果 $conf 不為陣列
|
|
|
738 |
if(gettype($conf)!="array"){
|
|
|
739 |
|
|
|
740 |
#設置執行失敗
|
|
|
741 |
$result["status"]="false";
|
|
|
742 |
|
|
|
743 |
#設置執行錯誤訊息
|
|
|
744 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
745 |
|
|
|
746 |
#如果傳入的參數為 null
|
|
|
747 |
if($conf==null){
|
|
|
748 |
|
|
|
749 |
#設置執行錯誤訊息
|
|
|
750 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
751 |
|
|
|
752 |
}#if end
|
|
|
753 |
|
|
|
754 |
#回傳結果
|
|
|
755 |
return $result;
|
|
|
756 |
|
|
|
757 |
}#if end
|
|
|
758 |
|
|
|
759 |
#檢查參數
|
|
|
760 |
#函式說明:
|
|
|
761 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
762 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
763 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
764 |
#$result["function"],當前執行的函式名稱.
|
|
|
765 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
766 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
767 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
768 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
769 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
770 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
771 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
772 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
773 |
#必填寫的參數:
|
|
|
774 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
775 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
776 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
777 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline");
|
|
|
778 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
779 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
780 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
781 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
782 |
#可以省略的參數:
|
|
|
783 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
784 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
785 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
786 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
787 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
788 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
789 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
790 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
791 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
792 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
793 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
794 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
795 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
796 |
#參考資料來源:
|
|
|
797 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
798 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
799 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
800 |
|
|
|
801 |
#如果檢查參數失敗
|
|
|
802 |
if($checkArguments["status"]=="false"){
|
|
|
803 |
|
|
|
804 |
#設置執行不正常
|
|
|
805 |
$result["status"]="false";
|
|
|
806 |
|
|
|
807 |
#設置執行錯誤
|
|
|
808 |
$result["error"]=$checkArguments;
|
|
|
809 |
|
|
|
810 |
#回傳結果
|
|
|
811 |
return $result;
|
|
|
812 |
|
|
|
813 |
}#if end
|
|
|
814 |
|
|
|
815 |
#如果檢查參數不通過
|
|
|
816 |
if($checkArguments["passed"]=="false"){
|
|
|
817 |
|
|
|
818 |
#設置執行不正常
|
|
|
819 |
$result["status"]="false";
|
|
|
820 |
|
|
|
821 |
#設置執行錯誤
|
|
|
822 |
$result["error"]=$checkArguments;
|
|
|
823 |
|
|
|
824 |
#回傳結果
|
|
|
825 |
return $result;
|
|
|
826 |
|
|
|
827 |
}#if end
|
|
|
828 |
|
|
|
829 |
#涵式說明:
|
|
|
830 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
831 |
#回傳結果:
|
|
|
832 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
833 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
834 |
#$result["error"],陣列,錯訊訊息.
|
|
|
835 |
#$result["content"],執行完query的回傳內容.
|
|
|
836 |
#$result["cmd"],執行的指令.
|
|
|
837 |
#必填參數:
|
|
|
838 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
839 |
$conf["hive::query"]["sql"]="show databases;";
|
|
|
840 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
841 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
|
|
842 |
#可省略參數:
|
|
|
843 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
844 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
|
|
845 |
|
|
|
846 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
847 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
|
|
848 |
|
|
|
849 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
850 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
|
|
851 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
852 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
|
|
853 |
|
|
|
854 |
}#if end
|
|
|
855 |
|
|
|
856 |
#備註:
|
|
|
857 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
858 |
$query=hive::query($conf["hive::query"]);
|
|
|
859 |
unset($conf["hive::query"]);
|
|
|
860 |
|
|
|
861 |
#如果查詢失敗
|
|
|
862 |
if($query["status"]=="false"){
|
|
|
863 |
|
|
|
864 |
#設置執行不正常
|
|
|
865 |
$result["status"]="false";
|
|
|
866 |
|
|
|
867 |
#設置執行錯誤
|
|
|
868 |
$result["error"]=$query;
|
|
|
869 |
|
|
|
870 |
#回傳結果
|
|
|
871 |
return $result;
|
|
|
872 |
|
|
|
873 |
}#if end
|
|
|
874 |
|
|
|
875 |
#解析回傳的內容
|
|
|
876 |
#涵式說明:
|
|
|
877 |
#處理多個字串避免網頁出錯
|
|
|
878 |
#回傳的結果:
|
|
|
879 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
880 |
#$result["function"],當前執行的函數.
|
|
|
881 |
#$result["error"],錯誤訊息
|
|
|
882 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
883 |
#必填的參數:
|
|
|
884 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
885 |
#可省略的參數:
|
|
|
886 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
887 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
888 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
889 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
890 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
891 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
892 |
|
|
|
893 |
#如果過濾字串失敗
|
|
|
894 |
if($correctMutiStrCharacter["status"]=="false"){
|
|
|
895 |
|
|
|
896 |
#設置執行不正常
|
|
|
897 |
$result["status"]="false";
|
|
|
898 |
|
|
|
899 |
#設置執行錯誤
|
|
|
900 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
901 |
|
|
|
902 |
#回傳結果
|
|
|
903 |
return $result;
|
|
|
904 |
|
|
|
905 |
}#if end
|
|
|
906 |
|
|
|
907 |
#移除資料庫的名稱的標題
|
|
|
908 |
#涵式說明:
|
|
|
909 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
910 |
#回傳的結果:
|
|
|
911 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
912 |
#$result["error"],錯誤訊息
|
|
|
913 |
#$result["function"],當前執行的函數
|
|
|
914 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
915 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
916 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
917 |
#必填的參數:
|
|
|
918 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
|
|
919 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
|
|
920 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
921 |
unset($conf["arrays::eraseElement"]);
|
|
|
922 |
|
|
|
923 |
#如果移除元素失敗
|
|
|
924 |
if($eraseElement["status"]=="false"){
|
|
|
925 |
|
|
|
926 |
#設置執行不正常
|
|
|
927 |
$result["status"]="false";
|
|
|
928 |
|
|
|
929 |
#設置執行錯誤
|
|
|
930 |
$result["error"]=$eraseElement;
|
|
|
931 |
|
|
|
932 |
#回傳結果
|
|
|
933 |
return $result;
|
|
|
934 |
|
|
|
935 |
}#if end
|
|
|
936 |
|
|
|
937 |
#取得解析好的內容
|
|
|
938 |
$result["content"]=$eraseElement["content"]["byNumber"];
|
|
|
939 |
|
|
|
940 |
#設置執行正常
|
|
|
941 |
$result["status"]="true";
|
|
|
942 |
|
|
|
943 |
#回傳結果
|
|
|
944 |
return $result;
|
|
|
945 |
|
|
|
946 |
}#function getDbList end
|
|
|
947 |
|
|
|
948 |
/*
|
|
|
949 |
#涵式說明:
|
|
|
950 |
#執行hiveSQL,取得資料表列表.
|
|
|
951 |
#回傳結果:
|
|
|
952 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
953 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
954 |
#$result["error"],陣列,錯訊訊息.
|
|
|
955 |
#$result["content"],執行完query的回傳內容.
|
|
|
956 |
#$result["cmd"],執行的指令.
|
|
|
957 |
#必填參數:
|
|
|
958 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
959 |
$conf["beeline"]="beeline";
|
|
|
960 |
#$conf["dbName"],字串,要取得資料表列表的目標資料庫名稱.
|
|
|
961 |
$conf["dbName"]="";
|
|
|
962 |
#可省略參數:
|
|
|
963 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
964 |
#$conf["fileArgu"]=__FILE__
|
|
|
965 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
966 |
#$conf["userName"]="liveuser";
|
|
|
967 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
968 |
#$conf["userPass"]="password";
|
|
|
969 |
*/
|
|
|
970 |
function getDtList(&$conf){
|
|
|
971 |
|
|
|
972 |
#初始化要回傳的結果
|
|
|
973 |
$result=array();
|
|
|
974 |
|
|
|
975 |
#取得當前執行的函數名稱
|
|
|
976 |
$result["function"]=__FUNCTION__;
|
|
|
977 |
|
|
|
978 |
#如果沒有參數
|
|
|
979 |
if(func_num_args()==0){
|
|
|
980 |
|
|
|
981 |
#設置執行失敗
|
|
|
982 |
$result["status"]="false";
|
|
|
983 |
|
|
|
984 |
#設置執行錯誤訊息
|
|
|
985 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
986 |
|
|
|
987 |
#回傳結果
|
|
|
988 |
return $result;
|
|
|
989 |
|
|
|
990 |
}#if end
|
|
|
991 |
|
|
|
992 |
#取得參數
|
|
|
993 |
$result["argu"]=$conf;
|
|
|
994 |
|
|
|
995 |
#如果 $conf 不為陣列
|
|
|
996 |
if(gettype($conf)!="array"){
|
|
|
997 |
|
|
|
998 |
#設置執行失敗
|
|
|
999 |
$result["status"]="false";
|
|
|
1000 |
|
|
|
1001 |
#設置執行錯誤訊息
|
|
|
1002 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1003 |
|
|
|
1004 |
#如果傳入的參數為 null
|
|
|
1005 |
if($conf==null){
|
|
|
1006 |
|
|
|
1007 |
#設置執行錯誤訊息
|
|
|
1008 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1009 |
|
|
|
1010 |
}#if end
|
|
|
1011 |
|
|
|
1012 |
#回傳結果
|
|
|
1013 |
return $result;
|
|
|
1014 |
|
|
|
1015 |
}#if end
|
|
|
1016 |
|
|
|
1017 |
#檢查參數
|
|
|
1018 |
#函式說明:
|
|
|
1019 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1020 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1021 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1022 |
#$result["function"],當前執行的函式名稱.
|
|
|
1023 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1024 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1025 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1026 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1027 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1028 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1029 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1030 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1031 |
#必填寫的參數:
|
|
|
1032 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1033 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1034 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1035 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName");
|
|
|
1036 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1037 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1038 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1039 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1040 |
#可以省略的參數:
|
|
|
1041 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1042 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1043 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1044 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1045 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1046 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
1047 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1048 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1049 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1050 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1051 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1052 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1053 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1054 |
#參考資料來源:
|
|
|
1055 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1056 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1057 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1058 |
|
|
|
1059 |
#如果檢查參數失敗
|
|
|
1060 |
if($checkArguments["status"]=="false"){
|
|
|
1061 |
|
|
|
1062 |
#設置執行不正常
|
|
|
1063 |
$result["status"]="false";
|
|
|
1064 |
|
|
|
1065 |
#設置執行錯誤
|
|
|
1066 |
$result["error"]=$checkArguments;
|
|
|
1067 |
|
|
|
1068 |
#回傳結果
|
|
|
1069 |
return $result;
|
|
|
1070 |
|
|
|
1071 |
}#if end
|
|
|
1072 |
|
|
|
1073 |
#如果檢查參數不通過
|
|
|
1074 |
if($checkArguments["passed"]=="false"){
|
|
|
1075 |
|
|
|
1076 |
#設置執行不正常
|
|
|
1077 |
$result["status"]="false";
|
|
|
1078 |
|
|
|
1079 |
#設置執行錯誤
|
|
|
1080 |
$result["error"]=$checkArguments;
|
|
|
1081 |
|
|
|
1082 |
#回傳結果
|
|
|
1083 |
return $result;
|
|
|
1084 |
|
|
|
1085 |
}#if end
|
|
|
1086 |
|
|
|
1087 |
#涵式說明:
|
|
|
1088 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1089 |
#回傳結果:
|
|
|
1090 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1091 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1092 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1093 |
#$result["content"],執行完query的回傳內容.
|
|
|
1094 |
#$result["cmd"],執行的指令.
|
|
|
1095 |
#必填參數:
|
|
|
1096 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1097 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; show tables;";
|
|
|
1098 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1099 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
|
|
1100 |
#可省略參數:
|
|
|
1101 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1102 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1103 |
|
|
|
1104 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
1105 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
|
|
1106 |
|
|
|
1107 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1108 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
|
|
1109 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1110 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
|
|
1111 |
|
|
|
1112 |
}#if end
|
|
|
1113 |
|
|
|
1114 |
#備註:
|
|
|
1115 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1116 |
$query=hive::query($conf["hive::query"]);
|
|
|
1117 |
unset($conf["hive::query"]);
|
|
|
1118 |
|
|
|
1119 |
#如果查詢失敗
|
|
|
1120 |
if($query["status"]=="false"){
|
|
|
1121 |
|
|
|
1122 |
#設置執行不正常
|
|
|
1123 |
$result["status"]="false";
|
|
|
1124 |
|
|
|
1125 |
#設置執行錯誤
|
|
|
1126 |
$result["error"]=$query;
|
|
|
1127 |
|
|
|
1128 |
#回傳結果
|
|
|
1129 |
return $result;
|
|
|
1130 |
|
|
|
1131 |
}#if end
|
|
|
1132 |
|
|
|
1133 |
#解析回傳的內容
|
|
|
1134 |
#涵式說明:
|
|
|
1135 |
#處理多個字串避免網頁出錯
|
|
|
1136 |
#回傳的結果:
|
|
|
1137 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1138 |
#$result["function"],當前執行的函數.
|
|
|
1139 |
#$result["error"],錯誤訊息
|
|
|
1140 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1141 |
#必填的參數:
|
|
|
1142 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
1143 |
#可省略的參數:
|
|
|
1144 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1145 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1146 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1147 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1148 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1149 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1150 |
|
|
|
1151 |
#如果過濾字串失敗
|
|
|
1152 |
if($correctMutiStrCharacter["status"]=="false"){
|
|
|
1153 |
|
|
|
1154 |
#設置執行不正常
|
|
|
1155 |
$result["status"]="false";
|
|
|
1156 |
|
|
|
1157 |
#設置執行錯誤
|
|
|
1158 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
1159 |
|
|
|
1160 |
#回傳結果
|
|
|
1161 |
return $result;
|
|
|
1162 |
|
|
|
1163 |
}#if end
|
|
|
1164 |
|
|
|
1165 |
#移除資料庫的名稱的標題
|
|
|
1166 |
#涵式說明:
|
|
|
1167 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
1168 |
#回傳的結果:
|
|
|
1169 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1170 |
#$result["error"],錯誤訊息
|
|
|
1171 |
#$result["function"],當前執行的函數
|
|
|
1172 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
1173 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
1174 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
1175 |
#必填的參數:
|
|
|
1176 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
|
|
1177 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
|
|
1178 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
1179 |
unset($conf["arrays::eraseElement"]);
|
|
|
1180 |
|
|
|
1181 |
#如果移除元素失敗
|
|
|
1182 |
if($eraseElement["status"]=="false"){
|
|
|
1183 |
|
|
|
1184 |
#設置執行不正常
|
|
|
1185 |
$result["status"]="false";
|
|
|
1186 |
|
|
|
1187 |
#設置執行錯誤
|
|
|
1188 |
$result["error"]=$eraseElement;
|
|
|
1189 |
|
|
|
1190 |
#回傳結果
|
|
|
1191 |
return $result;
|
|
|
1192 |
|
|
|
1193 |
}#if end
|
|
|
1194 |
|
|
|
1195 |
#取得解析好的內容
|
|
|
1196 |
$result["content"]=$eraseElement["content"]["byNumber"];
|
|
|
1197 |
|
|
|
1198 |
#設置執行正常
|
|
|
1199 |
$result["status"]="true";
|
|
|
1200 |
|
|
|
1201 |
#回傳結果
|
|
|
1202 |
return $result;
|
|
|
1203 |
|
|
|
1204 |
}#function getDtList end
|
|
|
1205 |
|
|
|
1206 |
/*
|
|
|
1207 |
#涵式說明:
|
|
|
1208 |
#執行hiveSQL,取得資料表結構.
|
|
|
1209 |
#回傳結果:
|
|
|
1210 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1211 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1212 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1213 |
#$result["content"],執行完query的回傳內容.
|
|
|
1214 |
#$result["cmd"],執行的指令.
|
|
|
1215 |
#必填參數:
|
|
|
1216 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1217 |
$conf["beeline"]="beeline";
|
|
|
1218 |
#$conf["dbName"],字串,要取得資料表結構的目標資料庫名稱.
|
|
|
1219 |
$conf["dbName"]="";
|
|
|
1220 |
#$conf["dtName"],字串,要取得結構的目標資料表名稱.
|
|
|
1221 |
$conf["dtName"]="";
|
|
|
1222 |
#可省略參數:
|
|
|
1223 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1224 |
#$conf["fileArgu"]=__FILE__
|
|
|
1225 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1226 |
#$conf["userName"]="liveuser";
|
|
|
1227 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1228 |
#$conf["userPass"]="password";
|
|
|
1229 |
*/
|
|
|
1230 |
function getDtStruc(&$conf){
|
|
|
1231 |
|
|
|
1232 |
#初始化要回傳的結果
|
|
|
1233 |
$result=array();
|
|
|
1234 |
|
|
|
1235 |
#取得當前執行的函數名稱
|
|
|
1236 |
$result["function"]=__FUNCTION__;
|
|
|
1237 |
|
|
|
1238 |
#如果沒有參數
|
|
|
1239 |
if(func_num_args()==0){
|
|
|
1240 |
|
|
|
1241 |
#設置執行失敗
|
|
|
1242 |
$result["status"]="false";
|
|
|
1243 |
|
|
|
1244 |
#設置執行錯誤訊息
|
|
|
1245 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1246 |
|
|
|
1247 |
#回傳結果
|
|
|
1248 |
return $result;
|
|
|
1249 |
|
|
|
1250 |
}#if end
|
|
|
1251 |
|
|
|
1252 |
#取得參數
|
|
|
1253 |
$result["argu"]=$conf;
|
|
|
1254 |
|
|
|
1255 |
#如果 $conf 不為陣列
|
|
|
1256 |
if(gettype($conf)!="array"){
|
|
|
1257 |
|
|
|
1258 |
#設置執行失敗
|
|
|
1259 |
$result["status"]="false";
|
|
|
1260 |
|
|
|
1261 |
#設置執行錯誤訊息
|
|
|
1262 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1263 |
|
|
|
1264 |
#如果傳入的參數為 null
|
|
|
1265 |
if($conf==null){
|
|
|
1266 |
|
|
|
1267 |
#設置執行錯誤訊息
|
|
|
1268 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1269 |
|
|
|
1270 |
}#if end
|
|
|
1271 |
|
|
|
1272 |
#回傳結果
|
|
|
1273 |
return $result;
|
|
|
1274 |
|
|
|
1275 |
}#if end
|
|
|
1276 |
|
|
|
1277 |
#檢查參數
|
|
|
1278 |
#函式說明:
|
|
|
1279 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1280 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1281 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1282 |
#$result["function"],當前執行的函式名稱.
|
|
|
1283 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1284 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1285 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1286 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1287 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1288 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1289 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1290 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1291 |
#必填寫的參數:
|
|
|
1292 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1293 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1294 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1295 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName","dtName");
|
|
|
1296 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1297 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1298 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1299 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1300 |
#可以省略的參數:
|
|
|
1301 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1302 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1303 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1304 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1305 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1306 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
1307 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1308 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1309 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1310 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1311 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1312 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1313 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1314 |
#參考資料來源:
|
|
|
1315 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1316 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1317 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1318 |
|
|
|
1319 |
#如果檢查參數失敗
|
|
|
1320 |
if($checkArguments["status"]=="false"){
|
|
|
1321 |
|
|
|
1322 |
#設置執行不正常
|
|
|
1323 |
$result["status"]="false";
|
|
|
1324 |
|
|
|
1325 |
#設置執行錯誤
|
|
|
1326 |
$result["error"]=$checkArguments;
|
|
|
1327 |
|
|
|
1328 |
#回傳結果
|
|
|
1329 |
return $result;
|
|
|
1330 |
|
|
|
1331 |
}#if end
|
|
|
1332 |
|
|
|
1333 |
#如果檢查參數不通過
|
|
|
1334 |
if($checkArguments["passed"]=="false"){
|
|
|
1335 |
|
|
|
1336 |
#設置執行不正常
|
|
|
1337 |
$result["status"]="false";
|
|
|
1338 |
|
|
|
1339 |
#設置執行錯誤
|
|
|
1340 |
$result["error"]=$checkArguments;
|
|
|
1341 |
|
|
|
1342 |
#回傳結果
|
|
|
1343 |
return $result;
|
|
|
1344 |
|
|
|
1345 |
}#if end
|
|
|
1346 |
|
|
|
1347 |
#涵式說明:
|
|
|
1348 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1349 |
#回傳結果:
|
|
|
1350 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1351 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1352 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1353 |
#$result["content"],執行完query的回傳內容.
|
|
|
1354 |
#$result["cmd"],執行的指令.
|
|
|
1355 |
#必填參數:
|
|
|
1356 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1357 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; DESCRIBE ".$conf["dtName"].";";
|
|
|
1358 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1359 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
|
|
1360 |
#可省略參數:
|
|
|
1361 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1362 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
|
|
1363 |
|
|
|
1364 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
1365 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
|
|
1366 |
|
|
|
1367 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1368 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
|
|
1369 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1370 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
|
|
1371 |
|
|
|
1372 |
}#if end
|
|
|
1373 |
|
|
|
1374 |
#備註:
|
|
|
1375 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1376 |
$query=hive::query($conf["hive::query"]);
|
|
|
1377 |
unset($conf["hive::query"]);
|
|
|
1378 |
|
|
|
1379 |
#如果查詢失敗
|
|
|
1380 |
if($query["status"]=="false"){
|
|
|
1381 |
|
|
|
1382 |
#設置執行不正常
|
|
|
1383 |
$result["status"]="false";
|
|
|
1384 |
|
|
|
1385 |
#設置執行錯誤
|
|
|
1386 |
$result["error"]=$query;
|
|
|
1387 |
|
|
|
1388 |
#回傳結果
|
|
|
1389 |
return $result;
|
|
|
1390 |
|
|
|
1391 |
}#if end
|
|
|
1392 |
|
|
|
1393 |
#解析回傳的內容
|
|
|
1394 |
#涵式說明:
|
|
|
1395 |
#處理多個字串避免網頁出錯
|
|
|
1396 |
#回傳的結果:
|
|
|
1397 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
1398 |
#$result["function"],當前執行的函數.
|
|
|
1399 |
#$result["error"],錯誤訊息
|
|
|
1400 |
#$result["processedStrArray"],處理好的字串陣列
|
|
|
1401 |
#必填的參數:
|
|
|
1402 |
$conf["stringProcess::correctMutiStrCharacter"]["stringIn"]=$query["content"];#爲要處理的字串陣列
|
|
|
1403 |
#可省略的參數:
|
|
|
1404 |
$conf["stringProcess::correctMutiStrCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1405 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1406 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1407 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
|
|
|
1408 |
$correctMutiStrCharacter=stringProcess::correctMutiStrCharacter($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1409 |
unset($conf["stringProcess::correctMutiStrCharacter"]);
|
|
|
1410 |
|
|
|
1411 |
#如果過濾字串失敗
|
|
|
1412 |
if($correctMutiStrCharacter["status"]=="false"){
|
|
|
1413 |
|
|
|
1414 |
#設置執行不正常
|
|
|
1415 |
$result["status"]="false";
|
|
|
1416 |
|
|
|
1417 |
#設置執行錯誤
|
|
|
1418 |
$result["error"]=$correctMutiStrCharacter;
|
|
|
1419 |
|
|
|
1420 |
#回傳結果
|
|
|
1421 |
return $result;
|
|
|
1422 |
|
|
|
1423 |
}#if end
|
|
|
1424 |
|
|
|
1425 |
#移除資料庫的名稱的標題
|
|
|
1426 |
#涵式說明:
|
|
|
1427 |
#將陣列中特定元素剔除,並重新按照順序排序
|
|
|
1428 |
#回傳的結果:
|
|
|
1429 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1430 |
#$result["error"],錯誤訊息
|
|
|
1431 |
#$result["function"],當前執行的函數
|
|
|
1432 |
#$result["empty"],移除完元素後是否為空陣列,"true"為是,"false"為否.
|
|
|
1433 |
#$result["content"]["byName"],剔除掉特定元素的陣列,使用原來陣列的key來儲存.
|
|
|
1434 |
#$result["content"]["byNumber"],剔除掉特定元素的陣列,使用從0開始的整數key來儲存.
|
|
|
1435 |
#必填的參數:
|
|
|
1436 |
$conf["arrays::eraseElement"]["rawInputArray"]=$correctMutiStrCharacter["processedStrArray"];#要處理的原始數字陣列
|
|
|
1437 |
$conf["arrays::eraseElement"]["eraseElementKey"]="0";#要移除的元素key值
|
|
|
1438 |
$eraseElement=arrays::eraseElement($conf["arrays::eraseElement"]);
|
|
|
1439 |
unset($conf["arrays::eraseElement"]);
|
|
|
1440 |
|
|
|
1441 |
#如果移除元素失敗
|
|
|
1442 |
if($eraseElement["status"]=="false"){
|
|
|
1443 |
|
|
|
1444 |
#設置執行不正常
|
|
|
1445 |
$result["status"]="false";
|
|
|
1446 |
|
|
|
1447 |
#設置執行錯誤
|
|
|
1448 |
$result["error"]=$eraseElement;
|
|
|
1449 |
|
|
|
1450 |
#回傳結果
|
|
|
1451 |
return $result;
|
|
|
1452 |
|
|
|
1453 |
}#if end
|
|
|
1454 |
|
|
|
1455 |
#取得欄位的名稱、類型、註解
|
|
|
1456 |
#涵式說明:
|
|
|
1457 |
#將多個固定格式的字串分開,並回傳分開的結果
|
|
|
1458 |
#回傳的參數:
|
|
|
1459 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
1460 |
#$result["error"],錯誤訊息陣列.
|
|
|
1461 |
#$result["function"],當前執行的函數名稱.
|
|
|
1462 |
#$result["spiltString"][$i]["oriStr"],爲第i個字串的原始內容
|
|
|
1463 |
#$result["spiltString"][$i]["dataArray"],爲第($i+1)個字串分割後的字串陣列
|
|
|
1464 |
#$result["spiltString"][$i]["dataArray"][$j],爲第($i+1)的分割好的字串的第($j+1)段內容
|
|
|
1465 |
#$result["spiltString"][$i]["dataCounts"],爲第($i+1)個字串分割後總共分成幾段
|
|
|
1466 |
#必填的參數:
|
|
|
1467 |
#$conf["stringIn"],字串陣列,要處理的字串陣列.
|
|
|
1468 |
$conf["stringProcess::spiltMutiString"]["stringIn"]=$eraseElement["content"]["byName"];
|
|
|
1469 |
#$conf["spiltSymbol"],字串,爲要以哪個符號作爲分割.
|
|
|
1470 |
$conf["stringProcess::spiltMutiString"]["spiltSymbol"]=",";
|
|
|
1471 |
$spiltMutiString=stringProcess::spiltMutiString($conf["stringProcess::spiltMutiString"]);
|
|
|
1472 |
unset($conf["stringProcess::spiltMutiString"]);
|
|
|
1473 |
|
|
|
1474 |
#如果分割欄位資訊失敗
|
|
|
1475 |
if($spiltMutiString["status"]=="false"){
|
|
|
1476 |
|
|
|
1477 |
#設置執行不正常
|
|
|
1478 |
$result["status"]="false";
|
|
|
1479 |
|
|
|
1480 |
#設置執行錯誤
|
|
|
1481 |
$result["error"]=$spiltMutiString;
|
|
|
1482 |
|
|
|
1483 |
#回傳結果
|
|
|
1484 |
return $result;
|
|
|
1485 |
|
|
|
1486 |
}#if end
|
|
|
1487 |
|
|
|
1488 |
#針對每個欄位
|
|
|
1489 |
foreach($spiltMutiString["spiltString"] as $num=>$col){
|
|
|
1490 |
|
|
|
1491 |
#如果欄位資訊沒有大於等於2個
|
|
|
1492 |
if($col["dataCounts"]<2){
|
|
|
1493 |
|
|
|
1494 |
#設置執行不正常
|
|
|
1495 |
$result["status"]="false";
|
|
|
1496 |
|
|
|
1497 |
#設置執行錯誤
|
|
|
1498 |
$result["error"][]="欄位資訊解析錯誤";
|
|
|
1499 |
|
|
|
1500 |
#回傳結果
|
|
|
1501 |
return $result;
|
|
|
1502 |
|
|
|
1503 |
}#if end
|
|
|
1504 |
|
|
|
1505 |
#取得欄位的名稱
|
|
|
1506 |
$result["content"][$num]["name"]=$col["dataArray"][0];
|
|
|
1507 |
|
|
|
1508 |
#取得欄位的類型
|
|
|
1509 |
$result["content"][$num]["type"]=$col["dataArray"][1];
|
|
|
1510 |
|
|
|
1511 |
#如果存在註解
|
|
|
1512 |
if(isset($col["dataArray"][2])){
|
|
|
1513 |
|
|
|
1514 |
#取得註解
|
|
|
1515 |
$result["content"][$num]["comment"]=$col["dataArray"][2];
|
|
|
1516 |
|
|
|
1517 |
}#if end
|
|
|
1518 |
|
|
|
1519 |
}#foreach end
|
|
|
1520 |
|
|
|
1521 |
#設置執行正常
|
|
|
1522 |
$result["status"]="true";
|
|
|
1523 |
|
|
|
1524 |
#回傳結果
|
|
|
1525 |
return $result;
|
|
|
1526 |
|
|
|
1527 |
}#function getDtStruc end
|
|
|
1528 |
|
|
|
1529 |
/*
|
|
|
1530 |
#涵式說明:
|
|
|
1531 |
#執行hiveSQL,取得資料表資料.
|
|
|
1532 |
#回傳結果:
|
|
|
1533 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1534 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1535 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1536 |
#$result["content"],執行完query的回傳內容.
|
|
|
1537 |
#$result["colName"],陣列,欄位的名稱.
|
|
|
1538 |
#$result["cmd"],執行的指令.
|
|
|
1539 |
#必填參數:
|
|
|
1540 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1541 |
$conf["beeline"]="beeline";
|
|
|
1542 |
#$conf["dbName"],字串,要取得資料表資料的目標資料庫名稱.
|
|
|
1543 |
$conf["dbName"]="";
|
|
|
1544 |
#$conf["dtName"],字串,要取得資料的目標資料表名稱.
|
|
|
1545 |
$conf["dtName"]="";
|
|
|
1546 |
#可省略參數:
|
|
|
1547 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1548 |
#$conf["fileArgu"]=__FILE__
|
|
|
1549 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1550 |
#$conf["userName"]="liveuser";
|
|
|
1551 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1552 |
#$conf["userPass"]="password";
|
|
|
1553 |
*/
|
|
|
1554 |
function getDtData(&$conf){
|
|
|
1555 |
|
|
|
1556 |
#初始化要回傳的結果
|
|
|
1557 |
$result=array();
|
|
|
1558 |
|
|
|
1559 |
#取得當前執行的函數名稱
|
|
|
1560 |
$result["function"]=__FUNCTION__;
|
|
|
1561 |
|
|
|
1562 |
#如果沒有參數
|
|
|
1563 |
if(func_num_args()==0){
|
|
|
1564 |
|
|
|
1565 |
#設置執行失敗
|
|
|
1566 |
$result["status"]="false";
|
|
|
1567 |
|
|
|
1568 |
#設置執行錯誤訊息
|
|
|
1569 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1570 |
|
|
|
1571 |
#回傳結果
|
|
|
1572 |
return $result;
|
|
|
1573 |
|
|
|
1574 |
}#if end
|
|
|
1575 |
|
|
|
1576 |
#取得參數
|
|
|
1577 |
$result["argu"]=$conf;
|
|
|
1578 |
|
|
|
1579 |
#如果 $conf 不為陣列
|
|
|
1580 |
if(gettype($conf)!="array"){
|
|
|
1581 |
|
|
|
1582 |
#設置執行失敗
|
|
|
1583 |
$result["status"]="false";
|
|
|
1584 |
|
|
|
1585 |
#設置執行錯誤訊息
|
|
|
1586 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1587 |
|
|
|
1588 |
#如果傳入的參數為 null
|
|
|
1589 |
if($conf==null){
|
|
|
1590 |
|
|
|
1591 |
#設置執行錯誤訊息
|
|
|
1592 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1593 |
|
|
|
1594 |
}#if end
|
|
|
1595 |
|
|
|
1596 |
#回傳結果
|
|
|
1597 |
return $result;
|
|
|
1598 |
|
|
|
1599 |
}#if end
|
|
|
1600 |
|
|
|
1601 |
#檢查參數
|
|
|
1602 |
#函式說明:
|
|
|
1603 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1604 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1605 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1606 |
#$result["function"],當前執行的函式名稱.
|
|
|
1607 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1608 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1609 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1610 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1611 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1612 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1613 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1614 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1615 |
#必填寫的參數:
|
|
|
1616 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1617 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1618 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1619 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName","dtName");
|
|
|
1620 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1621 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1622 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1623 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1624 |
#可以省略的參數:
|
|
|
1625 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1626 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1627 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1628 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1629 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1630 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
1631 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1632 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1633 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1634 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1635 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1636 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1637 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1638 |
#參考資料來源:
|
|
|
1639 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1640 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1641 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
1642 |
|
|
|
1643 |
#如果檢查參數失敗
|
|
|
1644 |
if($checkArguments["status"]=="false"){
|
|
|
1645 |
|
|
|
1646 |
#設置執行不正常
|
|
|
1647 |
$result["status"]="false";
|
|
|
1648 |
|
|
|
1649 |
#設置執行錯誤
|
|
|
1650 |
$result["error"]=$checkArguments;
|
|
|
1651 |
|
|
|
1652 |
#回傳結果
|
|
|
1653 |
return $result;
|
|
|
1654 |
|
|
|
1655 |
}#if end
|
|
|
1656 |
|
|
|
1657 |
#如果檢查參數不通過
|
|
|
1658 |
if($checkArguments["passed"]=="false"){
|
|
|
1659 |
|
|
|
1660 |
#設置執行不正常
|
|
|
1661 |
$result["status"]="false";
|
|
|
1662 |
|
|
|
1663 |
#設置執行錯誤
|
|
|
1664 |
$result["error"]=$checkArguments;
|
|
|
1665 |
|
|
|
1666 |
#回傳結果
|
|
|
1667 |
return $result;
|
|
|
1668 |
|
|
|
1669 |
}#if end
|
|
|
1670 |
|
|
|
1671 |
#涵式說明:
|
|
|
1672 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
1673 |
#回傳結果:
|
|
|
1674 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1675 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1676 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1677 |
#$result["argu"],字串陣列,呼叫web service所用的參數.
|
|
|
1678 |
#$result["content"],執行完query的回傳內容.
|
|
|
1679 |
#$result["cmd"],執行的指令.
|
|
|
1680 |
#必填參數:
|
|
|
1681 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
1682 |
$conf["hive::query"]["sql"]="use ".$conf["dbName"]."; select * from pokes;";
|
|
|
1683 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1684 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
|
|
1685 |
#可省略參數:
|
|
|
1686 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1687 |
#$conf["fileArgu"]=__FILE__;
|
|
|
1688 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1689 |
#$conf["userName"]="liveuser";
|
|
|
1690 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1691 |
#$conf["userPass"]="password";
|
|
|
1692 |
#備註:
|
|
|
1693 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
1694 |
$query=hive::query($conf["hive::query"]);
|
|
|
1695 |
unset($conf["hive::query"]);
|
|
|
1696 |
|
|
|
1697 |
#如果 query 失敗
|
|
|
1698 |
if($query["status"]=="false"){
|
|
|
1699 |
|
|
|
1700 |
#設置執行不正常
|
|
|
1701 |
$result["status"]="false";
|
|
|
1702 |
|
|
|
1703 |
#設置執行錯誤
|
|
|
1704 |
$result["error"]=$query;
|
|
|
1705 |
|
|
|
1706 |
#回傳結果
|
|
|
1707 |
return $result;
|
|
|
1708 |
|
|
|
1709 |
}#if end
|
|
|
1710 |
|
|
|
1711 |
#初始化儲存標題欄位名稱的變數
|
|
|
1712 |
$colName=array();
|
|
|
1713 |
|
|
|
1714 |
#依據 $query["content"] 的數量
|
|
|
1715 |
for($i=0;$i<count($query["content"]);$i++){
|
|
|
1716 |
|
|
|
1717 |
#用逗號分割欄位
|
|
|
1718 |
#涵式說明:
|
|
|
1719 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1720 |
#回傳結果:
|
|
|
1721 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1722 |
#$result["error"],錯誤訊息陣列
|
|
|
1723 |
#$result["function"],當前執行的函數名稱.
|
|
|
1724 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1725 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1726 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1727 |
#必填的參數:
|
|
|
1728 |
$conf["stringProcess::spiltString"]["stringIn"]=$query["content"][$i];#要處理的字串。
|
|
|
1729 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=",";#爲以哪個符號作爲分割
|
|
|
1730 |
#可省略參數:
|
|
|
1731 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1732 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1733 |
$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1734 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1735 |
|
|
|
1736 |
#如果分割字串失敗
|
|
|
1737 |
if($spiltString["status"]=="false"){
|
|
|
1738 |
|
|
|
1739 |
#設置執行不正常
|
|
|
1740 |
$result["status"]="false";
|
|
|
1741 |
|
|
|
1742 |
#設置執行錯誤
|
|
|
1743 |
$result["error"]=$spiltString;
|
|
|
1744 |
|
|
|
1745 |
#回傳結果
|
|
|
1746 |
return $result;
|
|
|
1747 |
|
|
|
1748 |
}#if end
|
|
|
1749 |
|
|
|
1750 |
#如果是標題欄位
|
|
|
1751 |
if($i==0){
|
|
|
1752 |
|
|
|
1753 |
#針對每個欄位
|
|
|
1754 |
for($j=0;$j<$spiltString["dataCounts"];$j++){
|
|
|
1755 |
|
|
|
1756 |
#將標題欄位的資料庫名稱剃除
|
|
|
1757 |
#涵式說明:
|
|
|
1758 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
1759 |
#回傳結果:
|
|
|
1760 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1761 |
#$result["error"],錯誤訊息陣列
|
|
|
1762 |
#$result["function"],當前執行的函數名稱.
|
|
|
1763 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
1764 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
1765 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
1766 |
#必填的參數:
|
|
|
1767 |
$conf["stringProcess::spiltString"]["stringIn"]=$spiltString["dataArray"][$j];#要處理的字串。
|
|
|
1768 |
$conf["stringProcess::spiltString"]["spiltSymbol"]=".";#爲以哪個符號作爲分割
|
|
|
1769 |
#可省略參數:
|
|
|
1770 |
#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
|
|
|
1771 |
$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
|
|
|
1772 |
$spiltColStr=stringProcess::spiltString($conf["stringProcess::spiltString"]);
|
|
|
1773 |
unset($conf["stringProcess::spiltString"]);
|
|
|
1774 |
|
|
|
1775 |
#如果分割字串失敗
|
|
|
1776 |
if($spiltColStr["status"]=="false"){
|
|
|
1777 |
|
|
|
1778 |
#設置執行不正常
|
|
|
1779 |
$result["status"]="false";
|
|
|
1780 |
|
|
|
1781 |
#設置執行錯誤
|
|
|
1782 |
$result["error"]=$spiltColStr;
|
|
|
1783 |
|
|
|
1784 |
#回傳結果
|
|
|
1785 |
return $result;
|
|
|
1786 |
|
|
|
1787 |
}#if end
|
|
|
1788 |
|
|
|
1789 |
#過濾欄位的換行符號
|
|
|
1790 |
#涵式說明:
|
|
|
1791 |
#處理字串避免網頁出錯
|
|
|
1792 |
#回傳的結果:
|
|
|
1793 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1794 |
#$result["function"],當前執行的函數.
|
|
|
1795 |
#$result["content"],爲處理好的字串.
|
|
|
1796 |
#$result["error"],錯誤訊息陣列.
|
|
|
1797 |
#必填的參數:
|
|
|
1798 |
$conf["stringProcess::correctCharacter"]["stringIn"]=$spiltColStr["dataArray"][1];#爲要處理的字串
|
|
|
1799 |
#可省略的參數:
|
|
|
1800 |
$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("\n");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
1801 |
#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
|
|
|
1802 |
#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
|
|
|
1803 |
#$conf["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
1804 |
$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
|
|
|
1805 |
unset($conf["stringProcess::correctCharacter"]);
|
|
|
1806 |
|
|
|
1807 |
#如果過濾字串失敗
|
|
|
1808 |
if($correctCharacter["status"]=="false"){
|
|
|
1809 |
|
|
|
1810 |
#設置執行不正常
|
|
|
1811 |
$result["status"]="false";
|
|
|
1812 |
|
|
|
1813 |
#設置執行錯誤
|
|
|
1814 |
$result["error"]=$correctCharacter;
|
|
|
1815 |
|
|
|
1816 |
#回傳結果
|
|
|
1817 |
return $result;
|
|
|
1818 |
|
|
|
1819 |
}#if end
|
|
|
1820 |
|
|
|
1821 |
#取得欄位名稱
|
|
|
1822 |
$colName[]=$correctCharacter["content"];
|
|
|
1823 |
|
|
|
1824 |
}#for end
|
|
|
1825 |
|
|
|
1826 |
}#if end
|
|
|
1827 |
|
|
|
1828 |
#反之是資料欄位
|
|
|
1829 |
else{
|
|
|
1830 |
|
|
|
1831 |
#針對每個資料欄位
|
|
|
1832 |
for($j=0;$j<$spiltString["dataCounts"];$j++){
|
|
|
1833 |
|
|
|
1834 |
#取得欄位資料
|
|
|
1835 |
#$result["content"][$colName[$j]][]=$spiltString["dataArray"][$j];
|
|
|
1836 |
$result["content"][$i-1][][$colName[$j]]=$spiltString["dataArray"][$j];
|
|
|
1837 |
|
|
|
1838 |
}#for end
|
|
|
1839 |
|
|
|
1840 |
}#else end
|
|
|
1841 |
|
|
|
1842 |
}#for end
|
|
|
1843 |
|
|
|
1844 |
#儲存欄位的名稱
|
|
|
1845 |
$result["colName"]=$colName;
|
|
|
1846 |
|
|
|
1847 |
#設置執行正常
|
|
|
1848 |
$result["status"]="true";
|
|
|
1849 |
|
|
|
1850 |
#回傳結果
|
|
|
1851 |
return $result;
|
|
|
1852 |
|
|
|
1853 |
}#function getDtData end
|
|
|
1854 |
|
|
|
1855 |
/*
|
|
|
1856 |
|
|
|
1857 |
*/
|
|
|
1858 |
function updateData(&$conf=array()){
|
|
|
1859 |
|
|
|
1860 |
}#function updateDate end
|
|
|
1861 |
|
|
|
1862 |
/*
|
|
|
1863 |
|
|
|
1864 |
*/
|
|
|
1865 |
function delData(&$conf=array()){
|
|
|
1866 |
|
|
|
1867 |
}#function delData
|
|
|
1868 |
|
|
|
1869 |
/*
|
|
|
1870 |
|
|
|
1871 |
*/
|
|
|
1872 |
function createTable(&$conf=array()){
|
|
|
1873 |
|
|
|
1874 |
}#function create table end
|
|
|
1875 |
|
|
|
1876 |
/*
|
|
|
1877 |
|
|
|
1878 |
*/
|
|
|
1879 |
function modifyTable(&$conf=array()){
|
|
|
1880 |
|
|
|
1881 |
}#function modifyTable end
|
|
|
1882 |
|
|
|
1883 |
/*
|
|
|
1884 |
|
|
|
1885 |
*/
|
|
|
1886 |
function delTable(&$conf=array()){
|
|
|
1887 |
|
|
|
1888 |
}#function delTable end
|
|
|
1889 |
|
|
|
1890 |
/*
|
|
|
1891 |
#函數說明:
|
|
|
1892 |
#建立資料庫,並回傳資料庫列表.
|
|
|
1893 |
#回傳結果:
|
|
|
1894 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
1895 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
1896 |
#$result["error"],陣列,錯訊訊息.
|
|
|
1897 |
#$result["content"],資料庫列表.
|
|
|
1898 |
#$result["cmd"],執行的指令.
|
|
|
1899 |
#必填參數:
|
|
|
1900 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
1901 |
$conf["beeline"]="beeline";
|
|
|
1902 |
#$conf["dbName"],字串,要建立的資料庫名稱.
|
|
|
1903 |
$conf["dbName"]="";
|
|
|
1904 |
#可省略參數:
|
|
|
1905 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
1906 |
#$conf["fileArgu"]=__FILE__
|
|
|
1907 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
1908 |
#$conf["userName"]="liveuser";
|
|
|
1909 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
1910 |
#$conf["userPass"]="password";
|
|
|
1911 |
*/
|
|
|
1912 |
function createDb(&$conf=array()){
|
|
|
1913 |
|
|
|
1914 |
#初始化要回傳的結果
|
|
|
1915 |
$result=array();
|
|
|
1916 |
|
|
|
1917 |
#取得當前執行的函數名稱
|
|
|
1918 |
$result["function"]=__FUNCTION__;
|
|
|
1919 |
|
|
|
1920 |
#如果沒有參數
|
|
|
1921 |
if(func_num_args()==0){
|
|
|
1922 |
|
|
|
1923 |
#設置執行失敗
|
|
|
1924 |
$result["status"]="false";
|
|
|
1925 |
|
|
|
1926 |
#設置執行錯誤訊息
|
|
|
1927 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
1928 |
|
|
|
1929 |
#回傳結果
|
|
|
1930 |
return $result;
|
|
|
1931 |
|
|
|
1932 |
}#if end
|
|
|
1933 |
|
|
|
1934 |
#取得參數
|
|
|
1935 |
$result["argu"]=$conf;
|
|
|
1936 |
|
|
|
1937 |
#如果 $conf 不為陣列
|
|
|
1938 |
if(gettype($conf)!="array"){
|
|
|
1939 |
|
|
|
1940 |
#設置執行失敗
|
|
|
1941 |
$result["status"]="false";
|
|
|
1942 |
|
|
|
1943 |
#設置執行錯誤訊息
|
|
|
1944 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1945 |
|
|
|
1946 |
#如果傳入的參數為 null
|
|
|
1947 |
if($conf==null){
|
|
|
1948 |
|
|
|
1949 |
#設置執行錯誤訊息
|
|
|
1950 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
1951 |
|
|
|
1952 |
}#if end
|
|
|
1953 |
|
|
|
1954 |
#回傳結果
|
|
|
1955 |
return $result;
|
|
|
1956 |
|
|
|
1957 |
}#if end
|
|
|
1958 |
|
|
|
1959 |
#檢查參數
|
|
|
1960 |
#函式說明:
|
|
|
1961 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1962 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1963 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1964 |
#$result["function"],當前執行的函式名稱.
|
|
|
1965 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1966 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1967 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1968 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1969 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
1970 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1971 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1972 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1973 |
#必填寫的參數:
|
|
|
1974 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1975 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1976 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1977 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("beeline","dbName");
|
|
|
1978 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
1979 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
1980 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1981 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1982 |
#可以省略的參數:
|
|
|
1983 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
1984 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1985 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
1986 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
1987 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1988 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","userName","userPass");
|
|
|
1989 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
1990 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
|
|
|
1991 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1992 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,null,null);
|
|
|
1993 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1994 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
|
|
|
1995 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
|
|
|
1996 |
#參考資料來源:
|
|
|
1997 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1998 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1999 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
2000 |
|
|
|
2001 |
#如果檢查參數失敗
|
|
|
2002 |
if($checkArguments["status"]=="false"){
|
|
|
2003 |
|
|
|
2004 |
#設置執行不正常
|
|
|
2005 |
$result["status"]="false";
|
|
|
2006 |
|
|
|
2007 |
#設置執行錯誤
|
|
|
2008 |
$result["error"]=$checkArguments;
|
|
|
2009 |
|
|
|
2010 |
#回傳結果
|
|
|
2011 |
return $result;
|
|
|
2012 |
|
|
|
2013 |
}#if end
|
|
|
2014 |
|
|
|
2015 |
#如果檢查參數不通過
|
|
|
2016 |
if($checkArguments["passed"]=="false"){
|
|
|
2017 |
|
|
|
2018 |
#設置執行不正常
|
|
|
2019 |
$result["status"]="false";
|
|
|
2020 |
|
|
|
2021 |
#設置執行錯誤
|
|
|
2022 |
$result["error"]=$checkArguments;
|
|
|
2023 |
|
|
|
2024 |
#回傳結果
|
|
|
2025 |
return $result;
|
|
|
2026 |
|
|
|
2027 |
}#if end
|
|
|
2028 |
|
|
|
2029 |
#涵式說明:
|
|
|
2030 |
#執行hiveSQL,取得未解析的SQL結果.
|
|
|
2031 |
#回傳結果:
|
|
|
2032 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
2033 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
2034 |
#$result["error"],陣列,錯訊訊息.
|
|
|
2035 |
#$result["content"],執行完query的回傳內容.
|
|
|
2036 |
#$result["cmd"],執行的指令.
|
|
|
2037 |
#必填參數:
|
|
|
2038 |
#$conf["sql"],字串,要執行的sql字串.
|
|
|
2039 |
$conf["hive::query"]["sql"]="create ".$conf["dbName"]."; show databases;";
|
|
|
2040 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
2041 |
$conf["hive::query"]["beeline"]=$conf["beeline"];
|
|
|
2042 |
#可省略參數:
|
|
|
2043 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
2044 |
$conf["hive::query"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2045 |
|
|
|
2046 |
#如果有設置 $conf["userName"] 與 $conf["userPass"]
|
|
|
2047 |
if(isset($conf["userName"]) && isset($conf["userPass"])){
|
|
|
2048 |
|
|
|
2049 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
2050 |
$conf["hive::query"]["userName"]=$conf["userName"];
|
|
|
2051 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
2052 |
$conf["hive::query"]["userPass"]=$conf["userPass"];
|
|
|
2053 |
|
|
|
2054 |
}#if end
|
|
|
2055 |
|
|
|
2056 |
#備註:
|
|
|
2057 |
#若使用 $conf["userName"] 跟 $conf["userPass"] 則會因為$conf["sql"]中含有「'或"」而造成指令錯誤.
|
|
|
2058 |
$query=hive::query($conf["hive::query"]);
|
|
|
2059 |
unset($conf["hive::query"]);
|
|
|
2060 |
|
|
|
2061 |
#取得建立資料庫執行的cmd
|
|
|
2062 |
$result["cmd"][]=$query["cmd"];
|
|
|
2063 |
|
|
|
2064 |
#如果查詢失敗
|
|
|
2065 |
if($query["status"]=="false"){
|
|
|
2066 |
|
|
|
2067 |
#設置執行不正常
|
|
|
2068 |
$result["status"]="false";
|
|
|
2069 |
|
|
|
2070 |
#設置執行錯誤
|
|
|
2071 |
$result["error"]=$query;
|
|
|
2072 |
|
|
|
2073 |
#回傳結果
|
|
|
2074 |
return $result;
|
|
|
2075 |
|
|
|
2076 |
}#if end
|
|
|
2077 |
|
|
|
2078 |
#涵式說明:
|
|
|
2079 |
#執行hiveSQL,取得資料庫列表.
|
|
|
2080 |
#回傳結果:
|
|
|
2081 |
#$result["status"],字串,執行否正常,"true"代表正常,"false"代表不正常.
|
|
|
2082 |
#$result["functin"],字串,當前函數的名稱.
|
|
|
2083 |
#$result["error"],陣列,錯訊訊息.
|
|
|
2084 |
#$result["content"],執行完query的回傳內容.
|
|
|
2085 |
#$result["cmd"],執行的指令.
|
|
|
2086 |
#必填參數:
|
|
|
2087 |
#$conf["beeline"],字串,beeline程式的位置.
|
|
|
2088 |
$conf["hive::getDbList"]["beeline"]=$conf["beeline"];
|
|
|
2089 |
#可省略參數:
|
|
|
2090 |
#$conf["fileArgu"],字串.__FILE__的內容,若省略,則為伺服器上該檔案的位置.
|
|
|
2091 |
$conf["hive::getDbList"]["fileArgu"]=$conf["fileArgu"];
|
|
|
2092 |
|
|
|
2093 |
#如果有設定 $conf["userName"]
|
|
|
2094 |
if(isset($conf["userName"])){
|
|
|
2095 |
|
|
|
2096 |
#$conf["userName"],字串,執行beeline程式的使用者名稱.
|
|
|
2097 |
$conf["hive::getDbList"]["userName"]="liveuser";
|
|
|
2098 |
|
|
|
2099 |
}#if end
|
|
|
2100 |
|
|
|
2101 |
#如果有設定 $conf["userPass"]
|
|
|
2102 |
if(isset($conf["userPass"])){
|
|
|
2103 |
|
|
|
2104 |
#$conf["userPass"],字串,執行beeline程式的使用者名稱對應的密碼.
|
|
|
2105 |
$conf["hive::getDbList"]["userPass"]="password";
|
|
|
2106 |
|
|
|
2107 |
}#if end
|
|
|
2108 |
|
|
|
2109 |
$getDbList=hive::getDbList($conf["hive::getDbList"]);
|
|
|
2110 |
unset($conf["hive::getDbList"]);
|
|
|
2111 |
|
|
|
2112 |
#如果取得資料庫列表失敗
|
|
|
2113 |
if($getDbList["status"]=="false"){
|
|
|
2114 |
|
|
|
2115 |
#設置執行不正常
|
|
|
2116 |
$result["status"]="false";
|
|
|
2117 |
|
|
|
2118 |
#設置執行錯誤
|
|
|
2119 |
$result["error"]=$query;
|
|
|
2120 |
|
|
|
2121 |
#回傳結果
|
|
|
2122 |
return $result;
|
|
|
2123 |
|
|
|
2124 |
}#if end
|
|
|
2125 |
|
|
|
2126 |
#取得資料庫列表執行的cmd
|
|
|
2127 |
$result["cmd"][]=$getDbList["cmd"];
|
|
|
2128 |
|
|
|
2129 |
#取得資料庫列表
|
|
|
2130 |
$result["content"]=$getDbList["content"];
|
|
|
2131 |
|
|
|
2132 |
#設置執行正常
|
|
|
2133 |
$result["status"]="true";
|
|
|
2134 |
|
|
|
2135 |
#回傳結果
|
|
|
2136 |
return $result;
|
|
|
2137 |
|
|
|
2138 |
}#function createDb end
|
|
|
2139 |
|
|
|
2140 |
/*
|
|
|
2141 |
|
|
|
2142 |
*/
|
|
|
2143 |
function dropDb(&$conf=array()){
|
|
|
2144 |
|
|
|
2145 |
}#function dropDb end
|
|
|
2146 |
|
|
|
2147 |
}#class hive end
|
|
|
2148 |
|
|
|
2149 |
?>
|