-
Notifications
You must be signed in to change notification settings - Fork 25.6k
SQL: Implement binary format support for SQL clear cursor #84230
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
Changes from all commits
9ab021a
eedaa4b
e0e9e22
a968837
1f8d2b5
b26c949
553bf13
eb584b4
cfc0eff
c53c7b8
ca1eefd
3fdcde0
c9481a5
c8e9ce3
5ad8c0b
c03406c
9eebe9c
ceab361
6fd1163
ce6922f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 84230 | ||
| summary: Implement binary format support for SQL clear cursor | ||
| area: SQL | ||
| type: bug | ||
| issues: | ||
| - 53359 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.sql.qa.jdbc.single_node; | ||
|
|
||
| import org.elasticsearch.xpack.sql.qa.jdbc.CloseCursorTestCase; | ||
|
|
||
| public class JdbcCloseCursorIT extends CloseCursorTestCase {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.sql.qa.jdbc; | ||
|
|
||
| import org.elasticsearch.core.CheckedConsumer; | ||
| import org.junit.Before; | ||
|
|
||
| import java.io.IOException; | ||
| import java.sql.Connection; | ||
| import java.sql.ResultSet; | ||
| import java.sql.SQLException; | ||
| import java.sql.Statement; | ||
|
|
||
| public abstract class CloseCursorTestCase extends JdbcIntegrationTestCase { | ||
|
|
||
| @Before | ||
| public void initIndex() throws IOException { | ||
| index("library", "1", builder -> { builder.field("name", "foo"); }); | ||
| index("library", "2", builder -> { builder.field("name", "bar"); }); | ||
| index("library", "3", builder -> { builder.field("name", "baz"); }); | ||
| } | ||
|
|
||
| public void testCloseCursor() throws SQLException { | ||
| doWithQuery("SELECT name FROM library", results -> { | ||
| assertTrue(results.next()); | ||
| results.close(); // force sending a cursor close since more pages are available | ||
| assertTrue(results.isClosed()); | ||
| }); | ||
| } | ||
|
|
||
| public void testCloseConsumedCursor() throws SQLException { | ||
| doWithQuery("SELECT name FROM library", results -> { | ||
| for (int i = 0; i < 3; i++) { | ||
| assertTrue(results.next()); | ||
| } | ||
luigidellaquila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assertFalse(results.next()); | ||
| results.close(); | ||
| assertTrue(results.isClosed()); | ||
| }); | ||
| } | ||
|
|
||
| public void testCloseNoCursor() throws SQLException { | ||
| doWithQuery("SELECT name FROM library WHERE name = 'zzz'", results -> { | ||
| results.close(); | ||
| assertTrue(results.isClosed()); | ||
| }); | ||
| } | ||
|
|
||
| private void doWithQuery(String query, CheckedConsumer<ResultSet, SQLException> consumer) throws SQLException { | ||
| try (Connection connection = createConnection(connectionProperties()); Statement statement = connection.createStatement()) { | ||
| statement.setFetchSize(1); | ||
| ResultSet results = statement.executeQuery(query); | ||
| consumer.accept(results); | ||
| } | ||
| } | ||
luigidellaquila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.xcontent.ConstructingObjectParser; | ||
| import org.elasticsearch.xcontent.ParseField; | ||
| import org.elasticsearch.xcontent.XContentParser; | ||
| import org.elasticsearch.xpack.sql.proto.Mode; | ||
| import org.elasticsearch.xpack.sql.proto.RequestInfo; | ||
|
|
@@ -24,12 +25,16 @@ | |
| import static org.elasticsearch.xpack.sql.action.AbstractSqlQueryRequest.CURSOR; | ||
| import static org.elasticsearch.xpack.sql.action.AbstractSqlQueryRequest.MODE; | ||
| import static org.elasticsearch.xpack.sql.action.AbstractSqlQueryRequest.VERSION; | ||
| import static org.elasticsearch.xpack.sql.proto.CoreProtocol.BINARY_COMMUNICATION; | ||
| import static org.elasticsearch.xpack.sql.proto.CoreProtocol.BINARY_FORMAT_NAME; | ||
|
|
||
| /** | ||
| * Request to clean all SQL resources associated with the cursor | ||
| */ | ||
| public class SqlClearCursorRequest extends AbstractSqlRequest { | ||
|
|
||
| static final ParseField BINARY_FORMAT = new ParseField(BINARY_FORMAT_NAME); | ||
|
|
||
| private static final ConstructingObjectParser<SqlClearCursorRequest, Void> PARSER = | ||
| // here the position in "objects" is the same as the fields parser declarations below | ||
| new ConstructingObjectParser<>(SqlClearCursorAction.NAME, objects -> { | ||
|
|
@@ -43,9 +48,11 @@ public class SqlClearCursorRequest extends AbstractSqlRequest { | |
| PARSER.declareString(optionalConstructorArg(), MODE); | ||
| PARSER.declareString(optionalConstructorArg(), CLIENT_ID); | ||
| PARSER.declareString(optionalConstructorArg(), VERSION); | ||
| PARSER.declareBoolean(SqlClearCursorRequest::binaryCommunication, BINARY_FORMAT); | ||
|
Member
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. Declaring this field mandatory (instead of optional), breaks backwards compatibility for clients that do not set this parameter.
Contributor
Author
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. Not sure I got it, maybe I'm misinterpreting some logic here.
Member
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. I read the above as having |
||
| } | ||
|
|
||
| private String cursor; | ||
| private Boolean binaryCommunication = BINARY_COMMUNICATION; | ||
luigidellaquila marked this conversation as resolved.
Show resolved
Hide resolved
luigidellaquila marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public SqlClearCursorRequest() {} | ||
|
|
||
|
|
@@ -80,12 +87,23 @@ public String getDescription() { | |
| public SqlClearCursorRequest(StreamInput in) throws IOException { | ||
| super(in); | ||
| cursor = in.readString(); | ||
| binaryCommunication = in.readOptionalBoolean(); | ||
| } | ||
|
|
||
| public SqlClearCursorRequest binaryCommunication(Boolean binaryCommunication) { | ||
| this.binaryCommunication = binaryCommunication; | ||
| return this; | ||
| } | ||
|
|
||
| public Boolean binaryCommunication() { | ||
| return this.binaryCommunication; | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| super.writeTo(out); | ||
| out.writeString(cursor); | ||
| out.writeOptionalBoolean(binaryCommunication); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -94,12 +112,12 @@ public boolean equals(Object o) { | |
| if (o == null || getClass() != o.getClass()) return false; | ||
| if (super.equals(o) == false) return false; | ||
| SqlClearCursorRequest that = (SqlClearCursorRequest) o; | ||
| return Objects.equals(cursor, that.cursor); | ||
| return Objects.equals(cursor, that.cursor) && Objects.equals(binaryCommunication, that.binaryCommunication); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), cursor); | ||
| return Objects.hash(super.hashCode(), cursor, binaryCommunication); | ||
| } | ||
|
|
||
| public static SqlClearCursorRequest fromXContent(XContentParser parser) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.