Skip to content

Commit 6164475

Browse files
committed
SQL: Introduce ODBC mode, similar to JDBC (#34825)
Close #34720 (cherry picked from commit b97546a) (cherry picked from commit df125af)
1 parent e339270 commit 6164475

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/license/XPackLicenseState.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ private static String[] sqlAcknowledgementMessages(OperationMode currentMode, Op
239239
switch (currentMode) {
240240
case TRIAL:
241241
case PLATINUM:
242-
return new String[] { "JDBC support will be disabled, but you can continue to use SQL CLI and REST endpoint" };
242+
return new String[] {
243+
"JDBC and ODBC support will be disabled, but you can continue to use SQL CLI and REST endpoint" };
243244
}
244245
break;
245246
}
@@ -627,6 +628,20 @@ public synchronized boolean isJdbcAllowed() {
627628
return licensed && localStatus.active;
628629
}
629630

631+
/**
632+
* Determine if ODBC support should be enabled.
633+
* <p>
634+
* ODBC is available only in for {@link OperationMode#PLATINUM} and {@link OperationMode#TRIAL} licences
635+
*/
636+
public synchronized boolean isOdbcAllowed() {
637+
Status localStatus = status;
638+
OperationMode operationMode = localStatus.mode;
639+
640+
boolean licensed = operationMode == OperationMode.TRIAL || operationMode == OperationMode.PLATINUM;
641+
642+
return licensed && localStatus.active;
643+
}
644+
630645
public synchronized boolean isTrialLicense() {
631646
return status.mode == OperationMode.TRIAL;
632647
}

x-pack/plugin/sql/sql-action/src/main/java/org/elasticsearch/xpack/sql/action/SqlQueryResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
167167
* Serializes the provided value in SQL-compatible way based on the client mode
168168
*/
169169
public static XContentBuilder value(XContentBuilder builder, Mode mode, Object value) throws IOException {
170-
if (mode == Mode.JDBC && value instanceof ReadableDateTime) {
170+
if (Mode.isDriver(mode) && value instanceof ReadableDateTime) {
171171
// JDBC cannot parse dates in string format
172172
builder.value(((ReadableDateTime) value).getMillis());
173173
} else {

x-pack/plugin/sql/sql-proto/src/main/java/org/elasticsearch/xpack/sql/proto/Mode.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
*/
1414
public enum Mode {
1515
PLAIN,
16-
JDBC;
16+
JDBC,
17+
ODBC;
1718

1819
public static Mode fromString(String mode) {
1920
if (mode == null) {
@@ -27,4 +28,8 @@ public static Mode fromString(String mode) {
2728
public String toString() {
2829
return this.name().toLowerCase(Locale.ROOT);
2930
}
31+
32+
public static boolean isDriver(Mode mode) {
33+
return mode == JDBC || mode == ODBC;
34+
}
3035
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public SqlPlugin(Settings settings) {
6464
throw LicenseUtils.newComplianceException("jdbc");
6565
}
6666
break;
67+
case ODBC:
68+
if (licenseState.isOdbcAllowed() == false) {
69+
throw LicenseUtils.newComplianceException("odbc");
70+
}
71+
break;
6772
case PLAIN:
6873
if (licenseState.isSqlAllowed() == false) {
6974
throw LicenseUtils.newComplianceException(XPackField.SQL);

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.elasticsearch.xpack.sql.action.SqlQueryResponse;
2121
import org.elasticsearch.xpack.sql.execution.PlanExecutor;
2222
import org.elasticsearch.xpack.sql.proto.ColumnInfo;
23+
import org.elasticsearch.xpack.sql.proto.Mode;
2324
import org.elasticsearch.xpack.sql.session.Configuration;
2425
import org.elasticsearch.xpack.sql.session.Cursors;
2526
import org.elasticsearch.xpack.sql.session.RowSet;
@@ -30,7 +31,6 @@
3031
import java.util.List;
3132

3233
import static java.util.Collections.unmodifiableList;
33-
import static org.elasticsearch.xpack.sql.proto.Mode.JDBC;
3434

3535
public class TransportSqlQueryAction extends HandledTransportAction<SqlQueryRequest, SqlQueryResponse> {
3636
private final PlanExecutor planExecutor;
@@ -76,7 +76,7 @@ public static void operation(PlanExecutor planExecutor, SqlQueryRequest request,
7676
static SqlQueryResponse createResponse(SqlQueryRequest request, SchemaRowSet rowSet) {
7777
List<ColumnInfo> columns = new ArrayList<>(rowSet.columnCount());
7878
for (Schema.Entry entry : rowSet.schema()) {
79-
if (request.mode() == JDBC) {
79+
if (Mode.isDriver(request.mode())) {
8080
columns.add(new ColumnInfo("", entry.name(), entry.type().esType, entry.type().jdbcType,
8181
entry.type().displaySize));
8282
} else {

0 commit comments

Comments
 (0)