@@ -13,27 +13,27 @@ |
||
13 | 13 | $cl->setSoftCheck(true); |
14 | 14 | if (!$cl->isReplicasIsOk()) |
15 | 15 | { |
16 | - throw new Exception('Replica state is bad , error='.$cl->getError()); |
|
16 | + throw new Exception('Replica state is bad , error=' . $cl->getError()); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | |
20 | -$tables=$cl->getTables(); |
|
20 | +$tables = $cl->getTables(); |
|
21 | 21 | |
22 | 22 | foreach ($tables as $dbtable=>$tmp) |
23 | 23 | { |
24 | 24 | echo ">>> $dbtable :"; |
25 | 25 | |
26 | - $size=$cl->getSizeTable($dbtable); |
|
26 | + $size = $cl->getSizeTable($dbtable); |
|
27 | 27 | |
28 | 28 | |
29 | - echo "\t".\ClickHouseDB\Example\Helper::humanFileSize($size)."\n"; |
|
29 | + echo "\t" . \ClickHouseDB\Example\Helper::humanFileSize($size) . "\n"; |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | -$table_for_truncate='target.events_sharded'; |
|
34 | +$table_for_truncate = 'target.events_sharded'; |
|
35 | 35 | |
36 | -$result=$cl->truncateTable($table_for_truncate); |
|
36 | +$result = $cl->truncateTable($table_for_truncate); |
|
37 | 37 | |
38 | 38 | echo "Result:truncate table\n"; |
39 | 39 | print_r($result); |
@@ -12,10 +12,10 @@ |
||
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
15 | - * @param $file_name |
|
16 | - * @param int $from_id |
|
17 | - * @param int $to_id |
|
18 | - */ |
|
15 | + * @param $file_name |
|
16 | + * @param int $from_id |
|
17 | + * @param int $to_id |
|
18 | + */ |
|
19 | 19 | public static function makeListSitesKeysDataFile($file_name, $from_id = 1000, $to_id = 20000) |
20 | 20 | { |
21 | 21 | @unlink($file_name); |
@@ -7,8 +7,8 @@ |
||
7 | 7 | public static function init() |
8 | 8 | { |
9 | 9 | date_default_timezone_set('Europe/Moscow'); |
10 | - error_reporting( E_ALL ); |
|
11 | - ini_set('display_errors',1); |
|
10 | + error_reporting(E_ALL); |
|
11 | + ini_set('display_errors', 1); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -123,8 +123,10 @@ |
||
123 | 123 | |
124 | 124 | for ($day_ago = 0; $day_ago < 360; $day_ago++) { |
125 | 125 | $date = strtotime('-' . $day_ago . ' day'); |
126 | - for ($hash_id = 1; $hash_id < (1 + $size); $hash_id++) |
|
127 | - for ($site_id = 100; $site_id < 199; $site_id++) { |
|
126 | + for ($hash_id = 1; $hash_id < (1 + $size); $hash_id++) { |
|
127 | + for ($site_id = 100; |
|
128 | + } |
|
129 | + $site_id < 199; $site_id++) { |
|
128 | 130 | $j['event_time'] = date('Y-m-d H:00:00', $date); |
129 | 131 | $j['site_id'] = $site_id; |
130 | 132 | $j['hash_id'] = $hash_id; |
@@ -49,7 +49,9 @@ discard block |
||
49 | 49 | private function applyFormatQuery() |
50 | 50 | { |
51 | 51 | // FORMAT\s(\w)*$ |
52 | - if (null === $this->format) return false; |
|
52 | + if (null === $this->format) { |
|
53 | + return false; |
|
54 | + } |
|
53 | 55 | $supportFormats= |
54 | 56 | "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated"; |
55 | 57 | |
@@ -63,8 +65,7 @@ discard block |
||
63 | 65 | $this->format=trim(str_ireplace('format','',$matches[0][0])); |
64 | 66 | |
65 | 67 | } |
66 | - } |
|
67 | - else { |
|
68 | + } else { |
|
68 | 69 | $this->sql = $this->sql . ' FORMAT ' . $this->format; |
69 | 70 | } |
70 | 71 |
@@ -20,21 +20,21 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * @var array |
22 | 22 | */ |
23 | - private $degenerations=[]; |
|
23 | + private $degenerations = []; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Query constructor. |
27 | 27 | * @param string $sql |
28 | 28 | * @param array $degenerations |
29 | 29 | */ |
30 | - public function __construct($sql,$degenerations=[]) |
|
30 | + public function __construct($sql, $degenerations = []) |
|
31 | 31 | { |
32 | 32 | if (!trim($sql)) |
33 | 33 | { |
34 | 34 | throw new QueryException('Empty Query'); |
35 | 35 | } |
36 | 36 | $this->sql = $sql; |
37 | - $this->degenerations=$degenerations; |
|
37 | + $this->degenerations = $degenerations; |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | { |
51 | 51 | // FORMAT\s(\w)*$ |
52 | 52 | if (null === $this->format) return false; |
53 | - $supportFormats= |
|
53 | + $supportFormats = |
|
54 | 54 | "FORMAT\\s+TSV|FORMAT\\s+TSVRaw|FORMAT\\s+TSVWithNames|FORMAT\\s+TSVWithNamesAndTypes|FORMAT\\s+Vertical|FORMAT\\s+JSONCompact|FORMAT\\s+JSONEachRow|FORMAT\\s+TSKV|FORMAT\\s+TabSeparatedWithNames|FORMAT\\s+TabSeparatedWithNamesAndTypes|FORMAT\\s+TabSeparatedRaw|FORMAT\\s+BlockTabSeparated|FORMAT\\s+CSVWithNames|FORMAT\\s+CSV|FORMAT\\s+JSON|FORMAT\\s+TabSeparated"; |
55 | 55 | |
56 | - $matches=[]; |
|
57 | - if (preg_match_all('%('.$supportFormats.')%ius',$this->sql,$matches)){ |
|
56 | + $matches = []; |
|
57 | + if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) { |
|
58 | 58 | |
59 | 59 | // skip add "format json" |
60 | 60 | if (isset($matches[0])) |
61 | 61 | { |
62 | 62 | |
63 | - $this->format=trim(str_ireplace('format','',$matches[0][0])); |
|
63 | + $this->format = trim(str_ireplace('format', '', $matches[0][0])); |
|
64 | 64 | |
65 | 65 | } |
66 | 66 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | foreach ($this->degenerations as $degeneration) |
96 | 96 | { |
97 | 97 | if ($degeneration instanceof Degeneration) { |
98 | - $this->sql=$degeneration->process($this->sql); |
|
98 | + $this->sql = $degeneration->process($this->sql); |
|
99 | 99 | } |
100 | 100 | } |
101 | 101 | } |
@@ -167,13 +167,11 @@ discard block |
||
167 | 167 | |
168 | 168 | if ($parse) { |
169 | 169 | throw new DatabaseException($parse['message'] . "\nIN:" . $this->sql(), $parse['code']); |
170 | - } |
|
171 | - else { |
|
170 | + } else { |
|
172 | 171 | $code = $this->response()->http_code(); |
173 | 172 | $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body; |
174 | 173 | } |
175 | - } |
|
176 | - else { |
|
174 | + } else { |
|
177 | 175 | $code = $error_no; |
178 | 176 | $message = $this->response()->error(); |
179 | 177 | } |
@@ -349,8 +347,12 @@ discard block |
||
349 | 347 | $this->init(); |
350 | 348 | if ($key) |
351 | 349 | { |
352 | - if (!is_array($this->statistics)) return null; |
|
353 | - if (!isset($this->statistics[$key])) return null; |
|
350 | + if (!is_array($this->statistics)) { |
|
351 | + return null; |
|
352 | + } |
|
353 | + if (!isset($this->statistics[$key])) { |
|
354 | + return null; |
|
355 | + } |
|
354 | 356 | return $this->statistics[$key]; |
355 | 357 | } |
356 | 358 | return $this->statistics; |
@@ -394,8 +396,7 @@ discard block |
||
394 | 396 | if ($key) { |
395 | 397 | if (isset($this->array_data[0][$key])) { |
396 | 398 | return $this->array_data[0][$key]; |
397 | - } |
|
398 | - else { |
|
399 | + } else { |
|
399 | 400 | return null; |
400 | 401 | } |
401 | 402 | } |
@@ -489,16 +490,14 @@ discard block |
||
489 | 490 | { |
490 | 491 | if (is_array($path)) { |
491 | 492 | $keys = $path; |
492 | - } |
|
493 | - else { |
|
493 | + } else { |
|
494 | 494 | $args = func_get_args(); |
495 | 495 | array_shift($args); |
496 | 496 | |
497 | 497 | if (sizeof($args) < 2) { |
498 | 498 | $separator = '.'; |
499 | 499 | $keys = explode($separator, $path); |
500 | - } |
|
501 | - else { |
|
500 | + } else { |
|
502 | 501 | $keys = $args; |
503 | 502 | } |
504 | 503 | } |
@@ -510,14 +509,15 @@ discard block |
||
510 | 509 | |
511 | 510 | if (isset($arr[$key])) { |
512 | 511 | $val = $arr[$key]; |
513 | - } |
|
514 | - else { |
|
512 | + } else { |
|
515 | 513 | $val = $key; |
516 | 514 | } |
517 | 515 | |
518 | 516 | $tree = array($val => $tree); |
519 | 517 | } |
520 | - if (!is_array($tree)) return []; |
|
518 | + if (!is_array($tree)) { |
|
519 | + return []; |
|
520 | + } |
|
521 | 521 | return $tree; |
522 | 522 | } |
523 | 523 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | /** |
84 | 84 | * @var array|null |
85 | 85 | */ |
86 | - private $statistics=null; |
|
86 | + private $statistics = null; |
|
87 | 87 | |
88 | 88 | |
89 | 89 | public function __construct(CurlerRequest $request) |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | $body = $this->response()->body(); |
162 | 162 | $error_no = $this->response()->error_no(); |
163 | - $error=$this->response()->error(); |
|
163 | + $error = $this->response()->error(); |
|
164 | 164 | |
165 | 165 | if (!$error_no && !$error) { |
166 | 166 | $parse = $this->parseErrorClickHouse($body); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | else { |
172 | 172 | $code = $this->response()->http_code(); |
173 | - $message = "HttpCode:" . $this->response()->http_code() . " ; ".$this->response()->error()." ;" . $body; |
|
173 | + $message = "HttpCode:" . $this->response()->http_code() . " ; " . $this->response()->error() . " ;" . $body; |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | else { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | return false; |
228 | 228 | } |
229 | 229 | |
230 | - foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least','statistics'] as $key) { |
|
230 | + foreach (['meta', 'data', 'totals', 'extremes', 'rows', 'rows_before_limit_at_least', 'statistics'] as $key) { |
|
231 | 231 | if (isset($this->_rawData[$key])) { |
232 | 232 | $this->{$key} = $this->_rawData[$key]; |
233 | 233 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | * @return array|mixed|null |
345 | 345 | * @throws Exception\TransportException |
346 | 346 | */ |
347 | - public function statistics($key=false) |
|
347 | + public function statistics($key = false) |
|
348 | 348 | { |
349 | 349 | $this->init(); |
350 | 350 | if ($key) |