Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Simple Query Cursor support #390

Merged
merged 52 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
19499d6
Add integ tests to be passed
abbashus Mar 11, 2020
dd400f3
Add cluster settings for cursor - enabled, fetch_size, keep_alive
abbashus Mar 11, 2020
abf7d65
Add fetch_size and cursor params. fetch_size valisation
abbashus Mar 12, 2020
496335c
new SqlRequest constructor for cursor
abbashus Mar 12, 2020
68efc8b
Add logic to open scroll based on settings, fetch_size and limit values
abbashus Mar 12, 2020
e5bc18b
Add curosr close endpoint
abbashus Mar 12, 2020
6871b35
Some updates
abbashus Mar 16, 2020
7818bd6
Remove date formatting changes
abbashus Mar 18, 2020
9b82f75
Fix unit and integ tests, Ignored date format tests for a while, sync…
abbashus Mar 18, 2020
444fc06
Add cursor generation
abbashus Mar 18, 2020
d5a5263
Add test helper methods
abbashus Mar 18, 2020
fc1dc3a
Add test hepler method to get query with explicit fetch_size
abbashus Mar 18, 2020
1b46c33
Add some integ test cases
abbashus Mar 18, 2020
718a773
More integ tests, more test hepler methods
abbashus Mar 18, 2020
527f6f9
Add two more integ tests
abbashus Mar 18, 2020
c1a8642
Refactor
abbashus Mar 19, 2020
d6c623b
Cursor close API
abbashus Mar 19, 2020
dbaf8c1
Close cursor integ tests
abbashus Mar 19, 2020
3c0213e
Merge branch 'master' into cursor-one
abbashus Mar 19, 2020
b82f98f
Fix typo causing cursor close API to fail
abbashus Mar 19, 2020
f592e88
Remove commented code and add partial date formatting change
abbashus Mar 19, 2020
1d13a83
Remove unused import causing build failure
abbashus Mar 19, 2020
25a1749
Add error metrics when not able to close cursor
abbashus Mar 19, 2020
cbe4f93
Add indexname and fieldAliasMap to cursor context
abbashus Mar 19, 2020
c7df8df
Remove ignored test cases affected by date formatting changes
abbashus Mar 19, 2020
21f00ff
Remove unneeded interface, refactor CursorType enum
abbashus Mar 19, 2020
392defd
Remove logs, unneeded fields, comments, refactor
abbashus Mar 19, 2020
3cb9ffb
Add more assert and remove comments
abbashus Mar 19, 2020
edbb36c
Address comments
abbashus Mar 20, 2020
4d9a6e8
Merge branch 'master' into cursor-one
abbashus Mar 20, 2020
29941ad
Merge branch 'master' into cursor-one
abbashus Mar 24, 2020
afd251f
Disable cursor by default, remove comments, fixed tests
abbashus Mar 26, 2020
153d91a
Merge branch 'master' into cursor-one
abbashus Apr 3, 2020
16712b3
Fix cursor for parameterized request, add integration test for same
abbashus Apr 3, 2020
7c272ec
LIMIT changes
abbashus Apr 6, 2020
a285d10
Changes to handle different LIMIT cases
abbashus Apr 6, 2020
230f8e7
Add default cursor metrics
abbashus Apr 6, 2020
f48ab5f
Merge branch 'master' into cursor-one
abbashus Apr 7, 2020
0b7c5b6
Refactoring and integration tests
abbashus Apr 9, 2020
160754c
Merge branch 'master' into cursor-one
abbashus Apr 9, 2020
4bbbd5f
Address comments
abbashus Apr 9, 2020
641ed28
Add integration test on explain cursor
abbashus Apr 9, 2020
6bc00b1
Update monitoring, settings and endpoint docs
abbashus Apr 9, 2020
63868ec
Refactor cursor classes to separate package
abbashus Apr 9, 2020
579d12c
Add Lombok for DefaultCursor
abbashus Apr 9, 2020
3ef6d7a
Add unit test for DefaultCursor
abbashus Apr 9, 2020
cafa9d9
Update doc
abbashus Apr 10, 2020
06be5e5
Unit tests, bug fix , refactoring
abbashus Apr 11, 2020
72cbe34
Merge branch 'master' into cursor-one
abbashus Apr 11, 2020
14d2b7c
Updates
abbashus Apr 13, 2020
32bbfe5
Merge branch 'master' into cursor-one
abbashus Apr 13, 2020
e5f344b
Address comments
abbashus Apr 13, 2020
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
34 changes: 20 additions & 14 deletions docs/user/admin/monitoring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ Description

The meaning of fields in the response is as follows:

+---------------------------+---------------------------------------------------------------+
| Field name| Description|
+===========================+===============================================================+
| request_total| Total count of request|
+---------------------------+---------------------------------------------------------------+
| request_count| Total count of request within the interval|
+---------------------------+---------------------------------------------------------------+
|failed_request_count_syserr|Count of failed request due to system error within the interval|
+---------------------------+---------------------------------------------------------------+
|failed_request_count_cuserr| Count of failed request due to bad request within the interval|
+---------------------------+---------------------------------------------------------------+
| failed_request_count_cb| Indicate if plugin is being circuit broken within the interval|
+---------------------------+---------------------------------------------------------------+
+----------------------------+---------------------------------------------------------------+
| Field name| Description|
+============================+===============================================================+
| request_total| Total count of request|
+----------------------------+---------------------------------------------------------------+
| request_count| Total count of request within the interval|
+----------------------------+---------------------------------------------------------------+
|default_cursor_request_total| Total count of simple cursor request|
+----------------------------+---------------------------------------------------------------+
|default_cursor_request_count| Total count of simple cursor request within the interval|
+----------------------------+---------------------------------------------------------------+
| failed_request_count_syserr|Count of failed request due to system error within the interval|
+----------------------------+---------------------------------------------------------------+
| failed_request_count_cuserr| Count of failed request due to bad request within the interval|
+----------------------------+---------------------------------------------------------------+
| failed_request_count_cb| Indicate if plugin is being circuit broken within the interval|
+----------------------------+---------------------------------------------------------------+


Example
Expand All @@ -50,9 +54,11 @@ Result set::

{
"failed_request_count_cb" : 0,
"default_cursor_request_count" : 10,
"default_cursor_request_total" : 3,
"failed_request_count_cuserr" : 0,
"circuit_breaker" : 0,
"request_total" : 49,
"request_total" : 70,
"request_count" : 0,
"failed_request_count_syserr" : 0
}
Expand Down
126 changes: 126 additions & 0 deletions docs/user/admin/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,129 @@ Result set::
"timed_out" : false
}

opendistro.sql.cursor.enabled
=============================

Description
-----------

User can enable/disable pagination for all queries that are supported.

1. The default value is false.
2. This setting is node scope.
abbashus marked this conversation as resolved.
Show resolved Hide resolved
3. This setting can be updated dynamically.


Example
-------

You can update the setting with a new value like this.

SQL query::

>> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_opendistro/_sql/settings -d '{
"transient" : {
"opendistro.sql.cursor.enabled" : "true"
}
}'

Result set::

{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"opendistro" : {
"sql" : {
"cursor" : {
"enabled" : "true"
}
}
}
}
}

opendistro.sql.cursor.fetch_size
================================

Description
-----------

User can set the default fetch_size for all queries that are supported by pagination. Explicit `fetch_size` passed in request will override this value

1. The default value is 1000.
2. This setting is node scope.
3. This setting can be updated dynamically.


Example
-------

You can update the setting with a new value like this.

SQL query::

>> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_opendistro/_sql/settings -d '{
"transient" : {
"opendistro.sql.cursor.fetch_size" : "50"
}
}'

Result set::

{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"opendistro" : {
"sql" : {
"cursor" : {
"fetch_size" : "50"
}
}
}
}
}

opendistro.sql.cursor.keep_alive
================================

Description
-----------

User can set this value to indicate how long the cursor context should be kept open. Cursor contexts are resource heavy, and a lower value should be used if possible.

1. The default value is 1m.
2. This setting is node scope.
3. This setting can be updated dynamically.


Example
-------

You can update the setting with a new value like this.

SQL query::

>> curl -H 'Content-Type: application/json' -X PUT localhost:9200/_opendistro/_sql/settings -d '{
"transient" : {
"opendistro.sql.cursor.keep_alive" : "5m"
}
}'

Result set::

{
"acknowledged" : true,
"persistent" : { },
"transient" : {
"opendistro" : {
"sql" : {
"cursor" : {
"keep_alive" : "5m"
}
}
}
}
}

59 changes: 59 additions & 0 deletions docs/user/interfaces/endpoint.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,62 @@ Explain::
}
}

Cursor
======

Description
-----------

To get paginated response for a query, user needs to provide `fetch_size` parameter as part of normal query. The value of `fetch_size` should be greater than `0`. In absence of `fetch_size`, default value of 1000 is used. A value of `0` will fallback to non-paginated response. This feature is only available over `jdbc` format for now.
abbashus marked this conversation as resolved.
Show resolved Hide resolved

Example
-------

SQL query::

>> curl -H 'Content-Type: application/json' -X POST localhost:9200/_opendistro/_sql -d '{
"fetch_size" : 5,
"query" : "SELECT firstname, lastname FROM accounts WHERE age > 20 ORDER BY state ASC"
}'

Result set::

{
"schema": [
{
"name": "firstname",
"type": "text"
},
{
"name": "lastname",
"type": "text"
}
],
"cursor": "d:eyJhIjp7fSwicyI6IkRYRjFaWEo1UVc1a1JtVjBZMmdCQUFBQUFBQUFBQU1XZWpkdFRFRkZUMlpTZEZkeFdsWnJkRlZoYnpaeVVRPT0iLCJjIjpbeyJuYW1lIjoiZmlyc3RuYW1lIiwidHlwZSI6InRleHQifSx7Im5hbWUiOiJsYXN0bmFtZSIsInR5cGUiOiJ0ZXh0In1dLCJmIjo1LCJpIjoiYWNjb3VudHMiLCJsIjo5NTF9",
"total": 956,
"datarows": [
[
"Cherry",
"Carey"
],
[
"Lindsey",
"Hawkins"
],
[
"Sargent",
"Powers"
],
[
"Campos",
"Olsen"
],
[
"Savannah",
"Kirby"
]
],
"size": 5,
"status": 200
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazon.opendistroforelasticsearch.sql.cursor;


public interface Cursor {

/**
* All cursor's are of the form <cursorType>:<base64 encoded cursor>
* The serialized form before encoding is upto Cursor implementation
*/
String generateCursorId();

CursorType getType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazon.opendistroforelasticsearch.sql.cursor;

import java.util.HashMap;
import java.util.Map;

/**
* Different types queries for which cursor is supported.
* The result execution, and cursor genreation/parsing will depend on the cursor type.
* NullCursor is the placeholder implementation in case of non-cursor query.
*/
public enum CursorType {
abbashus marked this conversation as resolved.
Show resolved Hide resolved
NULL(null),
DEFAULT("d"),
AGGREGATION("a"),
JOIN("j");

public String id;

CursorType(String id) {
this.id = id;
}

public String getId() {
return this.id;
}

public static final Map<String, CursorType> LOOKUP = new HashMap<>();

static {
for (CursorType type : CursorType.values()) {
LOOKUP.put(type.getId(), type);
}
}

public static CursorType getById(String id) {
return LOOKUP.getOrDefault(id, NULL);
}
}
Loading