diff --git a/src/Snippet/CurrentDatabase.php b/src/Snippet/CurrentDatabase.php index 477c5a2..ab7d641 100644 --- a/src/Snippet/CurrentDatabase.php +++ b/src/Snippet/CurrentDatabase.php @@ -22,8 +22,8 @@ public static function run(ClickHouseClient $clickHouseClient): string $currentDatabase = $clickHouseClient->select( <<<'CLICKHOUSE' -SELECT currentDatabase() AS database -CLICKHOUSE, + SELECT currentDatabase() AS database + CLICKHOUSE, $format, ); diff --git a/src/Snippet/DatabaseSize.php b/src/Snippet/DatabaseSize.php index 1ff0948..0354c00 100644 --- a/src/Snippet/DatabaseSize.php +++ b/src/Snippet/DatabaseSize.php @@ -27,10 +27,10 @@ public static function run(ClickHouseClient $clickHouseClient, string|null $data $currentDatabase = $clickHouseClient->selectWithParams( <<<'CLICKHOUSE' -SELECT sum(bytes) AS size -FROM system.parts -WHERE active AND database=:database -CLICKHOUSE, + SELECT sum(bytes) AS size + FROM system.parts + WHERE active AND database=:database + CLICKHOUSE, ['database' => $databaseName ?? Expression::new('currentDatabase()')], $format, ); diff --git a/src/Snippet/Parts.php b/src/Snippet/Parts.php index e93be51..065b631 100644 --- a/src/Snippet/Parts.php +++ b/src/Snippet/Parts.php @@ -36,13 +36,13 @@ public static function run( $output = $clickHouseClient->selectWithParams( << $database, 'table' => $table, diff --git a/src/Snippet/ShowCreateTable.php b/src/Snippet/ShowCreateTable.php index e23bea6..f1bde5a 100644 --- a/src/Snippet/ShowCreateTable.php +++ b/src/Snippet/ShowCreateTable.php @@ -22,8 +22,8 @@ public static function run(ClickHouseClient $clickHouseClient, string $tableName $output = $clickHouseClient->select( <<select( <<<'CLICKHOUSE' -SHOW DATABASES -CLICKHOUSE, + SHOW DATABASES + CLICKHOUSE, $format, ); diff --git a/src/Snippet/TableSizes.php b/src/Snippet/TableSizes.php index 1a35a36..054b0c0 100644 --- a/src/Snippet/TableSizes.php +++ b/src/Snippet/TableSizes.php @@ -30,27 +30,27 @@ public static function run(ClickHouseClient $clickHouseClient, string|null $data return $clickHouseClient->selectWithParams( <<<'CLICKHOUSE' -SELECT - name AS table, - database, - max(size) AS size, - min(min_date) AS min_date, - max(max_date) AS max_date -FROM system.tables -ANY LEFT JOIN ( - SELECT - table, - database, - sum(bytes) AS size, - min(min_date) AS min_date, - max(max_date) AS max_date - FROM system.parts - WHERE active AND database = :database - GROUP BY table,database -) parts USING ( table, database ) -WHERE database = :database AND storage_policy <> '' -GROUP BY table, database -CLICKHOUSE, + SELECT + name AS table, + database, + max(size) AS size, + min(min_date) AS min_date, + max(max_date) AS max_date + FROM system.tables + ANY LEFT JOIN ( + SELECT + table, + database, + sum(bytes) AS size, + min(min_date) AS min_date, + max(max_date) AS max_date + FROM system.parts + WHERE active AND database = :database + GROUP BY table,database + ) parts USING ( table, database ) + WHERE database = :database AND storage_policy <> '' + GROUP BY table, database + CLICKHOUSE, ['database' => $databaseName ?? Expression::new('currentDatabase()')], $format, )->data;