Skip to content

Commit

Permalink
Add support for DESCRIBE for sharded tables
Browse files Browse the repository at this point in the history
  • Loading branch information
donhardman committed Jan 23, 2025
1 parent 867da16 commit 4e1e716
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Plugin/Sharding/DescHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/Plugin/Sharding/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
}
Expand All @@ -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<table>[^:\s\()]+)/ius';
$pattern = '/(?:DESC|DESCRIBE|SHOW\s+CREATE\s+TABLE)\s+(?P<table>[^:\s\()]+)/ius';
if (!preg_match($pattern, $request->payload, $matches)) {
throw QueryParseError::create('Failed to parse query');
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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'),
};
}
Expand Down

0 comments on commit 4e1e716

Please sign in to comment.