@@ -17,44 +17,44 @@ discard block |
||
17 | 17 | public function bindParams(array $bindings) |
18 | 18 | { |
19 | 19 | foreach ($bindings as $column => $value) { |
20 | - $this->bindings[$column]=$value; |
|
20 | + $this->bindings[$column] = $value; |
|
21 | 21 | } |
22 | 22 | } |
23 | 23 | |
24 | 24 | |
25 | - static function __ifsets($matches,$markers,$else=false) |
|
25 | + static function __ifsets($matches, $markers, $else = false) |
|
26 | 26 | { |
27 | - $content_false=''; |
|
27 | + $content_false = ''; |
|
28 | 28 | |
29 | 29 | if ($else) |
30 | 30 | { |
31 | - list($condition, $preset ,$variable, $content_true, $content_false) = $matches; |
|
31 | + list($condition, $preset, $variable, $content_true, $content_false) = $matches; |
|
32 | 32 | } |
33 | 33 | else |
34 | 34 | { |
35 | - list($condition, $preset ,$variable, $content_true) = $matches; |
|
35 | + list($condition, $preset, $variable, $content_true) = $matches; |
|
36 | 36 | } |
37 | - $preset=strtolower($preset); |
|
37 | + $preset = strtolower($preset); |
|
38 | 38 | |
39 | - if ($preset=='set') |
|
39 | + if ($preset == 'set') |
|
40 | 40 | { |
41 | - return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true: $content_false; |
|
41 | + return (isset($markers[$variable]) && !empty($markers[$variable])) ? $content_true : $content_false; |
|
42 | 42 | } |
43 | - if ($preset=='bool') |
|
43 | + if ($preset == 'bool') |
|
44 | 44 | { |
45 | - return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable]==true) |
|
45 | + return (isset($markers[$variable]) && is_bool($markers[$variable]) && $markers[$variable] == true) |
|
46 | 46 | ? $content_true |
47 | 47 | : $content_false; |
48 | 48 | } |
49 | - if ($preset=='string') |
|
49 | + if ($preset == 'string') |
|
50 | 50 | { |
51 | 51 | return (isset($markers[$variable]) && is_string($markers[$variable]) && strlen($markers[$variable])) |
52 | 52 | ? $content_true |
53 | 53 | : $content_false; |
54 | 54 | } |
55 | - if ($preset=='int') |
|
55 | + if ($preset == 'int') |
|
56 | 56 | { |
57 | - return (isset($markers[$variable]) && intval($markers[$variable])<>0 ) |
|
57 | + return (isset($markers[$variable]) && intval($markers[$variable]) <> 0) |
|
58 | 58 | ? $content_true |
59 | 59 | : $content_false; |
60 | 60 | } |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function process($sql) |
70 | 70 | { |
71 | - $markers=$this->bindings; |
|
71 | + $markers = $this->bindings; |
|
72 | 72 | |
73 | 73 | // 2. process if/else conditions |
74 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
74 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
75 | 75 | list($condition, $variable, $content_true, $content_false) = $matches; |
76 | 76 | |
77 | - return (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) ) ) |
|
77 | + return (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) |
|
78 | 78 | ? $content_true |
79 | 79 | : $content_false; |
80 | 80 | }, $sql); |
81 | 81 | |
82 | 82 | // 3. process if conditions |
83 | - $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { |
|
83 | + $sql = preg_replace_callback('#\{if\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { |
|
84 | 84 | list($condition, $variable, $content) = $matches; |
85 | 85 | |
86 | - if (isset($markers[$variable]) && ( $markers[$variable] || is_numeric($markers[$variable]) )) { |
|
86 | + if (isset($markers[$variable]) && ($markers[$variable] || is_numeric($markers[$variable]))) { |
|
87 | 87 | return $content; |
88 | 88 | } |
89 | 89 | }, $sql); |
90 | 90 | |
91 | 91 | // 1. process if[set|int]/else conditions |
92 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function ($matches) use ($markers) {return self::__ifsets($matches,$markers,true); }, $sql); |
|
93 | - $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function ($matches) use ($markers) { return self::__ifsets($matches,$markers,false); }, $sql); |
|
92 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{else}(.+?)\{/if}#sui', function($matches) use ($markers) {return self::__ifsets($matches, $markers, true); }, $sql); |
|
93 | + $sql = preg_replace_callback('#\{if(.{1,}?)\s(.+?)}(.+?)\{/if}#sui', function($matches) use ($markers) { return self::__ifsets($matches, $markers, false); }, $sql); |
|
94 | 94 | |
95 | 95 | return $sql; |
96 | 96 | } |
@@ -109,13 +109,13 @@ discard block |
||
109 | 109 | CURLOPT_SSL_VERIFYHOST => 0, |
110 | 110 | CURLOPT_SSL_VERIFYPEER => false, |
111 | 111 | CURLOPT_TIMEOUT => 10, |
112 | - CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
112 | + CURLOPT_CONNECTTIMEOUT => 5, // Количество секунд ожидания при попытке соединения |
|
113 | 113 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
114 | 114 | CURLOPT_MAXREDIRS => 10, |
115 | 115 | CURLOPT_HEADER => TRUE, |
116 | 116 | CURLOPT_FOLLOWLOCATION => TRUE, |
117 | - CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | - CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
117 | + CURLOPT_AUTOREFERER => 1, // при редиректе подставлять в «Referer:» значение из «Location:» |
|
118 | + CURLOPT_BINARYTRANSFER => 1, // передавать в binary-safe |
|
119 | 119 | CURLOPT_RETURNTRANSFER => TRUE, |
120 | 120 | CURLOPT_USERAGENT => 'smi2/PHPClickHouse/client', |
121 | 121 | ); |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | } |
235 | 235 | public function setReadFunction($callback) |
236 | 236 | { |
237 | - $this->options[CURLOPT_READFUNCTION]=$callback; |
|
237 | + $this->options[CURLOPT_READFUNCTION] = $callback; |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | |
353 | 353 | public function getHeaders() |
354 | 354 | { |
355 | - $head=[]; |
|
355 | + $head = []; |
|
356 | 356 | foreach ($this->headers as $key=>$value) |
357 | - $head[]= sprintf("%s: %s", $key, $value); |
|
357 | + $head[] = sprintf("%s: %s", $key, $value); |
|
358 | 358 | return $head; |
359 | 359 | } |
360 | 360 | |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | throw new \Exception('setFunctionProgress not is_callable'); |
629 | 629 | } |
630 | 630 | |
631 | - $this->option(CURLOPT_NOPROGRESS,false); |
|
632 | - $this->option(CURLOPT_PROGRESSFUNCTION,$callback); // version 5.5.0 |
|
631 | + $this->option(CURLOPT_NOPROGRESS, false); |
|
632 | + $this->option(CURLOPT_PROGRESSFUNCTION, $callback); // version 5.5.0 |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | } |
693 | 693 | |
694 | 694 | if ($this->options[CURLOPT_VERBOSE]) { |
695 | - echo "\n-----------BODY REQUEST----------\n".$curl_opt[CURLOPT_POSTFIELDS]."\n------END--------\n"; |
|
695 | + echo "\n-----------BODY REQUEST----------\n" . $curl_opt[CURLOPT_POSTFIELDS] . "\n------END--------\n"; |
|
696 | 696 | } |
697 | 697 | curl_setopt_array($this->handle, $curl_opt); |
698 | 698 | return true; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | */ |
71 | 71 | public function total_time() |
72 | 72 | { |
73 | - return round($this->_info['total_time'],3); |
|
73 | + return round($this->_info['total_time'], 3); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public function starttransfer_time() |
80 | 80 | { |
81 | - return round($this->_info['starttransfer_time'],3); |
|
81 | + return round($this->_info['starttransfer_time'], 3); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function connect_time() |
88 | 88 | { |
89 | - return round($this->_info['connect_time'],3); |
|
89 | + return round($this->_info['connect_time'], 3); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function pretransfer_time() |
96 | 96 | { |
97 | - return round($this->_info['pretransfer_time'],3); |
|
97 | + return round($this->_info['pretransfer_time'], 3); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | */ |
290 | 290 | public function rawDataOrJson($format) |
291 | 291 | { |
292 | - if (stripos($format,'json')!==false) |
|
292 | + if (stripos($format, 'json') !== false) |
|
293 | 293 | { |
294 | 294 | return $this->json(); |
295 | 295 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @var int |
44 | 44 | */ |
45 | - private $scanTimeOut=10; |
|
45 | + private $scanTimeOut = 10; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * @var array |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @var array |
79 | 79 | */ |
80 | - private $_table_size_cache=[]; |
|
80 | + private $_table_size_cache = []; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Cluster constructor. |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | |
192 | 192 | // @todo : rewrite total_replicas=1 если кластер без реплики , нужно проверять какой класте и сколько в нем реплик |
193 | 193 | // if ($replica['total_replicas']<2) {$ok=false;$this->error[]='total_replicas : '.json_encode($replica);} |
194 | - if ($this->softCheck ) |
|
194 | + if ($this->softCheck) |
|
195 | 195 | { |
196 | 196 | if (!$ok) break; |
197 | 197 | continue; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $statementsClusters[$node]->getRequest()->setDnsCache(0)->timeOut($this->scanTimeOut)->connectTimeOut($this->scanTimeOut); |
263 | 263 | } |
264 | 264 | $this->defaultClient()->executeAsync(); |
265 | - $tables=[]; |
|
265 | + $tables = []; |
|
266 | 266 | |
267 | 267 | foreach ($this->nodes as $node) { |
268 | 268 | |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | try { |
271 | 271 | $r = $statementsReplicas[$node]->rows(); |
272 | 272 | foreach ($r as $row) { |
273 | - $tables[$row['database']][$row['table']][$node] =$row; |
|
273 | + $tables[$row['database']][$row['table']][$node] = $row; |
|
274 | 274 | } |
275 | 275 | $result['replicas'][$node] = $r; |
276 | - } catch (\Exception $E) { |
|
276 | + }catch (\Exception $E) { |
|
277 | 277 | $result['replicas'][$node] = false; |
278 | 278 | $badNodes[$node] = $E->getMessage(); |
279 | 279 | $this->error[] = 'statementsReplicas:' . $E->getMessage(); |
280 | 280 | } |
281 | 281 | // --------------------------------------------------------------------------------------------------- |
282 | - $hosts=[]; |
|
282 | + $hosts = []; |
|
283 | 283 | |
284 | 284 | try { |
285 | 285 | $c = $statementsClusters[$node]->rows(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | ]; |
296 | 296 | } |
297 | 297 | |
298 | - } catch (\Exception $E) { |
|
298 | + }catch (\Exception $E) { |
|
299 | 299 | $result['clusters'][$node] = false; |
300 | 300 | |
301 | 301 | $this->error[] = 'clusters:' . $E->getMessage(); |
@@ -360,22 +360,22 @@ discard block |
||
360 | 360 | /** |
361 | 361 | * @return Client |
362 | 362 | */ |
363 | - public function clientLike($cluster,$ip_addr_like) |
|
363 | + public function clientLike($cluster, $ip_addr_like) |
|
364 | 364 | { |
365 | - $nodes_check=$this->nodes; |
|
366 | - $nodes=$this->getClusterNodes($cluster); |
|
367 | - $list_ips_need=explode(';',$ip_addr_like); |
|
368 | - $find=false; |
|
369 | - foreach($list_ips_need as $like) |
|
365 | + $nodes_check = $this->nodes; |
|
366 | + $nodes = $this->getClusterNodes($cluster); |
|
367 | + $list_ips_need = explode(';', $ip_addr_like); |
|
368 | + $find = false; |
|
369 | + foreach ($list_ips_need as $like) |
|
370 | 370 | { |
371 | 371 | foreach ($nodes as $node) |
372 | 372 | { |
373 | 373 | |
374 | - if (stripos($node,$like)!==false) |
|
374 | + if (stripos($node, $like) !== false) |
|
375 | 375 | { |
376 | - if (in_array($node,$nodes_check)) |
|
376 | + if (in_array($node, $nodes_check)) |
|
377 | 377 | { |
378 | - $find=$node; |
|
378 | + $find = $node; |
|
379 | 379 | } |
380 | 380 | else |
381 | 381 | { |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | } |
388 | 388 | if ($find) break; |
389 | 389 | } |
390 | - if (!$find){ |
|
391 | - $find=$nodes[0]; |
|
390 | + if (!$find) { |
|
391 | + $find = $nodes[0]; |
|
392 | 392 | } |
393 | 393 | return $this->client($find); |
394 | 394 | } |
@@ -462,10 +462,10 @@ discard block |
||
462 | 462 | * |
463 | 463 | * @return array |
464 | 464 | */ |
465 | - public function getTables($resultDetail=false) |
|
465 | + public function getTables($resultDetail = false) |
|
466 | 466 | { |
467 | 467 | $this->connect(); |
468 | - $list=[]; |
|
468 | + $list = []; |
|
469 | 469 | foreach ($this->tables as $db_name=>$tables) |
470 | 470 | { |
471 | 471 | foreach ($tables as $table_name=>$nodes) |
@@ -473,11 +473,11 @@ discard block |
||
473 | 473 | |
474 | 474 | if ($resultDetail) |
475 | 475 | { |
476 | - $list[$db_name.'.'.$table_name]=$nodes; |
|
476 | + $list[$db_name . '.' . $table_name] = $nodes; |
|
477 | 477 | } |
478 | 478 | else |
479 | 479 | { |
480 | - $list[$db_name.'.'.$table_name]=array_keys($nodes); |
|
480 | + $list[$db_name . '.' . $table_name] = array_keys($nodes); |
|
481 | 481 | } |
482 | 482 | } |
483 | 483 | } |
@@ -493,24 +493,24 @@ discard block |
||
493 | 493 | */ |
494 | 494 | public function getSizeTable($database_table) |
495 | 495 | { |
496 | - $list=[]; |
|
497 | - $nodes=$this->getNodesByTable($database_table); |
|
496 | + $list = []; |
|
497 | + $nodes = $this->getNodesByTable($database_table); |
|
498 | 498 | // scan need node`s |
499 | 499 | foreach ($nodes as $node) |
500 | 500 | { |
501 | 501 | if (empty($this->_table_size_cache[$node])) |
502 | 502 | { |
503 | - $this->_table_size_cache[$node]=$this->client($node)->tablesSize(true); |
|
503 | + $this->_table_size_cache[$node] = $this->client($node)->tablesSize(true); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | |
507 | - $sizes=[]; |
|
507 | + $sizes = []; |
|
508 | 508 | foreach ($this->_table_size_cache as $node=>$rows) |
509 | 509 | { |
510 | 510 | foreach ($rows as $row) |
511 | 511 | { |
512 | - $sizes[$row['database'].'.'.$row['table']][$node]=$row; |
|
513 | - @$sizes[$row['database'].'.'.$row['table']]['total']['sizebytes']+=$row['sizebytes']; |
|
512 | + $sizes[$row['database'] . '.' . $row['table']][$node] = $row; |
|
513 | + @$sizes[$row['database'] . '.' . $row['table']]['total']['sizebytes'] += $row['sizebytes']; |
|
514 | 514 | |
515 | 515 | |
516 | 516 | |
@@ -531,17 +531,17 @@ discard block |
||
531 | 531 | * @param $database_table |
532 | 532 | * @return array |
533 | 533 | */ |
534 | - public function truncateTable($database_table,$timeOut=2000) |
|
534 | + public function truncateTable($database_table, $timeOut = 2000) |
|
535 | 535 | { |
536 | - $out=[]; |
|
537 | - list($db,$table)=explode('.',$database_table); |
|
538 | - $nodes=$this->getMasterNodeForTable($database_table); |
|
536 | + $out = []; |
|
537 | + list($db, $table) = explode('.', $database_table); |
|
538 | + $nodes = $this->getMasterNodeForTable($database_table); |
|
539 | 539 | // scan need node`s |
540 | 540 | foreach ($nodes as $node) |
541 | 541 | { |
542 | - $def=$this->client($node)->getTimeout(); |
|
542 | + $def = $this->client($node)->getTimeout(); |
|
543 | 543 | $this->client($node)->database($db)->setTimeout($timeOut); |
544 | - $out[$node]=$this->client($node)->truncateTable($table); |
|
544 | + $out[$node] = $this->client($node)->truncateTable($table); |
|
545 | 545 | $this->client($node)->setTimeout($def); |
546 | 546 | } |
547 | 547 | return $out; |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | */ |
556 | 556 | public function getMasterNodeForTable($database_table) |
557 | 557 | { |
558 | - $list=$this->getTables(true); |
|
558 | + $list = $this->getTables(true); |
|
559 | 559 | |
560 | 560 | if (empty($list[$database_table])) return []; |
561 | 561 | |
562 | 562 | |
563 | - $result=[]; |
|
563 | + $result = []; |
|
564 | 564 | foreach ($list[$database_table] as $node=>$row) |
565 | 565 | { |
566 | - if ($row['is_leader']) $result[]=$node; |
|
566 | + if ($row['is_leader']) $result[] = $node; |
|
567 | 567 | } |
568 | 568 | return $result; |
569 | 569 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | */ |
576 | 576 | public function getNodesByTable($database_table) |
577 | 577 | { |
578 | - $list=$this->getTables(); |
|
578 | + $list = $this->getTables(); |
|
579 | 579 | if (empty($list[$database_table])) { |
580 | 580 | throw new QueryException('Not find :' . $database_table); |
581 | 581 | } |
@@ -16,12 +16,12 @@ discard block |
||
16 | 16 | */ |
17 | 17 | private $settings = []; |
18 | 18 | |
19 | - private $_ReadOnlyUser=false; |
|
19 | + private $_ReadOnlyUser = false; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @var bool |
23 | 23 | */ |
24 | - private $_isHttps=false; |
|
24 | + private $_isHttps = false; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Settings constructor. |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | |
119 | - public function https($flag=true) |
|
119 | + public function https($flag = true) |
|
120 | 120 | { |
121 | 121 | $this->set('https', $flag); |
122 | 122 | return $this; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | */ |
202 | 202 | public function setReadOnlyUser($flag) |
203 | 203 | { |
204 | - $this->_ReadOnlyUser=$flag; |
|
204 | + $this->_ReadOnlyUser = $flag; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var bool |
41 | 41 | */ |
42 | - private $_connect_user_readonly=false; |
|
42 | + private $_connect_user_readonly = false; |
|
43 | 43 | /** |
44 | 44 | * @var array |
45 | 45 | */ |
46 | - private $_support_format=['TabSeparated','TabSeparatedWithNames','CSV','CSVWithNames','JSONEachRow']; |
|
46 | + private $_support_format = ['TabSeparated', 'TabSeparatedWithNames', 'CSV', 'CSVWithNames', 'JSONEachRow']; |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Client constructor. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function setReadOnlyUser($flag) |
122 | 122 | { |
123 | - $this->_connect_user_readonly=$flag; |
|
123 | + $this->_connect_user_readonly = $flag; |
|
124 | 124 | $this->settings()->setReadOnlyUser($this->_connect_user_readonly); |
125 | 125 | } |
126 | 126 | /** |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | |
164 | 164 | if (is_array($host)) |
165 | 165 | { |
166 | - $host=array_rand(array_flip($host)); |
|
166 | + $host = array_rand(array_flip($host)); |
|
167 | 167 | } |
168 | 168 | |
169 | - $this->_connect_host=$host; |
|
169 | + $this->_connect_host = $host; |
|
170 | 170 | $this->transport()->setHost($host); |
171 | 171 | } |
172 | 172 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | /** |
290 | 290 | * @return $this |
291 | 291 | */ |
292 | - public function useSession($useSessionId=false) |
|
292 | + public function useSession($useSessionId = false) |
|
293 | 293 | { |
294 | 294 | if (!$this->settings()->getSessionId()) |
295 | 295 | { |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function enableLogQueries($flag = true) |
348 | 348 | { |
349 | - $this->settings()->set('log_queries',intval($flag)); |
|
349 | + $this->settings()->set('log_queries', intval($flag)); |
|
350 | 350 | return $this; |
351 | 351 | } |
352 | 352 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | * @param bool $flag |
369 | 369 | * @return $this |
370 | 370 | */ |
371 | - public function https($flag=true) |
|
371 | + public function https($flag = true) |
|
372 | 372 | { |
373 | 373 | $this->settings()->https($flag); |
374 | 374 | return $this; |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function enableExtremes($flag = true) |
384 | 384 | { |
385 | - $this->settings()->set('extremes',intval($flag)); |
|
385 | + $this->settings()->set('extremes', intval($flag)); |
|
386 | 386 | return $this; |
387 | 387 | } |
388 | 388 | |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | * @throws Exception\TransportException |
398 | 398 | * @throws \Exception |
399 | 399 | */ |
400 | - public function select($sql, $bindings = [], $whereInFile = null, $writeToFile=null) |
|
400 | + public function select($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
401 | 401 | { |
402 | - return $this->transport()->select($sql, $bindings, $whereInFile,$writeToFile); |
|
402 | + return $this->transport()->select($sql, $bindings, $whereInFile, $writeToFile); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -445,9 +445,9 @@ discard block |
||
445 | 445 | * @throws Exception\TransportException |
446 | 446 | * @throws \Exception |
447 | 447 | */ |
448 | - public function selectAsync($sql, $bindings = [], $whereInFile = null,$writeToFile=null) |
|
448 | + public function selectAsync($sql, $bindings = [], $whereInFile = null, $writeToFile = null) |
|
449 | 449 | { |
450 | - return $this->transport()->selectAsync($sql, $bindings, $whereInFile,$writeToFile); |
|
450 | + return $this->transport()->selectAsync($sql, $bindings, $whereInFile, $writeToFile); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -484,7 +484,7 @@ discard block |
||
484 | 484 | */ |
485 | 485 | public function showCreateTable($table) |
486 | 486 | { |
487 | - return ($this->select('SHOW CREATE TABLE '.$table)->fetchOne('statement')); |
|
487 | + return ($this->select('SHOW CREATE TABLE ' . $table)->fetchOne('statement')); |
|
488 | 488 | } |
489 | 489 | |
490 | 490 | /** |
@@ -544,17 +544,17 @@ discard block |
||
544 | 544 | */ |
545 | 545 | public function prepareInsertAssocBulk(array $values) |
546 | 546 | { |
547 | - if (isset($values[0]) && is_array($values[0])){ //случай, когда много строк вставляется |
|
547 | + if (isset($values[0]) && is_array($values[0])) { //случай, когда много строк вставляется |
|
548 | 548 | $preparedFields = array_keys($values[0]); |
549 | 549 | $preparedValues = []; |
550 | - foreach ($values as $idx => $row){ |
|
550 | + foreach ($values as $idx => $row) { |
|
551 | 551 | $_fields = array_keys($row); |
552 | - if ($_fields !== $preparedFields){ |
|
553 | - throw new QueryException("Fields not match: ".implode(',',$_fields)." and ".implode(',', $preparedFields)." on element $idx"); |
|
552 | + if ($_fields !== $preparedFields) { |
|
553 | + throw new QueryException("Fields not match: " . implode(',', $_fields) . " and " . implode(',', $preparedFields) . " on element $idx"); |
|
554 | 554 | } |
555 | 555 | $preparedValues[] = array_values($row); |
556 | 556 | } |
557 | - }else{ //одна строка |
|
557 | + } else { //одна строка |
|
558 | 558 | $preparedFields = array_keys($values); |
559 | 559 | $preparedValues = [array_values($values)]; |
560 | 560 | } |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | */ |
588 | 588 | public function insertBatchTSVFiles($table_name, $file_names, $columns_array) |
589 | 589 | { |
590 | - return $this->insertBatchFiles($table_name,$file_names,$columns_array,'TabSeparated'); |
|
590 | + return $this->insertBatchFiles($table_name, $file_names, $columns_array, 'TabSeparated'); |
|
591 | 591 | } |
592 | 592 | |
593 | 593 | /** |
@@ -600,17 +600,17 @@ discard block |
||
600 | 600 | * @return array |
601 | 601 | * @throws Exception\TransportException |
602 | 602 | */ |
603 | - public function insertBatchFiles($table_name, $file_names, $columns_array,$format="CSV") |
|
603 | + public function insertBatchFiles($table_name, $file_names, $columns_array, $format = "CSV") |
|
604 | 604 | { |
605 | 605 | if (is_string($file_names)) |
606 | 606 | { |
607 | - $file_names=[$file_names]; |
|
607 | + $file_names = [$file_names]; |
|
608 | 608 | } |
609 | 609 | if ($this->getCountPendingQueue() > 0) { |
610 | 610 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
611 | 611 | } |
612 | 612 | |
613 | - if (!in_array($format,$this->_support_format)) |
|
613 | + if (!in_array($format, $this->_support_format)) |
|
614 | 614 | { |
615 | 615 | throw new QueryException('Format not support in insertBatchFiles'); |
616 | 616 | } |
@@ -619,17 +619,17 @@ discard block |
||
619 | 619 | |
620 | 620 | foreach ($file_names as $fileName) { |
621 | 621 | if (!is_file($fileName) || !is_readable($fileName)) { |
622 | - throw new QueryException('Cant read file: ' . $fileName.' '.(is_file($fileName)?'':' is not file')); |
|
622 | + throw new QueryException('Cant read file: ' . $fileName . ' ' . (is_file($fileName) ? '' : ' is not file')); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | if (!$columns_array) |
626 | 626 | { |
627 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
627 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
628 | 628 | |
629 | 629 | } |
630 | 630 | else |
631 | 631 | { |
632 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
632 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
633 | 633 | |
634 | 634 | } |
635 | 635 | $result[$fileName] = $this->transport()->writeAsyncCSV($sql, $fileName); |
@@ -656,25 +656,25 @@ discard block |
||
656 | 656 | * @param string $format |
657 | 657 | * @return Transport\CurlerRequest |
658 | 658 | */ |
659 | - public function insertBatchStream($table_name, $columns_array,$format="CSV") |
|
659 | + public function insertBatchStream($table_name, $columns_array, $format = "CSV") |
|
660 | 660 | { |
661 | 661 | if ($this->getCountPendingQueue() > 0) { |
662 | 662 | throw new QueryException('Queue must be empty, before insertBatch, need executeAsync'); |
663 | 663 | } |
664 | 664 | |
665 | - if (!in_array($format,$this->_support_format)) |
|
665 | + if (!in_array($format, $this->_support_format)) |
|
666 | 666 | { |
667 | 667 | throw new QueryException('Format not support in insertBatchFiles'); |
668 | 668 | } |
669 | 669 | |
670 | 670 | if (!$columns_array) |
671 | 671 | { |
672 | - $sql = 'INSERT INTO ' . $table_name . ' FORMAT '.$format; |
|
672 | + $sql = 'INSERT INTO ' . $table_name . ' FORMAT ' . $format; |
|
673 | 673 | |
674 | 674 | } |
675 | 675 | else |
676 | 676 | { |
677 | - $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT '.$format; |
|
677 | + $sql = 'INSERT INTO ' . $table_name . ' ( ' . implode(',', $columns_array) . ' ) FORMAT ' . $format; |
|
678 | 678 | |
679 | 679 | } |
680 | 680 | |
@@ -739,16 +739,16 @@ discard block |
||
739 | 739 | * @throws Exception\TransportException |
740 | 740 | * @throws \Exception |
741 | 741 | */ |
742 | - public function tablesSize($flatList=false) |
|
742 | + public function tablesSize($flatList = false) |
|
743 | 743 | { |
744 | - $z=$this->select(' |
|
744 | + $z = $this->select(' |
|
745 | 745 | SELECT table,database, |
746 | 746 | formatReadableSize(sum(bytes)) as size, |
747 | 747 | sum(bytes) as sizebytes, |
748 | 748 | min(min_date) as min_date, |
749 | 749 | max(max_date) as max_date |
750 | 750 | FROM system.parts |
751 | - WHERE active AND database=\''.$this->settings()->getDatabase().'\' |
|
751 | + WHERE active AND database=\''.$this->settings()->getDatabase() . '\' |
|
752 | 752 | GROUP BY table,database |
753 | 753 | '); |
754 | 754 | |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | * @throws Exception\TransportException |
772 | 772 | * @throws \Exception |
773 | 773 | */ |
774 | - public function isExists($database,$table) |
|
774 | + public function isExists($database, $table) |
|
775 | 775 | { |
776 | 776 | return $this->select(' |
777 | 777 | SELECT * |
778 | 778 | FROM system.tables |
779 | - WHERE name=\''.$table.'\' AND database=\''.$database.'\'' |
|
779 | + WHERE name=\''.$table . '\' AND database=\'' . $database . '\'' |
|
780 | 780 | )->rowsAsTree('name'); |
781 | 781 | } |
782 | 782 | |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | return $this->select(' |
796 | 796 | SELECT * |
797 | 797 | FROM system.parts |
798 | - WHERE like(table,\'%' . $table . '%\') AND database=\''.$this->settings()->getDatabase().'\' |
|
798 | + WHERE like(table,\'%' . $table . '%\') AND database=\'' . $this->settings()->getDatabase() . '\' |
|
799 | 799 | ORDER BY max_date ' . ($limit > 0 ? ' LIMIT ' . intval($limit) : '') |
800 | 800 | )->rowsAsTree('name'); |
801 | 801 | } |
@@ -810,8 +810,8 @@ discard block |
||
810 | 810 | public function dropPartition($dataBaseTableName, $partition_id) |
811 | 811 | { |
812 | 812 | |
813 | - $partition_id=trim($partition_id,'\''); |
|
814 | - $this->settings()->set('replication_alter_partitions_sync',2); |
|
813 | + $partition_id = trim($partition_id, '\''); |
|
814 | + $this->settings()->set('replication_alter_partitions_sync', 2); |
|
815 | 815 | $state = $this->write('ALTER TABLE {dataBaseTableName} DROP PARTITION :partion_id', [ |
816 | 816 | 'dataBaseTableName' => $dataBaseTableName, |
817 | 817 | 'partion_id' => $partition_id |
@@ -829,12 +829,12 @@ discard block |
||
829 | 829 | */ |
830 | 830 | public function truncateTable($tableName) |
831 | 831 | { |
832 | - $partions=$this->partitions($tableName); |
|
833 | - $out=[]; |
|
832 | + $partions = $this->partitions($tableName); |
|
833 | + $out = []; |
|
834 | 834 | foreach ($partions as $part_key=>$part) |
835 | 835 | { |
836 | - $part_id=$part['partition']; |
|
837 | - $out[$part_id]=$this->dropPartition($tableName,$part_id); |
|
836 | + $part_id = $part['partition']; |
|
837 | + $out[$part_id] = $this->dropPartition($tableName, $part_id); |
|
838 | 838 | } |
839 | 839 | return $out; |
840 | 840 | } |
@@ -869,9 +869,9 @@ discard block |
||
869 | 869 | } |
870 | 870 | } |
871 | 871 | |
872 | - $result=[]; |
|
872 | + $result = []; |
|
873 | 873 | foreach ($drop as $partition_id) { |
874 | - $result[$partition_id]=$this->dropPartition($table_name, $partition_id); |
|
874 | + $result[$partition_id] = $this->dropPartition($table_name, $partition_id); |
|
875 | 875 | } |
876 | 876 | |
877 | 877 | return $result; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @var bool |
63 | 63 | */ |
64 | - private $xClickHouseProgress=false; |
|
64 | + private $xClickHouseProgress = false; |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Http constructor. |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getUri() |
115 | 115 | { |
116 | - $proto='http'; |
|
117 | - if ($this->settings()->isHttps()) $proto='https'; |
|
116 | + $proto = 'http'; |
|
117 | + if ($this->settings()->isHttps()) $proto = 'https'; |
|
118 | 118 | |
119 | - return $proto.'://' . $this->_host . ':' . $this->_port; |
|
119 | + return $proto . '://' . $this->_host . ':' . $this->_port; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | $new->timeOut($this->settings()->getTimeOut()); |
188 | - $new->connectTimeOut($this->_connectTimeOut)->keepAlive();// one sec |
|
188 | + $new->connectTimeOut($this->_connectTimeOut)->keepAlive(); // one sec |
|
189 | 189 | $new->verbose($this->_verbose); |
190 | 190 | |
191 | 191 | return $new; |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $request = $this->newRequest($extendinfo); |
280 | 280 | $request->url($url); |
281 | 281 | |
282 | - $request->setCallbackFunction(function (CurlerRequest $request) { |
|
282 | + $request->setCallbackFunction(function(CurlerRequest $request) { |
|
283 | 283 | fclose($request->getInfileHandle()); |
284 | 284 | }); |
285 | 285 | |
@@ -322,29 +322,29 @@ discard block |
||
322 | 322 | |
323 | 323 | public function __findXClickHouseProgress($handle) |
324 | 324 | { |
325 | - $code=curl_getinfo($handle,CURLINFO_HTTP_CODE); |
|
325 | + $code = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
|
326 | 326 | |
327 | 327 | // Search X-ClickHouse-Progress |
328 | - if ($code==200) { |
|
328 | + if ($code == 200) { |
|
329 | 329 | $response = curl_multi_getcontent($handle); |
330 | 330 | $header_size = curl_getinfo($handle, CURLINFO_HEADER_SIZE); |
331 | 331 | if (!$header_size) return false; |
332 | 332 | |
333 | 333 | $header = substr($response, 0, $header_size); |
334 | 334 | if (!$header_size) return false; |
335 | - $pos=strrpos($header,'X-ClickHouse-Progress'); |
|
335 | + $pos = strrpos($header, 'X-ClickHouse-Progress'); |
|
336 | 336 | |
337 | 337 | if (!$pos) return false; |
338 | 338 | |
339 | - $last=substr($header,$pos); |
|
340 | - $data=@json_decode(str_ireplace('X-ClickHouse-Progress:','',$last),true); |
|
339 | + $last = substr($header, $pos); |
|
340 | + $data = @json_decode(str_ireplace('X-ClickHouse-Progress:', '', $last), true); |
|
341 | 341 | |
342 | 342 | if ($data && is_callable($this->xClickHouseProgress)) { |
343 | 343 | |
344 | - if (is_array($this->xClickHouseProgress)){ |
|
345 | - call_user_func_array($this->xClickHouseProgress,[$data]); |
|
344 | + if (is_array($this->xClickHouseProgress)) { |
|
345 | + call_user_func_array($this->xClickHouseProgress, [$data]); |
|
346 | 346 | } else { |
347 | - call_user_func($this->xClickHouseProgress,$data); |
|
347 | + call_user_func($this->xClickHouseProgress, $data); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | |
@@ -407,13 +407,13 @@ discard block |
||
407 | 407 | } |
408 | 408 | |
409 | 409 | |
410 | - $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function (CurlerRequest $request) { |
|
410 | + $request->setResultFileHandle($fout, $isGz)->setCallbackFunction(function(CurlerRequest $request) { |
|
411 | 411 | fclose($request->getResultFileHandle()); |
412 | 412 | }); |
413 | 413 | } |
414 | 414 | if ($this->xClickHouseProgress) |
415 | 415 | { |
416 | - $request->setFunctionProgress([$this,'__findXClickHouseProgress']); |
|
416 | + $request->setFunctionProgress([$this, '__findXClickHouseProgress']); |
|
417 | 417 | } |
418 | 418 | // --------------------------------------------------------------------------------- |
419 | 419 | return $request; |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | */ |
542 | 542 | public function setProgressFunction(callable $callback) |
543 | 543 | { |
544 | - $this->xClickHouseProgress=$callback; |
|
544 | + $this->xClickHouseProgress = $callback; |
|
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
@@ -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); |
@@ -8,20 +8,20 @@ discard block |
||
8 | 8 | |
9 | 9 | |
10 | 10 | $db = new ClickHouseDB\Client($config); |
11 | -$_flag_create_table=false; |
|
11 | +$_flag_create_table = false; |
|
12 | 12 | |
13 | -$size=$db->tableSize('summing_url_views_cityHash64_site_id'); |
|
14 | -echo "Site table summing_url_views_cityHash64_site_id : ".(isset($size['size'])?$size['size']:'false')."\n"; |
|
13 | +$size = $db->tableSize('summing_url_views_cityHash64_site_id'); |
|
14 | +echo "Site table summing_url_views_cityHash64_site_id : " . (isset($size['size']) ? $size['size'] : 'false') . "\n"; |
|
15 | 15 | |
16 | 16 | |
17 | -if (!isset($size['size'])) $_flag_create_table=true; |
|
17 | +if (!isset($size['size'])) $_flag_create_table = true; |
|
18 | 18 | |
19 | 19 | |
20 | 20 | if ($_flag_create_table) { |
21 | 21 | |
22 | 22 | |
23 | 23 | $db->write("DROP TABLE IF EXISTS summing_url_views_cityHash64_site_id"); |
24 | - $re=$db->write(' |
|
24 | + $re = $db->write(' |
|
25 | 25 | CREATE TABLE IF NOT EXISTS summing_url_views_cityHash64_site_id ( |
26 | 26 | event_date Date DEFAULT toDate(event_time), |
27 | 27 | event_time DateTime, |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | $c = 0; |
49 | 49 | foreach ($file_data_names as $file_name) { |
50 | 50 | $c++; |
51 | - $shift_days=( -1* $c*3); |
|
52 | - \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 23 * $c,$shift_days); |
|
51 | + $shift_days = ( -1 * $c * 3); |
|
52 | + \ClickHouseDB\Example\Helper::makeSomeDataFileBig($file_name, 23 * $c, $shift_days); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | echo "----------------------------------------------------------------------------------------------------\n"; |
@@ -75,56 +75,56 @@ discard block |
||
75 | 75 | } |
76 | 76 | echo "------------------------------- COMPARE event_date ---------------------------------------------------------------------\n"; |
77 | 77 | |
78 | -$rows=($db->select('select event_date,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date')); |
|
78 | +$rows = ($db->select('select event_date,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY event_date ORDER BY event_date')->rowsAsTree('event_date')); |
|
79 | 79 | |
80 | -$samp=($db->select('select event_date,(sum(views)*10) as v from summing_url_views_cityHash64_site_id SAMPLE 0.1 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date')); |
|
80 | +$samp = ($db->select('select event_date,(sum(views)*10) as v from summing_url_views_cityHash64_site_id SAMPLE 0.1 GROUP BY event_date ORDER BY event_date ')->rowsAsTree('event_date')); |
|
81 | 81 | |
82 | 82 | |
83 | 83 | foreach ($rows as $event_date=>$data) |
84 | 84 | { |
85 | - echo $event_date."\t".$data['v']."\t".@$samp[$event_date]['v']."\n"; |
|
85 | + echo $event_date . "\t" . $data['v'] . "\t" . @$samp[$event_date]['v'] . "\n"; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | |
89 | -$rows=($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id')); |
|
89 | +$rows = ($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id')); |
|
90 | 90 | |
91 | -$samp=($db->select('select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id')); |
|
91 | +$samp = ($db->select('select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE 0.5 GROUP BY site_id ORDER BY site_id ')->rowsAsTree('site_id')); |
|
92 | 92 | |
93 | 93 | |
94 | 94 | foreach ($rows as $event_date=>$data) |
95 | 95 | { |
96 | - echo $event_date."\t".$data['v']."\t".intval(@$samp[$event_date]['v'])."\n"; |
|
96 | + echo $event_date . "\t" . $data['v'] . "\t" . intval(@$samp[$event_date]['v']) . "\n"; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | -for($f=1;$f<=9;$f++) |
|
101 | +for ($f = 1; $f <= 9; $f++) |
|
102 | 102 | { |
103 | - $SAMPLE=$f/10; |
|
103 | + $SAMPLE = $f / 10; |
|
104 | 104 | |
105 | - $CQL='select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE '.$SAMPLE.' WHERE site_id=34 GROUP BY site_id ORDER BY site_id '; |
|
105 | + $CQL = 'select site_id,(sum(views)) as v from summing_url_views_cityHash64_site_id SAMPLE ' . $SAMPLE . ' WHERE site_id=34 GROUP BY site_id ORDER BY site_id '; |
|
106 | 106 | |
107 | - echo $CQL."\n"; |
|
108 | - $rows=($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id WHERE site_id=34 GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id')); |
|
109 | - $samp=($db->select($CQL)->rowsAsTree('site_id')); |
|
107 | + echo $CQL . "\n"; |
|
108 | + $rows = ($db->select('select site_id,sum(views) as v from summing_url_views_cityHash64_site_id WHERE site_id=34 GROUP BY site_id ORDER BY site_id')->rowsAsTree('site_id')); |
|
109 | + $samp = ($db->select($CQL)->rowsAsTree('site_id')); |
|
110 | 110 | foreach ($rows as $id=>$data) |
111 | 111 | { |
112 | - $s=$samp[$id]['v']; |
|
113 | - $v=$data['v']; |
|
112 | + $s = $samp[$id]['v']; |
|
113 | + $v = $data['v']; |
|
114 | 114 | |
115 | 115 | |
116 | - $percent=round( (100*$s) /$v ,2); |
|
116 | + $percent = round((100 * $s) / $v, 2); |
|
117 | 117 | |
118 | - $kof=(100/$percent); |
|
119 | - $norma_views=$s*(100/$percent); |
|
118 | + $kof = (100 / $percent); |
|
119 | + $norma_views = $s * (100 / $percent); |
|
120 | 120 | |
121 | 121 | |
122 | 122 | |
123 | - echo "Сумма показов без SAMPLE = " .$v."\n"; |
|
124 | - echo "Сумма показов c SAMPLE = " .$s."\n"; |
|
125 | - echo "Процент = " .$percent."\n"; |
|
126 | - echo "На что домжнож.семлир.данн= " .$kof."\n"; |
|
127 | - echo "Сумма показов расчитанное = " .$norma_views."\n"; |
|
123 | + echo "Сумма показов без SAMPLE = " . $v . "\n"; |
|
124 | + echo "Сумма показов c SAMPLE = " . $s . "\n"; |
|
125 | + echo "Процент = " . $percent . "\n"; |
|
126 | + echo "На что домжнож.семлир.данн= " . $kof . "\n"; |
|
127 | + echo "Сумма показов расчитанное = " . $norma_views . "\n"; |
|
128 | 128 | |
129 | 129 | /// >> 1/(0.8) = для SAMPLE 0.8 |
130 | 130 | /// >> 1/(0.5) = для SAMPLE 0.5 |