Skip to content
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 ODBC mode, similar to JDBC #34825

Merged
merged 2 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,20 @@ public synchronized boolean isJdbcAllowed() {
return licensed && localStatus.active;
}

/**
* Determine if ODBC support should be enabled.
* <p>
* ODBC is available only in for {@link OperationMode#PLATINUM} and {@link OperationMode#TRIAL} licences
*/
public synchronized boolean isOdbcAllowed() {
Status localStatus = status;
OperationMode operationMode = localStatus.mode;

boolean licensed = operationMode == OperationMode.TRIAL || operationMode == OperationMode.PLATINUM;

return licensed && localStatus.active;
}

public synchronized boolean isTrialLicense() {
return status.mode == OperationMode.TRIAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
* Serializes the provided value in SQL-compatible way based on the client mode
*/
public static XContentBuilder value(XContentBuilder builder, Mode mode, Object value) throws IOException {
if (mode == Mode.JDBC && value instanceof ReadableDateTime) {
if (Mode.isDriver(mode) && value instanceof ReadableDateTime) {
// JDBC cannot parse dates in string format
builder.value(((ReadableDateTime) value).getMillis());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
*/
public enum Mode {
PLAIN,
JDBC;
JDBC,
ODBC;

public static Mode fromString(String mode) {
if (mode == null) {
Expand All @@ -27,4 +28,8 @@ public static Mode fromString(String mode) {
public String toString() {
return this.name().toLowerCase(Locale.ROOT);
}

public static boolean isDriver(Mode mode) {
return mode == JDBC || mode == ODBC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public SqlPlugin(Settings settings) {
throw LicenseUtils.newComplianceException("jdbc");
}
break;
case ODBC:
if (licenseState.isOdbcAllowed() == false) {
throw LicenseUtils.newComplianceException("odbc");
}
break;
case PLAIN:
if (licenseState.isSqlAllowed() == false) {
throw LicenseUtils.newComplianceException(XPackField.SQL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.xpack.sql.action.SqlQueryResponse;
import org.elasticsearch.xpack.sql.execution.PlanExecutor;
import org.elasticsearch.xpack.sql.proto.ColumnInfo;
import org.elasticsearch.xpack.sql.proto.Mode;
import org.elasticsearch.xpack.sql.session.Configuration;
import org.elasticsearch.xpack.sql.session.Cursors;
import org.elasticsearch.xpack.sql.session.RowSet;
Expand All @@ -30,7 +31,6 @@
import java.util.List;

import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.xpack.sql.proto.Mode.JDBC;

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