1<?php 2 3include_once __DIR__ . '/../include.php'; 4include_once __DIR__ . '/Helper.php'; 5\ClickHouseDB\Example\Helper::init(); 6 7$config = include_once __DIR__ . '/00_config_connect.php'; 8 9 10$db = new ClickHouseDB\Client($config); 11$create = true; 12 13if ($create) { 14 $db->write("DROP TABLE IF EXISTS summing_partions_views"); 15 $db->write(' 16 CREATE TABLE IF NOT EXISTS summing_partions_views ( 17 event_date Date DEFAULT toDate(event_time), 18 event_time DateTime, 19 site_id Int32, 20 hash_id Int32, 21 views Int32 22 ) 23 ENGINE = SummingMergeTree(event_date, (site_id,hash_id, event_time, event_date), 8192) 24 '); 25 26 echo "Table EXISTS:" . json_encode($db->showTables()) . "\n"; 27 echo "----------------------------------- CREATE csv file -----------------------------------------------------------------\n"; 28 29 30 $file_data_names = [ 31 '/tmp/clickHouseDB_test.part.1.data', 32 '/tmp/clickHouseDB_test.part.2.data', 33 '/tmp/clickHouseDB_test.part.3.data', 34 ]; 35 36 $c = 0; 37 foreach ($file_data_names as $file_name) { 38 $c++; 39 \ClickHouseDB\Example\Helper::makeSomeDataFileBigOldDates($file_name, $c); 40 } 41 42 43 echo "--------------------------------------- insert -------------------------------------------------------------\n"; 44 echo "insert ALL file async + GZIP:\n"; 45 46 $db->enableHttpCompression(true); 47 $time_start = microtime(true); 48 49 $result_insert = $db->insertBatchFiles('summing_partions_views', $file_data_names, [ 50 'event_time', 'site_id', 'hash_id', 'views' 51 ]); 52 53 echo "use time:" . round(microtime(true) - $time_start, 2) . " sec.\n"; 54 55 foreach ($result_insert as $fileName => $state) { 56 echo "$fileName => " . json_encode($state->info_upload()) . "\n"; 57 } 58} 59 60 61echo "--------------------------------------- select -------------------------------------------------------------\n"; 62 63print_r($db->select('select min(event_date),max(event_date) from summing_partions_views ')->rows()); 64 65echo "--------------------------------------- list partitions -------------------------------------------------------------\n"; 66 67echo "databaseSize : " . json_encode($db->databaseSize()) . "\n"; 68echo "tableSize : " . json_encode($db->tableSize('summing_partions_views')) . "\n"; 69echo "partitions : " . json_encode($db->partitions('summing_partions_views', 2)) . "\n"; 70 71 72echo "--------------------------------------- drop partitions -------------------------------------------------------------\n"; 73 74echo "dropOldPartitions -30 days : " . json_encode($db->dropOldPartitions('summing_partions_views', 30)) . "\n"; 75 76echo "--------------------------------------- list partitions -------------------------------------------------------------\n"; 77 78echo "databaseSize : " . json_encode($db->databaseSize()) . "\n"; 79echo "tableSize : " . json_encode($db->tableSize('summing_partions_views')) . "\n"; 80echo "partitions : " . json_encode($db->partitions('summing_partions_views', 2)) . "\n"; 81 82