Skip to content

Commit 27bd6f6

Browse files
committed
[API] Adds sql async APIs
1 parent 3615c87 commit 27bd6f6

File tree

6 files changed

+308
-0
lines changed

6 files changed

+308
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SQL
22+
module Actions
23+
# Deletes an async SQL search or a stored synchronous SQL search. If the search is still running, the API cancels it.
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/delete-async-sql-search-api.html
29+
#
30+
def delete_async(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_DELETE
40+
path = "_sql/async/delete/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SQL
22+
module Actions
23+
# Returns the current status and available results for an async SQL search or stored synchronous SQL search
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [String] :delimiter Separator for CSV results
27+
# @option arguments [String] :format Short version of the Accept header, e.g. json, yaml
28+
# @option arguments [Time] :keep_alive Retention period for the search and its results
29+
# @option arguments [Time] :wait_for_completion_timeout Duration to wait for complete results
30+
# @option arguments [Hash] :headers Custom HTTP headers
31+
#
32+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/get-async-sql-search-api.html
33+
#
34+
def get_async(arguments = {})
35+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
36+
37+
headers = arguments.delete(:headers) || {}
38+
39+
arguments = arguments.clone
40+
41+
_id = arguments.delete(:id)
42+
43+
method = Elasticsearch::API::HTTP_GET
44+
path = "_sql/async/#{Elasticsearch::API::Utils.__listify(_id)}"
45+
params = Elasticsearch::API::Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)
46+
47+
body = nil
48+
perform_request(method, path, params, body, headers).body
49+
end
50+
51+
# Register this action with its valid params when the module is loaded.
52+
#
53+
# @since 6.2.0
54+
ParamsRegistry.register(:get_async, [
55+
:delimiter,
56+
:format,
57+
:keep_alive,
58+
:wait_for_completion_timeout
59+
].freeze)
60+
end
61+
end
62+
end
63+
end
64+
end
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
module Elasticsearch
19+
module XPack
20+
module API
21+
module SQL
22+
module Actions
23+
# Returns the current status of an async SQL search or a stored synchronous SQL search
24+
#
25+
# @option arguments [String] :id The async search ID
26+
# @option arguments [Hash] :headers Custom HTTP headers
27+
#
28+
# @see https://www.elastic.co/guide/en/elasticsearch/reference/7.14/get-async-sql-search-status-api.html
29+
#
30+
def get_async_status(arguments = {})
31+
raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
32+
33+
headers = arguments.delete(:headers) || {}
34+
35+
arguments = arguments.clone
36+
37+
_id = arguments.delete(:id)
38+
39+
method = Elasticsearch::API::HTTP_GET
40+
path = "_sql/async/status/#{Elasticsearch::API::Utils.__listify(_id)}"
41+
params = {}
42+
43+
body = nil
44+
perform_request(method, path, params, body, headers).body
45+
end
46+
end
47+
end
48+
end
49+
end
50+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.sql#delete_async' do
21+
let(:expected_args) do
22+
[
23+
'DELETE',
24+
'_sql/async/delete/foo',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
context 'when there is no id specified' do
32+
let(:client) do
33+
Class.new { include Elasticsearch::XPack::API }.new
34+
end
35+
36+
it 'raises an exception' do
37+
expect {
38+
client.sql.delete_async
39+
}.to raise_exception(ArgumentError)
40+
end
41+
end
42+
43+
context 'when an index is specified' do
44+
it 'performs the request' do
45+
expect(client_double.sql.delete_async(id: 'foo')).to eq({})
46+
end
47+
end
48+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.sql#get_async' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'_sql/async/foo',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
context 'when there is no id specified' do
32+
let(:client) do
33+
Class.new { include Elasticsearch::XPack::API }.new
34+
end
35+
36+
it 'raises an exception' do
37+
expect {
38+
client.sql.get_async
39+
}.to raise_exception(ArgumentError)
40+
end
41+
end
42+
43+
context 'when an index is specified' do
44+
it 'performs the request' do
45+
expect(client_double.sql.get_async(id: 'foo')).to eq({})
46+
end
47+
end
48+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Licensed to Elasticsearch B.V. under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Elasticsearch B.V. licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
require 'spec_helper'
19+
20+
describe 'client.sql#get_async_status' do
21+
let(:expected_args) do
22+
[
23+
'GET',
24+
'_sql/async/status/foo',
25+
{},
26+
nil,
27+
{}
28+
]
29+
end
30+
31+
context 'when there is no id specified' do
32+
let(:client) do
33+
Class.new { include Elasticsearch::XPack::API }.new
34+
end
35+
36+
it 'raises an exception' do
37+
expect {
38+
client.sql.get_async_status
39+
}.to raise_exception(ArgumentError)
40+
end
41+
end
42+
43+
context 'when an index is specified' do
44+
it 'performs the request' do
45+
expect(client_double.sql.get_async_status(id: 'foo')).to eq({})
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)