@@ -56,14 +56,14 @@ |
||
| 56 | 56 | [time(), 'CLICKS', 1, 1237, '192.168.1.13', 'Moscow', 'user_13', ''], |
| 57 | 57 | [time(), 'CLICKS', 1, 1237, '192.168.1.14', 'Moscow', 'user_14', ''], |
| 58 | 58 | |
| 59 | - [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
| 60 | - [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
| 61 | - |
|
| 62 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
| 63 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
| 64 | - [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
| 65 | - [time(), 'VIEWS', 1, 28, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
| 66 | - [time(), 'VIEWS', 1, 26, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
| 59 | + [time(), 'VIEWS', 1, 1237, '192.168.1.11', 'Moscow', 'user_11', ''], |
|
| 60 | + [time(), 'VIEWS', 1, 1237, '192.168.1.12', 'Moscow', 'user_12', ''], |
|
| 61 | + |
|
| 62 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Rwanda', 'user_55', 'http://smi2.ru?utm_campaign=abc'], |
|
| 63 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Banaadir', 'user_54', 'http://smi2.ru?utm_campaign=abc'], |
|
| 64 | + [time(), 'VIEWS', 1, 27, '192.168.1.1', 'Tobruk', 'user_32', 'http://smi2.ru?utm_campaign=CM1'], |
|
| 65 | + [time(), 'VIEWS', 1, 28, '192.168.1.1', 'Gisborne', 'user_12', 'http://smi2.ru?utm_campaign=CM1'], |
|
| 66 | + [time(), 'VIEWS', 1, 26, '192.168.1.1', 'Moscow', 'user_43', 'http://smi2.ru?utm_campaign=CM3'], |
|
| 67 | 67 | ], |
| 68 | 68 | ['event_time', 'event_type', 'site_id', 'article_id', 'ip', 'city', 'user_uuid', 'referer'] |
| 69 | 69 | ); |
@@ -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 | /** |
@@ -19,21 +19,21 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @var array |
| 21 | 21 | */ |
| 22 | - private $degenerations=[]; |
|
| 22 | + private $degenerations = []; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Query constructor. |
| 26 | 26 | * @param $sql |
| 27 | 27 | * @param array $degenerations |
| 28 | 28 | */ |
| 29 | - public function __construct($sql,$degenerations=[]) |
|
| 29 | + public function __construct($sql, $degenerations = []) |
|
| 30 | 30 | { |
| 31 | 31 | if (!trim($sql)) |
| 32 | 32 | { |
| 33 | 33 | throw new QueryException('Empty Query'); |
| 34 | 34 | } |
| 35 | 35 | $this->sql = $sql; |
| 36 | - $this->degenerations=$degenerations; |
|
| 36 | + $this->degenerations = $degenerations; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | // FORMAT\s(\w)*$ |
| 51 | 51 | if (null === $this->format) return false; |
| 52 | - $supportFormats= |
|
| 52 | + $supportFormats = |
|
| 53 | 53 | "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"; |
| 54 | 54 | |
| 55 | - $matches=[]; |
|
| 56 | - if (preg_match_all('%('.$supportFormats.')%ius',$this->sql,$matches)){ |
|
| 55 | + $matches = []; |
|
| 56 | + if (preg_match_all('%(' . $supportFormats . ')%ius', $this->sql, $matches)) { |
|
| 57 | 57 | |
| 58 | 58 | // skip add "format json" |
| 59 | 59 | if (isset($matches[0])) |
| 60 | 60 | { |
| 61 | - $format=trim(str_ireplace('format','',$matches[0][0])); |
|
| 62 | - $this->format=$format; |
|
| 61 | + $format = trim(str_ireplace('format', '', $matches[0][0])); |
|
| 62 | + $this->format = $format; |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | { |
| 93 | 93 | foreach ($this->degenerations as $degeneration) |
| 94 | 94 | { |
| 95 | - if ($degeneration instanceof \ClickHouseDB\Query\Degeneration){ |
|
| 96 | - $this->sql=$degeneration->process($this->sql); |
|
| 95 | + if ($degeneration instanceof \ClickHouseDB\Query\Degeneration) { |
|
| 96 | + $this->sql = $degeneration->process($this->sql); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |