From 4e1e7169385d466ecca7eec0eef6a0bb62762c4e Mon Sep 17 00:00:00 2001 From: Don Hardman Date: Wed, 22 Jan 2025 17:55:54 +0700 Subject: [PATCH] Add support for DESCRIBE for sharded tables --- src/Plugin/Sharding/DescHandler.php | 2 +- src/Plugin/Sharding/Payload.php | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Plugin/Sharding/DescHandler.php b/src/Plugin/Sharding/DescHandler.php index 1a5ddc3e..a8e2e7a6 100644 --- a/src/Plugin/Sharding/DescHandler.php +++ b/src/Plugin/Sharding/DescHandler.php @@ -53,7 +53,7 @@ public function run(): Task { $q = match ($this->payload->type) { 'show' => "SHOW CREATE TABLE {$shard}", - 'desc' => "DESC {$shard}", + 'desc', 'describe' => "DESC {$shard}", default => throw new RuntimeException("Unknown type: {$this->payload->type}"), }; $resp = $this->manticoreClient->sendRequest($q); diff --git a/src/Plugin/Sharding/Payload.php b/src/Plugin/Sharding/Payload.php index bc5063a9..1a407cc6 100644 --- a/src/Plugin/Sharding/Payload.php +++ b/src/Plugin/Sharding/Payload.php @@ -61,7 +61,7 @@ public static function fromRequest(Request $request): static { return match ($request->command) { 'create', 'alter' => static::fromCreate($request), 'drop' => static::fromDrop($request), - 'desc', 'show' => static::fromDesc($request), + 'desc', 'describe', 'show' => static::fromDesc($request), default => throw new QueryParseError('Failed to parse query'), }; } @@ -72,7 +72,7 @@ public static function fromRequest(Request $request): static { * @throws QueryParseError */ protected static function fromDesc(Request $request): static { - $pattern = '/(?:DESC|SHOW\s+CREATE\s+TABLE)\s+(?P[^:\s\()]+)/ius'; + $pattern = '/(?:DESC|DESCRIBE|SHOW\s+CREATE\s+TABLE)\s+(?P
[^:\s\()]+)/ius'; if (!preg_match($pattern, $request->payload, $matches)) { throw QueryParseError::create('Failed to parse query'); } @@ -163,7 +163,9 @@ protected static function fromDrop(Request $request): static { */ public static function hasMatch(Request $request): bool { // Desc and Show distributed table first - if ($request->command === 'desc' && strpos($request->error, 'contains system') !== false) { + if (($request->command === 'desc' || $request->command === 'describe') + && strpos($request->error, 'contains system') !== false + ) { return true; } if ($request->command === 'show' && strpos($request->error, 'error in your query') !== false) { @@ -246,7 +248,7 @@ public function getHandlerClassName(): string { return match ($this->type) { 'create' => CreateHandler::class, 'drop' => DropHandler::class, - 'desc' => DescHandler::class, + 'desc', 'describe', 'show' => DescHandler::class, default => throw new \Exception('Unsupported sharding type'), }; }