v_55 Int32
    ) 
    ENGINE = SummingMergeTree(event_date, (site_id, url_hash, event_time, event_date), 8192)
');
echo "Table EXISTS:" . json_encode($db->showTables()) . "\n";
// ------------------------------------------------------------------------------------------------------
echo "----------------------------------- CREATE big csv file -----------------------------------------------------------------\n";
$file_data_names = ['/tmp/clickHouseDB_test.b.1.data', '/tmp/clickHouseDB_test.b.2.data', '/tmp/clickHouseDB_test.b.3.data', '/tmp/clickHouseDB_test.b.4.data', '/tmp/clickHouseDB_test.b.5.data'];
$c = 0;
foreach ($file_data_names as $file_name) {
    $c++;
    makeSomeDataFileBig($file_name, 40 * $c);
}
echo "----------------------------------------------------------------------------------------------------\n";
echo "insert ALL file async NO gzip:\n";
$db->settings()->max_execution_time(200);
$time_start = microtime(true);
$result_insert = $db->insertBatchFiles('summing_url_views', $file_data_names, ['event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55']);
echo "use time:" . round(microtime(true) - $time_start, 2) . "\n";
foreach ($result_insert as $state) {
    echo "Info : " . json_encode($state->info_upload()) . "\n";
}
print_r($db->select('select sum(views) from summing_url_views')->rows());
echo "--------------------------------------- enableHttpCompression -------------------------------------------------------------\n";
echo "insert ALL file async + GZIP:\n";
$db->enableHttpCompression(true);
$time_start = microtime(true);
$result_insert = $db->insertBatchFiles('summing_url_views', $file_data_names, ['event_time', 'url_hash', 'site_id', 'views', 'v_00', 'v_55']);
echo "use time:" . round(microtime(true) - $time_start, 2) . "\n";
foreach ($result_insert as $fileName => $state) {
    echo "{$fileName} => " . json_encode($state->info_upload()) . "\n";
Example #2
0
 /**
  *
  */
 public function testSettings()
 {
     $config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x', 'settings' => ['max_execution_time' => 100]];
     $db = new ClickHouseDB\Client($config);
     $this->assertEquals(100, $db->settings()->getSetting('max_execution_time'));
     // settings via constructor
     $config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
     $db = new ClickHouseDB\Client($config, ['max_execution_time' => 100]);
     $this->assertEquals(100, $db->settings()->getSetting('max_execution_time'));
     //
     $config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
     $db = new ClickHouseDB\Client($config);
     $db->settings()->set('max_execution_time', 100);
     $this->assertEquals(100, $db->settings()->getSetting('max_execution_time'));
     $config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
     $db = new ClickHouseDB\Client($config);
     $db->settings()->apply(['max_execution_time' => 100, 'max_block_size' => 12345]);
     $this->assertEquals(100, $db->settings()->getSetting('max_execution_time'));
     $this->assertEquals(12345, $db->settings()->getSetting('max_block_size'));
 }
<?php

include_once __DIR__ . '/../include.php';
$config = ['host' => '192.168.1.20', 'port' => '8123', 'username' => 'default', 'password' => ''];
$db = new ClickHouseDB\Client($config);
//$db->verbose();
$db->settings()->readonly(false);
$result = $db->select('SELECT 12 as {key} WHERE {key} = :value', ['key' => 'ping', 'value' => 12]);
if ($result->fetchOne('ping') != 12) {
    echo "Error : ? \n";
}
print_r($result->fetchOne());
echo 'elapsed   :' . $result->statistics('elapsed') . "\n";
echo 'rows_read :' . $result->statistics('rows_read') . "\n";
echo 'bytes_read:' . $result->statistics('bytes_read') . "\n";
//
$result = $db->select("SELECT 12 as ping");
print_r($result->statistics());
/*
	"statistics":
	{
		"elapsed": 0.000029702,
		"rows_read": 1,
		"bytes_read": 1
	}
*/
Example #4
0
include_once __DIR__ . '/../include.php';
$config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x', 'settings' => ['max_execution_time' => 100]];
$db = new ClickHouseDB\Client($config);
if ($db->settings()->getSetting('max_execution_time') !== 100) {
    throw new Exception("Bad work settings");
}
// settings via constructor
$config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
$db = new ClickHouseDB\Client($config, ['max_execution_time' => 100]);
if ($db->settings()->getSetting('max_execution_time') !== 100) {
    throw new Exception("Bad work settings");
}
// set method
$config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
$db = new ClickHouseDB\Client($config);
$db->settings()->set('max_execution_time', 100);
if ($db->settings()->getSetting('max_execution_time') !== 100) {
    throw new Exception("Bad work settings");
}
// apply array method
$config = ['host' => 'x', 'port' => '8123', 'username' => 'x', 'password' => 'x'];
$db = new ClickHouseDB\Client($config);
$db->settings()->apply(['max_execution_time' => 100, 'max_block_size' => 12345]);
if ($db->settings()->getSetting('max_execution_time') !== 100) {
    throw new Exception("Bad work settings");
}
if ($db->settings()->getSetting('max_block_size') !== 12345) {
    throw new Exception("Bad work settings");
}
echo "getSetting - OK\n";