Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding specs for SQL namespace #379

Merged
merged 28 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
678fbdf
added sql query specification
Tokesh Jul 7, 2024
36b6c48
lint of query params
Tokesh Jul 7, 2024
2a61bed
added explain, close and stats API specs
Tokesh Jul 8, 2024
6af8316
small fix of x-operation group
Tokesh Jul 8, 2024
108d0a0
fixing lint errors
Tokesh Jul 8, 2024
a0965bc
small fix of operation group
Tokesh Jul 8, 2024
df6c0ff
Revert "fix operation xgroup"
Tokesh Jul 8, 2024
225447d
fix response body
Tokesh Jul 8, 2024
aa51113
response body not passing linter
Tokesh Jul 8, 2024
68752e2
response body
Tokesh Jul 8, 2024
374e0e6
deleting unnecessary response body
Tokesh Jul 8, 2024
73974e7
adding first test for SQL query api
Tokesh Jul 8, 2024
a615da8
deleting local parameters for testing
Tokesh Jul 8, 2024
cb81586
adding tests for sql namespace
Tokesh Jul 21, 2024
7ae06fb
fixing tests for sql namespace
Tokesh Jul 21, 2024
7efd2bb
fixing lint
Tokesh Jul 21, 2024
a9b20c5
fixing status in request body of sql query API
Tokesh Jul 24, 2024
f2ab07e
Merge branch 'main' into sql-namespace
Tokesh Jul 24, 2024
ebddcef
hotfix of sql query structure
Tokesh Jul 24, 2024
7a075cd
Merge remote-tracking branch 'refs/remotes/origin/sql-namespace' into…
Tokesh Jul 24, 2024
a14a618
fix structure of sql stats API
Tokesh Jul 24, 2024
f3003df
fix linter, descriptions
Tokesh Jul 24, 2024
bf278c8
fixing specs-validate ci
Tokesh Jul 24, 2024
ede9aba
adding verbose to check error in tests
Tokesh Jul 24, 2024
0c29ed7
adding second document to receive cursor
Tokesh Jul 24, 2024
8514dfd
added bulk in close API tests, description of PR to changelog, deleti…
Tokesh Jul 24, 2024
8cd485b
adding author name to cspell
Tokesh Jul 24, 2024
1573d8b
adding text to changelog and refactoring code from chapters to prologue
Tokesh Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cspell
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,7 @@ urldecode
vectory
whoamiprotected
wordnet
datarows
syserr
cuserr
Rudnick
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added AjvErrorsParser to print more informative error messages ([#364](https://github.com/opensearch-project/opensearch-api-specification/issues/364))
- Added JsonSchemaValidator, a wrapper for AJV ([#364](https://github.com/opensearch-project/opensearch-api-specification/issues/364))
- Added support for `application/cbor` responses ([#371](https://github.com/opensearch-project/opensearch-api-specification/pull/371))
- Added `/_plugins/_sql`, `close`, `explain` and `stats` ([#379](https://github.com/opensearch-project/opensearch-api-specification/pull/379))
- Added tests for SQL namespace ([#379](https://github.com/opensearch-project/opensearch-api-specification/pull/379))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the add is the spec.

Let's say "Added /_plugins/_sql, close and stats"?

- Added support for `application/smile` responses ([#386](https://github.com/opensearch-project/opensearch-api-specification/pull/386))
- Added `doc_status`, `remote_store`, `segment_replication` and `unreferenced_file_cleanups_performed` to `SegmentStats` ([#395](https://github.com/opensearch-project/opensearch-api-specification/pull/395))
- Added `concurrent_query_*` and `search_idle_reactivate_count_total` fields to `SearchStats` ([#395](https://github.com/opensearch-project/opensearch-api-specification/pull/395))
Expand Down
216 changes: 216 additions & 0 deletions spec/namespaces/sql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
openapi: 3.1.0
info:
title: OpenSearch SQL API
description: OpenSearch SQL API
version: 1.0.0
paths:
/_plugins/_sql:
post:
operationId: sql.query.0
x-operation-group: sql.query
x-version-added: '1.0'
description: Send a SQL/PPL query to the SQL plugin.
externalDocs:
url: https://opensearch.org/docs/latest/search-plugins/sql/sql-ppl-api/
parameters:
- $ref: '#/components/parameters/sql.query::query.format'
- $ref: '#/components/parameters/sql.query::query.sanitize'
requestBody:
$ref: '#/components/requestBodies/sql.query'
responses:
'200':
$ref: '#/components/responses/sql.query@200'
/_plugins/_sql/_explain:
post:
operationId: sql.explain.0
x-operation-group: sql.explain
x-version-added: '1.0'
description: Shows how a query is executed against OpenSearch.
externalDocs:
url: https://opensearch.org/docs/latest/search-plugins/sql/sql-ppl-api/
parameters:
- $ref: '#/components/parameters/sql.explain::query.format'
- $ref: '#/components/parameters/sql.explain::query.sanitize'
requestBody:
$ref: '#/components/requestBodies/sql.explain'
responses:
'200':
$ref: '#/components/responses/sql.explain@200'
/_plugins/_sql/close:
post:
operationId: sql.close.0
x-operation-group: sql.close
x-version-added: '1.0'
description: Clear the cursor context.
externalDocs:
url: https://opensearch.org/docs/latest/search-plugins/sql/sql-ppl-api/
parameters:
- $ref: '#/components/parameters/sql.close::query.format'
- $ref: '#/components/parameters/sql.close::query.sanitize'
requestBody:
$ref: '#/components/requestBodies/sql.close'
responses:
'200':
$ref: '#/components/responses/sql.close@200'
/_plugins/_sql/stats:
get:
operationId: sql.get_stats.0
x-operation-group: sql.get_stats
x-version-added: '1.0'
description: Collect metrics for the plugin within the interval.
externalDocs:
url: https://opensearch.org/docs/latest/search-plugins/sql/monitoring/
parameters:
- $ref: '#/components/parameters/sql.get_stats::query.format'
- $ref: '#/components/parameters/sql.get_stats::query.sanitize'
responses:
'200':
$ref: '#/components/responses/sql.get_stats@200'
post:
operationId: sql.post_stats.1
x-operation-group: sql.post_stats
x-version-added: '1.0'
description: By a stats endpoint, you are able to collect metrics for the plugin within the interval.
externalDocs:
url: https://opensearch.org/docs/latest/search-plugins/sql/monitoring/
parameters:
- $ref: '#/components/parameters/sql.post_stats::query.format'
- $ref: '#/components/parameters/sql.post_stats::query.sanitize'
requestBody:
$ref: '#/components/requestBodies/sql.post_stats'
responses:
'200':
$ref: '#/components/responses/sql.post_stats@200'
components:
parameters:
sql.query::query.format:
name: format
in: query
description: A short version of the Accept header, e.g. json, yaml.
schema:
type: string
description: A short version of the Accept header, e.g. json, yaml.
sql.query::query.sanitize:
name: sanitize
in: query
description: Specifies whether to escape special characters in the results
schema:
type: boolean
default: true
description: Specifies whether to escape special characters in the results
sql.explain::query.format:
name: format
in: query
description: A short version of the Accept header, e.g. json, yaml.
schema:
type: string
description: A short version of the Accept header, e.g. json, yaml.
sql.explain::query.sanitize:
name: sanitize
in: query
description: Specifies whether to escape special characters in the results
schema:
type: boolean
default: true
description: Specifies whether to escape special characters in the results
sql.close::query.format:
name: format
in: query
description: A short version of the Accept header, e.g. json, yaml.
schema:
type: string
description: A short version of the Accept header, e.g. json, yaml.
sql.close::query.sanitize:
name: sanitize
in: query
description: Specifies whether to escape special characters in the results
schema:
type: boolean
default: true
description: Specifies whether to escape special characters in the results
sql.get_stats::query.format:
name: format
in: query
description: A short version of the Accept header, e.g. json, yaml.
schema:
type: string
description: A short version of the Accept header, e.g. json, yaml.
sql.get_stats::query.sanitize:
name: sanitize
in: query
description: Specifies whether to escape special characters in the results
schema:
type: boolean
default: true
description: Specifies whether to escape special characters in the results
sql.post_stats::query.format:
name: format
in: query
description: A short version of the Accept header, e.g. json, yaml.
schema:
type: string
description: A short version of the Accept header, e.g. json, yaml.
sql.post_stats::query.sanitize:
name: sanitize
in: query
description: Specifies whether to escape special characters in the results
schema:
type: boolean
default: true
description: Specifies whether to escape special characters in the results
requestBodies:
sql.query:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlQuery'
required: true
sql.explain:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlExplain'
required: true
sql.close:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlClose'
required: true
sql.post_stats:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlStats'
required: true
responses:
sql.query@200:
description: ''
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlQueryResponse'
sql.explain@200:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlExplainResponse'
required: true
sql.close@200:
content:
application/json:
schema:
$ref: '../schemas/sql._common.yaml#/components/schemas/SqlCloseResponse'
required: true
sql.get_stats@200:
content:
text/plain:
schema:
type: string
required: true
sql.post_stats@200:
content:
text/plain:
schema:
type: string
required: true
88 changes: 88 additions & 0 deletions spec/schemas/sql._common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
openapi: 3.1.0
info:
title: Schemas of sql._common category.
description: Schemas of sql._common category.
version: 1.0.0
paths: {}
components:
schemas:
SqlQuery:
type: object
properties:
query:
type: string
filter:
type: object
fetch_size:
type: integer
SqlQueryResponse:
type: object
properties:
schema:
type: array
items:
type: object
datarows:
type: array
items:
type: array
cursor:
type: string
total:
type: integer
size:
type: integer
status:
type: integer
SqlExplain:
type: object
properties:
query:
type: string
filter:
type: object
fetch_size:
type: integer
SqlExplainResponse:
type: object
properties:
root:
$ref: '#/components/schemas/Explain'
Explain:
type: object
properties:
name:
type: string
description:
type: object
children:
type: array
items:
$ref: '#/components/schemas/Explain'
SqlClose:
type: object
properties:
cursor:
type: string
SqlCloseResponse:
type: object
properties:
succeeded:
type: boolean
SqlStats:
type: object
properties:
start_time:
type: string
end_time:
type: object
cluster_name:
type: object
index:
type: object
query:
type: object
user:
type: object
execution_time:
type: object
49 changes: 49 additions & 0 deletions tests/sql/close.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test to explicitly clear the cursor context
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a period at the end.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time for another lint!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have #403, I'll add a note on tests.


prologues:
- path: /{index}
method: PUT
parameters:
index: books
request_body:
payload: {}
- path: /_bulk
method: POST
request_body:
content_type: application/x-ndjson
payload:
- {create: {_index: books, _id: book_1392214}}
- {author: Harper Lee, title: To Kill a Mockingbird, year: 1960}
- {create: {_index: books, _id: book_1392215}}
- {author: Elizabeth Rudnick, title: Beauty and the Beast, year: 1991}
- path: /{index}/_refresh
method: POST
parameters:
index: books
epilogues:
- path: /books
method: DELETE
status: [200, 404]
chapters:
- synopsis: Get SQL query.
id: query_sql
path: /_plugins/_sql
method: POST
request_body:
payload:
fetch_size: 1
query: 'SELECT * FROM books'
response:
status: 200
output:
cursor: payload.cursor
- synopsis: Close cursor.
path: /_plugins/_sql/close
method: POST
request_body:
payload:
cursor: ${query_sql.cursor}
response:
status: 200
22 changes: 22 additions & 0 deletions tests/sql/explain.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$schema: ../../json_schemas/test_story.schema.yaml

description: Test how a query is executed against OpenSearch.

prologues:
- path: /books
method: PUT
request_body:
payload: {}
epilogues:
- path: /books
method: DELETE
status: [200, 404]
chapters:
- synopsis: Get explain of SQL Query
path: /_plugins/_sql/_explain
method: POST
request_body:
payload:
query: SELECT * FROM books
response:
status: 200
Loading
Loading