Skip to content

Commit

Permalink
Add proxies for SQL for backwards-compatibility. (#222)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Aug 12, 2024
1 parent 6ac68ab commit 6511e9c
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/ClientEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function renderClass(): string
$useNamespace = '';

// The following namespaces do not have OpenSearch API specifications
$patchnamespaces = ['async_search', 'searchable_snapshots', 'ssl', 'sql', 'data_frame_transform_deprecated', 'monitoring'];
$patchnamespaces = ['async_search', 'searchable_snapshots', 'ssl', 'data_frame_transform_deprecated', 'monitoring'];
$this->namespace = array_unique(array_merge($this->namespace, $patchnamespaces));
sort($this->namespace);

Expand Down
24 changes: 24 additions & 0 deletions util/EndpointProxies/sql/closeCursorProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

return <<<'EOD'
/**
* This API will be removed in a future version. Use 'close' API instead.
*
* $params['cursor'] = (string) The cursor given by the server
*
* @param array{'cursor': string} $params Associative array of parameters
* @return array
*/
public function closeCursor(array $params): array
{
$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Sql\Close');
$endpoint->setBody(array_filter([
'cursor' => $this->extractArgument($params, 'cursor'),
]));
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
EOD;
27 changes: 27 additions & 0 deletions util/EndpointProxies/sql/explainProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

return <<<'EOD'
/**
* $params['query'] = (string) The SQL Query
*
* @param array{'query': string} $params Associative array of parameters
* @return array
*
* Note: Use of query parameter is deprecated. Pass it in `body` instead.
*/
public function explain(array $params): array
{
$endpointBuilder = $this->endpoints;
$body = $this->extractArgument($params, 'body') ?? [];
$query = $this->extractArgument($params, 'query');
$endpoint = $endpointBuilder('Sql\Explain');
$endpoint->setBody(array_merge($body, [
'query' => $query,
]));
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
EOD;
31 changes: 31 additions & 0 deletions util/EndpointProxies/sql/queryProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return <<<'EOD'
/**
* $params['query'] = (string) The SQL Query
* $params['format'] = (string) The response format
* $params['cursor'] = (string) The cursor given by the server
* $params['fetch_size'] = (int) The fetch size
*
* @param array{'query'?: string, 'cursor'?: string, 'fetch_size'?: int} $params Associative array of parameters
* @return array
*
* Note: Use of `query`, `cursor` and `fetch_size` parameters is deprecated. Pass them in `body` instead.
*
*/
public function query(array $params): array
{
$endpointBuilder = $this->endpoints;
$endpoint = $endpointBuilder('Sql\Query');
$body = $this->extractArgument($params, 'body') ?? [];
$endpoint->setBody(array_merge($body, array_filter([
'query' => $this->extractArgument($params, 'query'),
'cursor' => $this->extractArgument($params, 'cursor'),
'fetch_size' => $this->extractArgument($params, 'fetch_size'),
])));
$endpoint->setParams($params);
return $this->performRequest($endpoint);
}
EOD;

0 comments on commit 6511e9c

Please sign in to comment.