-
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: Implement binary format support for SQL clear cursor #84230
SQL: Implement binary format support for SQL clear cursor #84230
Conversation
- support binary_format parameter on _sql/close - make cursor close response consistent with the query protocol (ie. in ODBC/JDBC/CLI return CBOR response for cursor close - as for query)
Pinging @elastic/es-ql (Team:QL) |
@elasticmachine update branch |
Hi @luigidellaquila, I've created a changelog YAML for you. |
expected head sha didn’t match current head ref. |
@elasticmachine update branch |
wrong randomization
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.
I've left some comments but I don't understand the motivation behind the change. The JDBC driver and CLI seem to work as is (but 👍 for adding JdbcCloseCursorIT
) and the binary_format
parameter is not documented anywhere.
Also, out of curiosity, I couldn't find much information about binary_format
. Why is this a flag instead of using Accept
for the content negotiation?
Maybe @bpintea do you have more background?
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Show resolved
Hide resolved
...gin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/SqlClearCursorRequest.java
Outdated
Show resolved
Hide resolved
...gin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorResponseListener.java
Outdated
Show resolved
Hide resolved
Thank you very much for the comments @Luegg |
As noted in PR's description, the motivation is to "make cursor close response consistent": currently, CBOR is used by default, both for requests and responses. The drivers indicate the need for a CBOR answer with the
They either "work" inconsistently (in respect to the body format), or leave cursors unclosed.
This has been by choice, I believe.
No longer sure either, might have been to keep the format unchangeable to (HTTP) proxies. #48261 has a few comments around, but not on this question. |
Thanks for the elaborations 👍 Consistency itself also makes sense of course, but I was unsure wether there was something else. |
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.
Looks good, left a few more notes.
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plugin/SqlMediaTypeParserTests.java
Outdated
Show resolved
Hide resolved
...gin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/SqlClearCursorRequest.java
Outdated
Show resolved
Hide resolved
...l/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/TestSqlClearCursorRequest.java
Outdated
Show resolved
Hide resolved
.../sql/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/SqlRequestParsersTests.java
Show resolved
Hide resolved
|
||
@Override | ||
public RestResponse buildResponse(SqlClearCursorResponse response) throws Exception { | ||
assert mediaType instanceof XContentType; |
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.
Indeed, this could actually be checked (and tested), instead of an assert: one could still send an Accept with a CSV value or something that wouldn't make sense?
@elasticmachine update branch |
Added a new batch of changes that addresses all the comments. |
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Show resolved
Hide resolved
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
...gin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorResponseListener.java
Outdated
Show resolved
Hide resolved
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.
No need to extend the logic beyond CBOR (binary) and XContent.
Please include also a test/set of backwards compatibility tests to check the proper interaction between old clients (that do NOT set the backwards compatibility flag) with the current code.
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
index("library", "2", builder -> { builder.field("name", "bar"); }); | ||
index("library", "3", builder -> { builder.field("name", "baz"); }); | ||
|
||
try (Connection connection = createConnection(connectionProperties())) { |
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.
Same comment as above.
@@ -43,9 +48,11 @@ | |||
PARSER.declareString(optionalConstructorArg(), MODE); | |||
PARSER.declareString(optionalConstructorArg(), CLIENT_ID); | |||
PARSER.declareString(optionalConstructorArg(), VERSION); | |||
PARSER.declareBoolean(SqlClearCursorRequest::binaryCommunication, BINARY_FORMAT); |
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.
Declaring this field mandatory (instead of optional), breaks backwards compatibility for clients that do not set this parameter.
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.
Not sure I got it, maybe I'm misinterpreting some logic here.
Isn't it optional already? (see also test https://github.com/elastic/elasticsearch/pull/84230/files#diff-7d14bc9a0a5fb5167a3d7eea6b457ea14324136f334a33df4417ec5f78fefb84R102 )
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.
I read the above as having constructorArg()
in a similar style to the previous declaration.
...gin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorResponseListener.java
Outdated
Show resolved
Hide resolved
/* | ||
* see getResponseMediaType(RestRequest, SqlQueryRequest) | ||
*/ | ||
public static MediaType getResponseMediaType(RestRequest request, SqlClearCursorRequest sqlRequest) { |
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.
This shouldn't be necessary, see my previous comment.
@elasticmachine update branch |
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Show resolved
Hide resolved
...gin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorResponseListener.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/plugin/SqlMediaTypeParserTests.java
Outdated
Show resolved
Hide resolved
and refactor test cases
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.
Left comments.
...ck/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java
Outdated
Show resolved
Hide resolved
...gin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlClearCursorResponseListener.java
Outdated
Show resolved
Hide resolved
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.
LGTM
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.
Good work so far. I've left some questions mostly looking for explanations on why a specific approach has been considered.
Also, please, have a look at JdbcHttpClientRequestTests
where the binary comm is checked for a query request. I think the same should happen for a query close request.
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Outdated
Show resolved
Hide resolved
...lugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/CloseCursorTestCase.java
Show resolved
Hide resolved
...n/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorRequest.java
Show resolved
Hide resolved
...l/sql-action/src/test/java/org/elasticsearch/xpack/sql/action/TestSqlClearCursorRequest.java
Outdated
Show resolved
Hide resolved
...gin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/SqlClearCursorRequest.java
Outdated
Show resolved
Hide resolved
...n/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlClearCursorRequest.java
Show resolved
Hide resolved
and refactor test cases
@elasticmachine update branch |
@elasticmachine update branch |
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.
LGTM
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.
You need to adjust SqlClearCursorRequestTests
to account for the new component.
mutateInstance
should probably look something like this
protected TestSqlClearCursorRequest mutateInstance(TestSqlClearCursorRequest instance) throws IOException {
@SuppressWarnings("unchecked")
Consumer<TestSqlClearCursorRequest> mutator = randomFrom(
request -> request.requestInfo(randomValueOtherThan(request.requestInfo(), this::randomRequestInfo)),
request -> request.setCursor(randomValueOtherThan(request.getCursor(), SqlQueryResponseTests::randomStringCursor)),
request -> request.binaryCommunication(randomValueOtherThan(request.binaryCommunication(), () -> randomBoolean()))
);
TestSqlClearCursorRequest newRequest = new TestSqlClearCursorRequest(instance.requestInfo(), instance.getCursor());
newRequest.binaryCommunication(instance.binaryCommunication());
mutator.accept(newRequest);
return newRequest;
}
createTestInstance()
should also consider a random value for binaryCommunication
.
…_close' into binary_format_on_cursor_close
@elasticmachine update branch |
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.
LGTM
(ie. in ODBC/JDBC/CLI return CBOR response for cursor close - as for query)
Fixes #53359