1<?php 2 3include_once __DIR__ . '/../include.php'; 4include_once __DIR__ . '/Helper.php'; 5\ClickHouseDB\Example\Helper::init(); 6 7 8$config = include_once __DIR__ . '/00_config_connect.php'; 9 10 11$db = new ClickHouseDB\Client($config); 12 13 14for ($f=0;$f<1000;$f++) 15{ 16 $list[$f]=$db->selectAsync('SELECT {num} as num',['num'=>$f]); 17} 18$db->executeAsync(); 19for ($f=0;$f<1000;$f++) 20{ 21 $c=$list[$f]; 22 23 echo $f."\t"; 24 $ret='-'; 25 try{ 26 $ret=$c->fetchOne('num'); 27 }catch (Exception $e) 28 { 29 30 } 31 32 33 echo "$ret\n"; 34} 35 36// -------------------------------- ------- ---------------------------------------------------------------- 37 38 39 40 41$db->write("DROP TABLE IF EXISTS summing_url_views"); 42$db->write(' 43 CREATE TABLE IF NOT EXISTS summing_url_views ( 44 event_date Date DEFAULT toDate(event_time), 45 event_time DateTime, 46 url_hash String, 47 site_id Int32, 48 views Int32, 49 v_00 Int32, 50 v_55 Int32 51 ) 52 ENGINE = SummingMergeTree(event_date, (site_id, url_hash, event_time, event_date), 8192) 53'); 54 55echo "Table EXISTSs:" . json_encode($db->showTables()) . "\n"; 56 57// -------------------------------- CREATE csv file ---------------------------------------------------------------- 58$file_data_names = [ 59 '/tmp/clickHouseDB_test.1.data', 60 '/tmp/clickHouseDB_test.2.data', 61]; 62 63foreach ($file_data_names as $file_name) { 64 \ClickHouseDB\Example\Helper::makeSomeDataFile($file_name, 1); 65} 66// ---------------------------------------------------------------------------------------------------- 67 68echo "insert ONE file:\n"; 69 70$time_start = microtime(true); 71$version_test = 3; 72 73if ($version_test == 1) { 74 $statselect1 = $db->selectAsync('SELECT * FROM summing_url_views LIMIT 1'); 75 $statselect2 = $db->selectAsync('SELECT * FROM summing_url_views LIMIT 1'); 76 77 $stat = $db->insertBatchFiles('summing_url_views', ['/tmp/clickHouseDB_test.1.data'], [ 78 'event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55' 79 ]); 80 81 // 'Exception' with message 'Queue must be empty, before insertBatch,need executeAsync' 82} 83 84// 85if ($version_test == 2) { 86 $statselect1 = $db->selectAsync('SELECT * FROM summing_url_views LIMIT 1'); 87 print_r($statselect1->rows()); 88 // 'Exception' with message 'Not have response' 89} 90 91// good 92if ($version_test == 3) { 93 $statselect2 = $db->selectAsync('SELECT * FROM summing_url_views LIMIT 1'); 94 $db->executeAsync(); 95 96 $stat = $db->insertBatchFiles('summing_url_views', ['/tmp/clickHouseDB_test.1.data'], [ 97 'event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55' 98 ]); 99 100 $statselect1 = $db->selectAsync('SELECT * FROM summing_url_views LIMIT 1'); 101 $db->executeAsync(); 102 103 print_r($statselect1->rows()); 104} 105 106 107 108