-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
SQL: introduce the columnar option for REST requests #39287
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
87fa0c3
Add "columnar" option for REST requests (but be lenient for non-plain
astefan 6ed602e
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 85c1580
Updated documentation
astefan 50b21f5
Addressing comments and fixing the docs
astefan c915524
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan 7db988d
One more test
astefan 7515daf
Address comments
astefan 0fca220
Merge branch 'master' of https://github.com/elastic/elasticsearch int…
astefan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,7 +133,7 @@ Which returns: | |
[float] | ||
=== Paginating through a large response | ||
|
||
Using the example above, onu can continue to the next page by sending back the `cursor` field. In | ||
Using the example above, one can continue to the next page by sending back the `cursor` field. In | ||
case of text format the cursor is returned as `Cursor` http header. | ||
|
||
[source,js] | ||
|
@@ -235,6 +235,81 @@ Douglas Adams |The Hitchhiker's Guide to the Galaxy|180 |1979-10-12T | |
// TESTRESPONSE[s/\|/\\|/ s/\+/\\+/] | ||
// TESTRESPONSE[_cat] | ||
|
||
[[sql-rest-columnar]] | ||
[float] | ||
=== Columnar results | ||
|
||
The most well known way of displaying the results of an SQL query result in general is the one where each | ||
individual record/document represents one line/row. For certain formats, {es-sql} can return the results | ||
in a columnar fashion: one row represents all the values of a certain column from the current page of results. | ||
|
||
A columnar style of results makes sense for certain formats, thus it's available for `json`, `yaml`, `cbor` and `smile`. | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
POST /_sql?format=json | ||
{ | ||
"query": "SELECT * FROM library ORDER BY page_count DESC", | ||
"fetch_size": 5, | ||
"columnar": true | ||
} | ||
-------------------------------------------------- | ||
// CONSOLE | ||
// TEST[setup:library] | ||
|
||
Which returns: | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
{ | ||
"columns": [ | ||
{"name": "author", "type": "text"}, | ||
{"name": "name", "type": "text"}, | ||
{"name": "page_count", "type": "long"}, | ||
{"name": "release_date", "type": "datetime"} | ||
], | ||
"values": [ | ||
["Peter F. Hamilton", "Vernor Vinge", "Frank Herbert", "Alastair Reynolds", "James S.A. Corey"], | ||
["Pandora's Star", "A Fire Upon the Deep", "Dune", "Revelation Space", "Leviathan Wakes"], | ||
[768, 613, 604, 585, 561], | ||
["2004-03-02T00:00:00.000Z", "1992-06-01T00:00:00.000Z", "1965-06-01T00:00:00.000Z", "2000-03-15T00:00:00.000Z", "2011-06-02T00:00:00.000Z"] | ||
], | ||
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl+v///w8=" | ||
} | ||
-------------------------------------------------- | ||
// TESTRESPONSE[s/sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl\+v\/\/\/w8=/$body.cursor/] | ||
|
||
Any subsequent calls using a `cursor` still have to contain the `columnar` parameter if it is wanted the results to be returned this way, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "if it is wanted the results to be ..." - "still have... to preserve the orientation " |
||
meaning the initial query will not _remember_ the columnar option. | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
POST /_sql?format=json | ||
{ | ||
"cursor": "sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl+v///w8=", | ||
"columnar": true | ||
} | ||
-------------------------------------------------- | ||
// CONSOLE | ||
// TEST[continued] | ||
// TEST[s/sDXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAAEWWWdrRlVfSS1TbDYtcW9lc1FJNmlYdw==:BAFmBmF1dGhvcgFmBG5hbWUBZgpwYWdlX2NvdW50AWYMcmVsZWFzZV9kYXRl\+v\/\/\/w8=/$body.cursor/] | ||
|
||
Which looks like: | ||
|
||
[source,js] | ||
-------------------------------------------------- | ||
{ | ||
"values": [ | ||
["Dan Simmons", "Iain M. Banks", "Neal Stephenson", "Frank Herbert", "Frank Herbert"], | ||
["Hyperion", "Consider Phlebas", "Snow Crash", "God Emperor of Dune", "Children of Dune"], | ||
[482, 471, 470, 454, 408], | ||
["1989-05-26T00:00:00.000Z", "1987-04-23T00:00:00.000Z", "1992-06-01T00:00:00.000Z", "1981-05-28T00:00:00.000Z", "1976-04-21T00:00:00.000Z"] | ||
], | ||
"cursor": "46ToAwFzQERYRjFaWEo1UVc1a1JtVjBZMmdCQUFBQUFBQUFBQUVXWjBaNlFXbzNOV0pVY21Wa1NUZDJhV2t3V2xwblp3PT3/////DwQBZgZhdXRob3IBBHRleHQAAAFmBG5hbWUBBHRleHQAAAFmCnBhZ2VfY291bnQBBGxvbmcBAAFmDHJlbGVhc2VfZGF0ZQEIZGF0ZXRpbWUBAAEP" | ||
} | ||
-------------------------------------------------- | ||
// TESTRESPONSE[s/46ToAwFzQERYRjFaWEo1UVc1a1JtVjBZMmdCQUFBQUFBQUFBQUVXWjBaNlFXbzNOV0pVY21Wa1NUZDJhV2t3V2xwblp3PT3\/\/\/\/\/DwQBZgZhdXRob3IBBHRleHQAAAFmBG5hbWUBBHRleHQAAAFmCnBhZ2VfY291bnQBBGxvbmcBAAFmDHJlbGVhc2VfZGF0ZQEIZGF0ZXRpbWUBAAEP/$body.cursor/] | ||
|
||
[[sql-rest-fields]] | ||
[float] | ||
=== Supported REST parameters | ||
|
@@ -277,7 +352,11 @@ s|Description | |
|Time-zone in ISO 8601 used for executing the query on the server. | ||
More information available https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html[here]. | ||
|
||
|columnar | ||
|false | ||
|Return the results in a columnar fashion, rather than row-based fashion. Valid for `json`, `yaml`, `cbor` and `smile`. | ||
|
||
|=== | ||
|
||
Do note that most parameters (outside the timeout ones) make sense only during the initial query - any follow-up pagination request only requires the `cursor` parameter as explained in the <<sql-pagination, pagination>> chapter. | ||
Do note that most parameters (outside the timeout and `columnar` ones) make sense only during the initial query - any follow-up pagination request only requires the `cursor` parameter as explained in the <<sql-pagination, pagination>> chapter. | ||
That's because the query has already been executed and the calls are simply about returning the found results - thus the parameters are simply ignored. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the "for certain formats" repetition, this could be rephrased to "The following formats can be returned in columnar orientation".