From 634a049b5d55f99a8763e999407289ac593d5d3b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Oct 2025 06:58:35 +0000 Subject: [PATCH 1/3] Initial plan From 6e5fa512c6cb7984b1f02301ed1bcb35f3ebbc85 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Oct 2025 07:14:45 +0000 Subject: [PATCH 2/3] Add support for ClickHouse settings configuration Co-authored-by: antonkomarev <1849174+antonkomarev@users.noreply.github.com> --- README.md | 22 ++++++++++++++ config/clickhouse.php | 4 +++ src/Factory/ClickhouseClientFactory.php | 11 +++++++ tests/Factory/ClickhouseClientFactoryTest.php | 29 +++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/README.md b/README.md index 9282756..b9725a2 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,28 @@ php artisan vendor:publish --provider="Cog\Laravel\Clickhouse\ClickhouseServiceP Edit `config/clickhouse.php` file. +### ClickHouse settings + +You can configure ClickHouse session settings in the configuration file. These settings will be applied to all queries made through the client. + +For example, to enable nested JSON storage using the experimental Object type: + +```php +'connection' => [ + // ... other connection settings + 'settings' => [ + 'allow_experimental_object_type' => 1, + ], +], +``` + +Common settings you might want to configure: +- `allow_experimental_object_type` - Enable JSON/Object type for nested data structures +- `max_execution_time` - Maximum query execution time in seconds +- `max_memory_usage` - Maximum memory usage for query execution + +See [ClickHouse settings documentation](https://clickhouse.com/docs/en/operations/settings/settings) for all available settings. + ## Usage ### ClickHouse client diff --git a/config/clickhouse.php b/config/clickhouse.php index 531fc0d..2aa6d50 100644 --- a/config/clickhouse.php +++ b/config/clickhouse.php @@ -33,6 +33,10 @@ 'timeout' => 1, 'connectTimeOut' => 2, ], + 'settings' => [ + // ClickHouse session settings + // Example: 'allow_experimental_object_type' => 1, + ], ], /* diff --git a/src/Factory/ClickhouseClientFactory.php b/src/Factory/ClickhouseClientFactory.php index da8ead7..fcc2358 100644 --- a/src/Factory/ClickhouseClientFactory.php +++ b/src/Factory/ClickhouseClientFactory.php @@ -42,6 +42,7 @@ public function create( } $options = []; + $settings = []; if (isset($config['options'])) { $options = $config['options']; @@ -49,6 +50,12 @@ public function create( unset($config['options']); } + if (isset($config['settings'])) { + $settings = $config['settings']; + + unset($config['settings']); + } + $client = new Client($config); foreach ($options as $option => $value) { @@ -57,6 +64,10 @@ public function create( $client->$method($value); } + foreach ($settings as $setting => $value) { + $client->settings()->set($setting, $value); + } + return $client; } diff --git a/tests/Factory/ClickhouseClientFactoryTest.php b/tests/Factory/ClickhouseClientFactoryTest.php index 33313f4..20fdce4 100644 --- a/tests/Factory/ClickhouseClientFactoryTest.php +++ b/tests/Factory/ClickhouseClientFactoryTest.php @@ -72,4 +72,33 @@ public function testInitializationWithNonExistsOption(): void self::assertSame(ClickhouseConfigException::class, get_class($exception)); } } + + public function testInitializationWithSettings(): void + { + $clickhouse = new ClickhouseClientFactory( + [ + 'host' => 'example.com', + 'port' => '9000', + 'username' => 'test_user', + 'password' => 'secret', + 'options' => [ + 'database' => 'test_database', + ], + 'settings' => [ + 'max_execution_time' => 60, + 'allow_experimental_object_type' => 1, + ], + ] + ); + + $client = $clickhouse->create(); + + self::assertSame('example.com', $client->getConnectHost()); + self::assertSame('9000', $client->getConnectPort()); + self::assertSame('test_user', $client->getConnectUsername()); + self::assertSame('secret', $client->getConnectPassword()); + self::assertSame('test_database', $client->settings()->getDatabase()); + self::assertSame(60, $client->settings()->getSetting('max_execution_time')); + self::assertSame(1, $client->settings()->getSetting('allow_experimental_object_type')); + } } From 836d0444cb4c816786b51ab99b8997043ce8b70a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 23 Oct 2025 07:15:56 +0000 Subject: [PATCH 3/3] Add example for working with nested JSON data Co-authored-by: antonkomarev <1849174+antonkomarev@users.noreply.github.com> --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index b9725a2..97f43cf 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,45 @@ app(\ClickHouseDB\Client::class)->write( ); ``` +#### Example: Working with nested JSON data + +After enabling `allow_experimental_object_type` in your configuration, you can create tables with JSON columns and store nested data: + +```php +// In your migration +$this->clickhouseClient->write( + <<databaseName}.users ( + id UInt64, + name String, + metadata JSON + ) ENGINE = MergeTree() + ORDER BY id + SQL +); + +// Inserting nested JSON data +app(\ClickHouseDB\Client::class)->insert('users', [ + [ + 'id' => 1, + 'name' => 'John Doe', + 'metadata' => json_encode([ + 'address' => [ + 'street' => '123 Main St', + 'city' => 'New York', + ], + 'preferences' => [ + 'theme' => 'dark', + 'language' => 'en', + ], + ]), + ], +]); + +// Reading nested JSON data +$users = app(\ClickHouseDB\Client::class)->select('SELECT * FROM users')->rows(); +``` + ### ClickHouse database migration #### Create migration