From 27810f2a5d053756f12a13e8d2f772eaf3ea2bf2 Mon Sep 17 00:00:00 2001 From: dblock Date: Mon, 12 Aug 2024 09:55:30 -0400 Subject: [PATCH] Generate API. Signed-off-by: dblock --- src/OpenSearch/Namespaces/SqlNamespace.php | 102 ++++++++++----------- util/EndpointProxies/sql/explainProxy.php | 2 +- util/EndpointProxies/sql/queryProxy.php | 2 +- 3 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/OpenSearch/Namespaces/SqlNamespace.php b/src/OpenSearch/Namespaces/SqlNamespace.php index 72a00412..ab8222c1 100644 --- a/src/OpenSearch/Namespaces/SqlNamespace.php +++ b/src/OpenSearch/Namespaces/SqlNamespace.php @@ -49,31 +49,6 @@ public function close(array $params = []) return $this->performRequest($endpoint); } - /** - * Shows how a query is executed against OpenSearch. - * - * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. - * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true) - * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. - * $params['human'] = (boolean) Whether to return human readable values for statistics. - * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. - * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. - * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response. - * - * @param array $params Associative array of parameters - * @return array - */ - public function explain(array $params = []) - { - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Sql\Explain'); - $endpoint->setParams($params); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } /** * Collect metrics for the plugin within the interval. * @@ -121,31 +96,6 @@ public function postStats(array $params = []) return $this->performRequest($endpoint); } - /** - * Send a SQL/PPL query to the SQL plugin. - * - * $params['format'] = (string) A short version of the Accept header, e.g. json, yaml. - * $params['sanitize'] = (boolean) Specifies whether to escape special characters in the results (Default = true) - * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. - * $params['human'] = (boolean) Whether to return human readable values for statistics. - * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. - * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. - * $params['filter_path'] = (any) Comma-separated list of filters used to reduce the response. - * - * @param array $params Associative array of parameters - * @return array - */ - public function query(array $params = []) - { - $body = $this->extractArgument($params, 'body'); - - $endpointBuilder = $this->endpoints; - $endpoint = $endpointBuilder('Sql\Query'); - $endpoint->setParams($params); - $endpoint->setBody($body); - - return $this->performRequest($endpoint); - } /** * Adds SQL settings to the standard OpenSearch cluster settings. * @@ -170,9 +120,7 @@ public function settings(array $params = []) return $this->performRequest($endpoint); } /** - * Proxy function to closeCursor() to prevent BC break. * This API will be removed in a future version. Use 'close' API instead. - * Note that the SQL close API takes the cursor in the body. * * $params['cursor'] = (string) The cursor given by the server * @@ -190,6 +138,56 @@ public function closeCursor(array $params): array ])); $endpoint->setParams($params); + return $this->performRequest($endpoint); + } /** + * $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'); + + /** @var AbstractEndpoint $endpoint */ + $endpoint = $endpointBuilder('Sql\Explain'); + $endpoint->setBody(array_merge($body, [ + 'query' => $query, + ])); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } /** + * $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; + + /** @var AbstractEndpoint $endpoint */ + $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); } } diff --git a/util/EndpointProxies/sql/explainProxy.php b/util/EndpointProxies/sql/explainProxy.php index 91f1d6f5..d168afad 100644 --- a/util/EndpointProxies/sql/explainProxy.php +++ b/util/EndpointProxies/sql/explainProxy.php @@ -13,7 +13,7 @@ public function explain(array $params): array { $endpointBuilder = $this->endpoints; - $body = $this->extractArgument($params, 'body'); + $body = $this->extractArgument($params, 'body') ?? []; $query = $this->extractArgument($params, 'query'); /** @var AbstractEndpoint $endpoint */ diff --git a/util/EndpointProxies/sql/queryProxy.php b/util/EndpointProxies/sql/queryProxy.php index 5a3d2d64..60da872a 100644 --- a/util/EndpointProxies/sql/queryProxy.php +++ b/util/EndpointProxies/sql/queryProxy.php @@ -19,7 +19,7 @@ public function query(array $params): array /** @var AbstractEndpoint $endpoint */ $endpoint = $endpointBuilder('Sql\Query'); - $body = $this->extractArgument($params, 'body'); + $body = $this->extractArgument($params, 'body') ?? []; $endpoint->setBody(array_merge($body, array_filter([ 'query' => $this->extractArgument($params, 'query'), 'cursor' => $this->extractArgument($params, 'cursor'),